kwebsocket 1.3__tar.gz → 1.4__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.
- {kwebsocket-1.3 → kwebsocket-1.4}/PKG-INFO +2 -2
- {kwebsocket-1.3 → kwebsocket-1.4}/kwebsocket/__init__.py +1 -1
- {kwebsocket-1.3 → kwebsocket-1.4}/kwebsocket/rfdszbfnbxrdfgvxrhbdtxrhtbs.py +79 -14
- {kwebsocket-1.3 → kwebsocket-1.4}/kwebsocket.egg-info/PKG-INFO +2 -2
- {kwebsocket-1.3 → kwebsocket-1.4}/kwebsocket.egg-info/requires.txt +1 -0
- {kwebsocket-1.3 → kwebsocket-1.4}/setup.py +1 -1
- {kwebsocket-1.3 → kwebsocket-1.4}/kwebsocket.egg-info/SOURCES.txt +0 -0
- {kwebsocket-1.3 → kwebsocket-1.4}/kwebsocket.egg-info/dependency_links.txt +0 -0
- {kwebsocket-1.3 → kwebsocket-1.4}/kwebsocket.egg-info/top_level.txt +0 -0
- {kwebsocket-1.3 → kwebsocket-1.4}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 1.2
|
|
2
2
|
Name: kwebsocket
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.4
|
|
4
4
|
Summary: kwebsocket
|
|
5
5
|
Home-page: UNKNOWN
|
|
6
6
|
Author: 百里
|
|
@@ -9,5 +9,5 @@ Maintainer: 坤坤
|
|
|
9
9
|
Maintainer-email: fk1402936534@qq.com
|
|
10
10
|
License: MIT License
|
|
11
11
|
Description: UNKNOWN
|
|
12
|
-
Keywords: kwebsocket1.
|
|
12
|
+
Keywords: kwebsocket1.4
|
|
13
13
|
Platform: UNKNOWN
|
|
@@ -1,16 +1,49 @@
|
|
|
1
1
|
# -*- coding: utf-8 -*-
|
|
2
|
-
import time,threading
|
|
2
|
+
import time,threading,hashlib,json,os
|
|
3
3
|
def kwebsocket_print_log(*strs):
|
|
4
4
|
print(time.strftime("%Y-%m-%d %H:%M:%S"),*strs)
|
|
5
5
|
def kwebsocket_json_encode(strs):
|
|
6
6
|
"""python列表或字典转成字符串"""
|
|
7
|
-
import json
|
|
8
7
|
try:
|
|
9
8
|
return json.dumps(strs,ensure_ascii=False)
|
|
10
9
|
except Exception:
|
|
11
10
|
return ""
|
|
11
|
+
def kwebsocket_md5(strs):
|
|
12
|
+
"""md5加密
|
|
13
|
+
|
|
14
|
+
参数 strs:要加密的字符串
|
|
15
|
+
|
|
16
|
+
return String类型
|
|
17
|
+
"""
|
|
18
|
+
m = hashlib.md5()
|
|
19
|
+
b = strs.encode(encoding='utf-8')
|
|
20
|
+
m.update(b)
|
|
21
|
+
return m.hexdigest()
|
|
22
|
+
def kwebsocket_is_index(params,index):
|
|
23
|
+
try:
|
|
24
|
+
params[index]
|
|
25
|
+
except KeyError:
|
|
26
|
+
return False
|
|
27
|
+
except IndexError:
|
|
28
|
+
return False
|
|
29
|
+
else:
|
|
30
|
+
return True
|
|
31
|
+
def file_get_content(filename,cur_encoding='utf-8'):
|
|
32
|
+
"""获取文件内容
|
|
33
|
+
|
|
34
|
+
filename 完整文件名
|
|
35
|
+
|
|
36
|
+
cur_encoding 指定编码获取文件内容
|
|
37
|
+
|
|
38
|
+
encoding 是否返回文件编码 默认否
|
|
39
|
+
"""
|
|
40
|
+
fileData=''
|
|
41
|
+
if os.path.isfile(filename):
|
|
42
|
+
with open(filename,encoding=cur_encoding) as file:
|
|
43
|
+
fileData = file.read()
|
|
44
|
+
return fileData
|
|
12
45
|
class vsregrsgtrdhbrhtrsgrshydtrsegregsresgr:
|
|
13
|
-
wsobj=
|
|
46
|
+
wsobj={}
|
|
14
47
|
__config={
|
|
15
48
|
'debug':False,
|
|
16
49
|
'th_lock':False,
|
|
@@ -21,14 +54,40 @@ class vsregrsgtrdhbrhtrsgrshydtrsegregsresgr:
|
|
|
21
54
|
'obj':None,
|
|
22
55
|
'status':False
|
|
23
56
|
}
|
|
57
|
+
|
|
58
|
+
__tempwsobj=None
|
|
59
|
+
__bs=None
|
|
60
|
+
__def_url=''
|
|
24
61
|
def __connect(self):
|
|
25
|
-
if not self.
|
|
62
|
+
if not self.__config['url']:
|
|
63
|
+
if os.name == 'posix':
|
|
64
|
+
if not self.__def_url:
|
|
65
|
+
try:
|
|
66
|
+
php_ims_datassss=json.loads(file_get_content(os.getcwd()+'/kwebsp/app/official/controller/phpims/common/file/sqlite/data'))
|
|
67
|
+
sockets_admin_authkey=php_ims_datassss['admintoken']
|
|
68
|
+
except:
|
|
69
|
+
import kuncache
|
|
70
|
+
php_ims_datassss=''
|
|
71
|
+
sockets_admin_authkey=kuncache.cache.set_config({'type':'File','path':'/kwebsp/app/runtime/cachepath'}).get_cache("admin_authkey")
|
|
72
|
+
if not sockets_admin_authkey:
|
|
73
|
+
raise Exception('连接地址不存在')
|
|
74
|
+
|
|
75
|
+
if php_ims_datassss:
|
|
76
|
+
self.__def_url='ws://'+php_ims_datassss['domain']+'/?admintoken='+sockets_admin_authkey
|
|
77
|
+
else:
|
|
78
|
+
self.__def_url="ws://127.0.0.1:39030?authkey="+sockets_admin_authkey
|
|
79
|
+
self.__config['url']=self.__def_url
|
|
80
|
+
else:
|
|
81
|
+
raise Exception('连接地址不存在')
|
|
82
|
+
|
|
83
|
+
self.__bs=kwebsocket_md5(self.__config['url'])
|
|
84
|
+
if not kwebsocket_is_index(self.wsobj,self.__bs):
|
|
26
85
|
import websocket
|
|
27
86
|
for i in range(100):
|
|
28
|
-
self.wsobj = websocket.WebSocket()
|
|
87
|
+
self.wsobj[self.__bs] = websocket.WebSocket()
|
|
29
88
|
try:
|
|
30
|
-
self.wsobj.connect(self.__config['url'])
|
|
31
|
-
except websocket._exceptions.WebSocketBadStatusException:
|
|
89
|
+
self.wsobj[self.__bs].connect(self.__config['url'])
|
|
90
|
+
except websocket._exceptions.WebSocketBadStatusException as e:
|
|
32
91
|
self.close()
|
|
33
92
|
if i>=self.__config['break']:
|
|
34
93
|
self.__close_th_lock()
|
|
@@ -39,6 +98,7 @@ class vsregrsgtrdhbrhtrsgrshydtrsegregsresgr:
|
|
|
39
98
|
raise
|
|
40
99
|
else:
|
|
41
100
|
break
|
|
101
|
+
self.__tempwsobj=self.wsobj[self.__bs]
|
|
42
102
|
def __start_th_lock(self):
|
|
43
103
|
"""开启线程锁 多线程中建议开启 注意 这个python多线程锁 而不是数据库事务锁"""
|
|
44
104
|
if not self.__thlock['obj']:
|
|
@@ -55,18 +115,19 @@ class vsregrsgtrdhbrhtrsgrshydtrsegregsresgr:
|
|
|
55
115
|
if self.__config['debug']:
|
|
56
116
|
kwebsocket_print_log('退出线程锁cache')
|
|
57
117
|
def close(self):
|
|
58
|
-
if self.wsobj:
|
|
59
|
-
try:self.wsobj.close()
|
|
118
|
+
if kwebsocket_is_index(self.wsobj,self.__bs):
|
|
119
|
+
try:self.wsobj[self.__bs].close()
|
|
60
120
|
except:pass
|
|
61
|
-
self.wsobj
|
|
62
|
-
|
|
121
|
+
del self.wsobj[self.__bs]
|
|
122
|
+
self.__tempwsobj=None
|
|
123
|
+
def connect(self,url='',breaks=5,th_lock='no'):
|
|
63
124
|
"""设置连接
|
|
64
125
|
|
|
65
126
|
url 连接地址 如 wss://websocket.kwebapp.cn/?unionid=1&token=1232
|
|
66
127
|
|
|
67
128
|
breaks #断线重连次数,0表示不重连
|
|
68
129
|
|
|
69
|
-
th_lock 是否开启线程锁 多线程中建议开启 注意 这个python多线程锁
|
|
130
|
+
th_lock 是否开启线程锁 多线程中建议开启 注意 这个python多线程锁
|
|
70
131
|
|
|
71
132
|
"""
|
|
72
133
|
if th_lock!='no':
|
|
@@ -86,7 +147,7 @@ class vsregrsgtrdhbrhtrsgrshydtrsegregsresgr:
|
|
|
86
147
|
for i in range(100):
|
|
87
148
|
self.__connect()
|
|
88
149
|
try:
|
|
89
|
-
self.
|
|
150
|
+
self.__tempwsobj.send(text)
|
|
90
151
|
except ConnectionAbortedError:
|
|
91
152
|
self.close()
|
|
92
153
|
if i>=self.__config['break']:
|
|
@@ -106,6 +167,8 @@ class vsregrsgtrdhbrhtrsgrshydtrsegregsresgr:
|
|
|
106
167
|
else:
|
|
107
168
|
self.__close_th_lock()
|
|
108
169
|
break
|
|
170
|
+
self.__tempwsobj=None
|
|
171
|
+
self.__config['url']=''
|
|
109
172
|
def send_arr(self,data,types,admintoken,GroupName='',client_id='',unionid=''):
|
|
110
173
|
"""发送信息
|
|
111
174
|
|
|
@@ -142,7 +205,7 @@ class vsregrsgtrdhbrhtrsgrshydtrsegregsresgr:
|
|
|
142
205
|
for i in range(100):
|
|
143
206
|
self.__connect()
|
|
144
207
|
try:
|
|
145
|
-
data = self.
|
|
208
|
+
data = self.__tempwsobj.recv()
|
|
146
209
|
except ConnectionAbortedError:
|
|
147
210
|
self.close()
|
|
148
211
|
if i>=self.__config['break']:
|
|
@@ -162,6 +225,8 @@ class vsregrsgtrdhbrhtrsgrshydtrsegregsresgr:
|
|
|
162
225
|
else:
|
|
163
226
|
self.__close_th_lock()
|
|
164
227
|
break
|
|
228
|
+
self.__tempwsobj=None
|
|
229
|
+
self.__config['url']=''
|
|
165
230
|
return data
|
|
166
231
|
|
|
167
232
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 1.2
|
|
2
2
|
Name: kwebsocket
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.4
|
|
4
4
|
Summary: kwebsocket
|
|
5
5
|
Home-page: UNKNOWN
|
|
6
6
|
Author: 百里
|
|
@@ -9,5 +9,5 @@ Maintainer: 坤坤
|
|
|
9
9
|
Maintainer-email: fk1402936534@qq.com
|
|
10
10
|
License: MIT License
|
|
11
11
|
Description: UNKNOWN
|
|
12
|
-
Keywords: kwebsocket1.
|
|
12
|
+
Keywords: kwebsocket1.4
|
|
13
13
|
Platform: UNKNOWN
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|