kcwebsockets 1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,13 @@
1
+ Metadata-Version: 1.2
2
+ Name: kcwebsockets
3
+ Version: 1.0
4
+ Summary: kcwebsockets
5
+ Home-page: UNKNOWN
6
+ Author: 百里
7
+ Author-email: kcwebs@kwebapp.cn
8
+ Maintainer: 坤坤
9
+ Maintainer-email: fk1402936534@qq.com
10
+ License: MIT License
11
+ Description: UNKNOWN
12
+ Keywords: kcwebsockets1.0
13
+ Platform: UNKNOWN
@@ -0,0 +1,4 @@
1
+ # -*- coding: utf-8 -*-
2
+ __version__ = '1.0'
3
+ from .rfdszbfnbxrdfgvxrhbdtxrhtbs import vsregrsgtrdhbrhtrsgrshydtrsegregsresgr
4
+ client=vsregrsgtrdhbrhtrsgrshydtrsegregsresgr()
@@ -0,0 +1,118 @@
1
+ # -*- coding: utf-8 -*-
2
+ import time,threading
3
+ def kcwcache_print_log(*strs):
4
+ print(time.strftime("%Y-%m-%d %H:%M:%S"),*strs)
5
+ class vsregrsgtrdhbrhtrsgrshydtrsegregsresgr:
6
+ wsobj=None
7
+ __config={
8
+ 'debug':False,
9
+ 'th_lock':False,
10
+ 'url':'',
11
+ 'break':5 #断线重连次数,0表示不重连
12
+ }
13
+ __thlock={
14
+ 'obj':None,
15
+ 'status':False
16
+ }
17
+ def __connect(self):
18
+ import websocket
19
+ for i in range(100):
20
+ self.wsobj = websocket.WebSocket()
21
+ try:
22
+ self.wsobj.connect(self.__config['url'])
23
+ except websocket._exceptions.WebSocketBadStatusException:
24
+ try:self.wsobj.close()
25
+ except:pass
26
+ self.wsobj=None
27
+ if i>=self.__config['break']:
28
+ self.__close_th_lock()
29
+ raise Exception('连接已中止,请重新连接')
30
+ time.sleep(0.1)
31
+ except:
32
+ try:self.wsobj.close()
33
+ except:pass
34
+ self.wsobj=None
35
+ self.__close_th_lock()
36
+ raise
37
+ else:
38
+ break
39
+ def __start_th_lock(self):
40
+ """开启线程锁 多线程中建议开启 注意 这个python多线程锁 而不是数据库事务锁"""
41
+ if not self.__thlock['obj']:
42
+ self.__thlock['obj']=threading.Lock()
43
+ self.__thlock['obj'].acquire()
44
+ self.__thlock['status']=True
45
+ if self.__config['debug']:
46
+ kcwcache_print_log('开启线程锁cache')
47
+ def __close_th_lock(self):
48
+ """退出线程锁 这个python多线程锁 而不是数据库事务锁"""
49
+ if self.__thlock['status']:
50
+ self.__thlock['obj'].release()
51
+ self.__thlock['status']=False
52
+ if self.__config['debug']:
53
+ kcwcache_print_log('退出线程锁cache')
54
+ def connect(self,url,th_lock=False):
55
+ """设置连接
56
+
57
+ url 连接地址 如 wss://websocket.kwebapp.cn/?unionid=1&token=1232
58
+
59
+ th_lock 是否开启线程锁 多线程中建议开启 注意 这个python多线程锁 而不是redis库事务锁 也可以在配置信息中全局开启
60
+
61
+ """
62
+ if th_lock!='no':
63
+ self.__config['th_lock']=th_lock
64
+ if self.__config['th_lock']:
65
+ self.__start_th_lock()
66
+ self.__config['url']=url
67
+ return self
68
+
69
+ def send(self,text):
70
+ for i in range(100):
71
+ if not self.wsobj:
72
+ self.__connect()
73
+ try:
74
+ self.wsobj.send(text)
75
+ except ConnectionAbortedError:
76
+ try:self.wsobj.close()
77
+ except:pass
78
+ self.wsobj=None
79
+ if i>=self.__config['break']:
80
+ self.__close_th_lock()
81
+ raise Exception('连接已中止,请重新连接')
82
+ time.sleep(0.1)
83
+ except:
84
+ try:self.wsobj.close()
85
+ except:pass
86
+ self.wsobj=None
87
+ self.__close_th_lock()
88
+ raise
89
+ else:
90
+ self.__close_th_lock()
91
+ break
92
+ def recv(self):
93
+ """接收数据"""
94
+ for i in range(100):
95
+ if not self.wsobj:
96
+ self.__connect()
97
+ try:
98
+ data = self.wsobj.recv()
99
+ except ConnectionAbortedError:
100
+ try:self.wsobj.close()
101
+ except:pass
102
+ self.wsobj=None
103
+ if i>=self.__config['break']:
104
+ self.__close_th_lock()
105
+ raise Exception('连接已中止,请重新连接')
106
+ time.sleep(0.1)
107
+ except:
108
+ try:self.wsobj.close()
109
+ except:pass
110
+ self.wsobj=None
111
+ self.__close_th_lock()
112
+ raise
113
+ else:
114
+ self.__close_th_lock()
115
+ break
116
+ return data
117
+
118
+
@@ -0,0 +1,13 @@
1
+ Metadata-Version: 1.2
2
+ Name: kcwebsockets
3
+ Version: 1.0
4
+ Summary: kcwebsockets
5
+ Home-page: UNKNOWN
6
+ Author: 百里
7
+ Author-email: kcwebs@kwebapp.cn
8
+ Maintainer: 坤坤
9
+ Maintainer-email: fk1402936534@qq.com
10
+ License: MIT License
11
+ Description: UNKNOWN
12
+ Keywords: kcwebsockets1.0
13
+ Platform: UNKNOWN
@@ -0,0 +1,8 @@
1
+ setup.py
2
+ kcwebsockets/__init__.py
3
+ kcwebsockets/rfdszbfnbxrdfgvxrhbdtxrhtbs.py
4
+ kcwebsockets.egg-info/PKG-INFO
5
+ kcwebsockets.egg-info/SOURCES.txt
6
+ kcwebsockets.egg-info/dependency_links.txt
7
+ kcwebsockets.egg-info/requires.txt
8
+ kcwebsockets.egg-info/top_level.txt
@@ -0,0 +1 @@
1
+ websocket-client==1.8.0
@@ -0,0 +1 @@
1
+ kcwebsockets
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,56 @@
1
+
2
+ # 打包上传 python setup.py sdist upload
3
+ # 打包并安装 python setup.py sdist install
4
+ # twine upload --repository-url https://test.pypi.org/legacy/ dist/* #上传到测试
5
+ # pip install --index-url https://pypi.org/simple/ kcwebs #安装测试服务上的kcwebs pip3 install kcwebs==4.12.4 -i https://pypi.org/simple/
6
+ # 安装 python setup.py install
7
+ ############################################# pip3.8 install kcwebs==6.4.15 -i https://pypi.org/simple
8
+ import os,sys
9
+ from setuptools import setup
10
+ from kcwebsockets import __version__
11
+ confkcws={}
12
+ confkcws['name']='kcwebsockets'
13
+ confkcws['version']=__version__
14
+ confkcws['description']='kcwebsockets'
15
+ confkcws['long_description']=''
16
+ confkcws['license']='MIT License'
17
+ confkcws['url']=''
18
+ confkcws['author']='百里'
19
+ confkcws['author_email']='kcwebs@kwebapp.cn'
20
+ confkcws['maintainer']='坤坤'
21
+ confkcws['maintainer_email']='fk1402936534@qq.com'
22
+ def get_file(folder='./',lists=[]):
23
+ lis=os.listdir(folder)
24
+ for files in lis:
25
+ if not os.path.isfile(folder+"/"+files):
26
+ if files=='__pycache__' or files=='.git':
27
+ pass
28
+ else:
29
+ lists.append(folder+"/"+files)
30
+ get_file(folder+"/"+files,lists)
31
+ else:
32
+ pass
33
+ return lists
34
+ def start():
35
+ b=get_file("kcwebsockets",['kcwebsockets'])
36
+ setup(
37
+ name = confkcws["name"],
38
+ version = confkcws["version"],
39
+ keywords = "kcwebsockets"+confkcws['version'],
40
+ description = confkcws["description"],
41
+ long_description = confkcws["long_description"],
42
+ license = confkcws["license"],
43
+ author = confkcws["author"],
44
+ author_email = confkcws["author_email"],
45
+ maintainer = confkcws["maintainer"],
46
+ maintainer_email = confkcws["maintainer_email"],
47
+ url=confkcws['url'],
48
+ packages = b,
49
+
50
+
51
+ install_requires = ['websocket-client==1.8.0'], #第三方包
52
+ package_data = {
53
+ '': ['*.html', '*.js','*.css','*.jpg','*.png','*.gif'],
54
+ }
55
+ )
56
+ start()