kwebsocket 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: kwebsocket
3
+ Version: 1.0
4
+ Summary: kwebsocket
5
+ Home-page: UNKNOWN
6
+ Author: 百里
7
+ Author-email: kwebs@kwebapp.cn
8
+ Maintainer: 坤坤
9
+ Maintainer-email: fk1402936534@qq.com
10
+ License: MIT License
11
+ Description: UNKNOWN
12
+ Keywords: kwebsocket1.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 kwebsocket_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
+ kwebsocket_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
+ kwebsocket_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: kwebsocket
3
+ Version: 1.0
4
+ Summary: kwebsocket
5
+ Home-page: UNKNOWN
6
+ Author: 百里
7
+ Author-email: kwebs@kwebapp.cn
8
+ Maintainer: 坤坤
9
+ Maintainer-email: fk1402936534@qq.com
10
+ License: MIT License
11
+ Description: UNKNOWN
12
+ Keywords: kwebsocket1.0
13
+ Platform: UNKNOWN
@@ -0,0 +1,8 @@
1
+ setup.py
2
+ kwebsocket/__init__.py
3
+ kwebsocket/rfdszbfnbxrdfgvxrhbdtxrhtbs.py
4
+ kwebsocket.egg-info/PKG-INFO
5
+ kwebsocket.egg-info/SOURCES.txt
6
+ kwebsocket.egg-info/dependency_links.txt
7
+ kwebsocket.egg-info/requires.txt
8
+ kwebsocket.egg-info/top_level.txt
@@ -0,0 +1 @@
1
+ websocket-client==1.8.0
@@ -0,0 +1 @@
1
+ kwebsocket
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,52 @@
1
+
2
+ # 打包上传 python setup.py sdist upload
3
+ # 安装 python setup.py install
4
+ import os,sys
5
+ from setuptools import setup
6
+ from kwebsocket import __version__
7
+ confkcws={}
8
+ confkcws['name']='kwebsocket'
9
+ confkcws['version']=__version__
10
+ confkcws['description']='kwebsocket'
11
+ confkcws['long_description']=''
12
+ confkcws['license']='MIT License'
13
+ confkcws['url']=''
14
+ confkcws['author']='百里'
15
+ confkcws['author_email']='kwebs@kwebapp.cn'
16
+ confkcws['maintainer']='坤坤'
17
+ confkcws['maintainer_email']='fk1402936534@qq.com'
18
+ def get_file(folder='./',lists=[]):
19
+ lis=os.listdir(folder)
20
+ for files in lis:
21
+ if not os.path.isfile(folder+"/"+files):
22
+ if files=='__pycache__' or files=='.git':
23
+ pass
24
+ else:
25
+ lists.append(folder+"/"+files)
26
+ get_file(folder+"/"+files,lists)
27
+ else:
28
+ pass
29
+ return lists
30
+ def start():
31
+ b=get_file("kwebsocket",['kwebsocket'])
32
+ setup(
33
+ name = confkcws["name"],
34
+ version = confkcws["version"],
35
+ keywords = "kwebsocket"+confkcws['version'],
36
+ description = confkcws["description"],
37
+ long_description = confkcws["long_description"],
38
+ license = confkcws["license"],
39
+ author = confkcws["author"],
40
+ author_email = confkcws["author_email"],
41
+ maintainer = confkcws["maintainer"],
42
+ maintainer_email = confkcws["maintainer_email"],
43
+ url=confkcws['url'],
44
+ packages = b,
45
+
46
+
47
+ install_requires = ['websocket-client==1.8.0'], #第三方包
48
+ package_data = {
49
+ '': ['*.html', '*.js','*.css','*.jpg','*.png','*.gif'],
50
+ }
51
+ )
52
+ start()