re-common 0.2.54__py3-none-any.whl → 2.0.1__py3-none-any.whl

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.
Files changed (207) hide show
  1. re_common/v2/baselibrary/s3object/baseboto3.py +230 -0
  2. re_common/v2/baselibrary/tools/dict_tools.py +24 -0
  3. re_common/v2/baselibrary/tools/search_hash_tools.py +33 -0
  4. re_common/v2/baselibrary/tools/text_matcher.py +223 -0
  5. re_common/v2/baselibrary/tools/unionfind_tools.py +60 -0
  6. re_common/v2/baselibrary/utils/BusinessStringUtil.py +74 -0
  7. re_common/v2/baselibrary/utils/author_smi.py +308 -0
  8. re_common/v2/baselibrary/utils/basedict.py +26 -0
  9. re_common/v2/baselibrary/utils/basehdfs.py +127 -0
  10. re_common/v2/baselibrary/utils/json_cls.py +11 -0
  11. re_common/v2/baselibrary/utils/string_bool.py +9 -0
  12. re_common/v2/baselibrary/utils/string_clear.py +98 -0
  13. re_common/v2/baselibrary/utils/stringutils.py +95 -0
  14. {re_common-0.2.54.dist-info → re_common-2.0.1.dist-info}/METADATA +1 -1
  15. re_common-2.0.1.dist-info/RECORD +25 -0
  16. re_common/baselibrary/__init__.py +0 -4
  17. re_common/baselibrary/baseabs/__init__.py +0 -7
  18. re_common/baselibrary/baseabs/baseabs.py +0 -26
  19. re_common/baselibrary/database/mbuilder.py +0 -132
  20. re_common/baselibrary/database/moudle.py +0 -93
  21. re_common/baselibrary/database/msqlite3.py +0 -194
  22. re_common/baselibrary/database/mysql.py +0 -169
  23. re_common/baselibrary/database/sql_factory.py +0 -26
  24. re_common/baselibrary/mthread/MThreadingRun.py +0 -486
  25. re_common/baselibrary/mthread/MThreadingRunEvent.py +0 -349
  26. re_common/baselibrary/mthread/__init__.py +0 -3
  27. re_common/baselibrary/mthread/mythreading.py +0 -695
  28. re_common/baselibrary/pakge_other/socks.py +0 -404
  29. re_common/baselibrary/readconfig/config_factory.py +0 -18
  30. re_common/baselibrary/readconfig/ini_config.py +0 -317
  31. re_common/baselibrary/readconfig/toml_config.py +0 -49
  32. re_common/baselibrary/temporary/envdata.py +0 -36
  33. re_common/baselibrary/tools/all_requests/aiohttp_request.py +0 -118
  34. re_common/baselibrary/tools/all_requests/httpx_requet.py +0 -102
  35. re_common/baselibrary/tools/all_requests/mrequest.py +0 -412
  36. re_common/baselibrary/tools/all_requests/requests_request.py +0 -81
  37. re_common/baselibrary/tools/batch_compre/__init__.py +0 -0
  38. re_common/baselibrary/tools/batch_compre/bijiao_batch.py +0 -31
  39. re_common/baselibrary/tools/contrast_db3.py +0 -123
  40. re_common/baselibrary/tools/copy_file.py +0 -39
  41. re_common/baselibrary/tools/db3_2_sizedb3.py +0 -102
  42. re_common/baselibrary/tools/foreachgz.py +0 -40
  43. re_common/baselibrary/tools/get_attr.py +0 -11
  44. re_common/baselibrary/tools/image_to_pdf.py +0 -62
  45. re_common/baselibrary/tools/java_code_deal.py +0 -139
  46. re_common/baselibrary/tools/javacode.py +0 -79
  47. re_common/baselibrary/tools/mdb_db3.py +0 -48
  48. re_common/baselibrary/tools/merge_file.py +0 -171
  49. re_common/baselibrary/tools/merge_gz_file.py +0 -165
  50. re_common/baselibrary/tools/mhdfstools/__init__.py +0 -0
  51. re_common/baselibrary/tools/mhdfstools/down_hdfs_files.py +0 -42
  52. re_common/baselibrary/tools/mhdfstools/hdfst.py +0 -42
  53. re_common/baselibrary/tools/mhdfstools/up_hdfs_files.py +0 -38
  54. re_common/baselibrary/tools/mongo_tools.py +0 -50
  55. re_common/baselibrary/tools/move_file.py +0 -170
  56. re_common/baselibrary/tools/move_mongo/__init__.py +0 -0
  57. re_common/baselibrary/tools/move_mongo/mongo_table_to_file.py +0 -63
  58. re_common/baselibrary/tools/move_mongo/move_mongo_table.py +0 -354
  59. re_common/baselibrary/tools/move_mongo/use_mttf.py +0 -18
  60. re_common/baselibrary/tools/move_mongo/use_mv.py +0 -93
  61. re_common/baselibrary/tools/mpandas/__init__.py +0 -0
  62. re_common/baselibrary/tools/mpandas/mpandasreadexcel.py +0 -125
  63. re_common/baselibrary/tools/mpandas/pandas_visualization.py +0 -8
  64. re_common/baselibrary/tools/myparsel.py +0 -104
  65. re_common/baselibrary/tools/rename_dir_file.py +0 -37
  66. re_common/baselibrary/tools/sequoiadb_utils.py +0 -398
  67. re_common/baselibrary/tools/split_line_to_many.py +0 -25
  68. re_common/baselibrary/tools/stringtodicts.py +0 -33
  69. re_common/baselibrary/tools/workwechant_bot.py +0 -84
  70. re_common/baselibrary/utils/__init__.py +0 -0
  71. re_common/baselibrary/utils/baseaiohttp.py +0 -296
  72. re_common/baselibrary/utils/baseaiomysql.py +0 -87
  73. re_common/baselibrary/utils/baseallstep.py +0 -191
  74. re_common/baselibrary/utils/baseavro.py +0 -19
  75. re_common/baselibrary/utils/baseboto3.py +0 -291
  76. re_common/baselibrary/utils/basecsv.py +0 -32
  77. re_common/baselibrary/utils/basedict.py +0 -133
  78. re_common/baselibrary/utils/basedir.py +0 -241
  79. re_common/baselibrary/utils/baseencode.py +0 -351
  80. re_common/baselibrary/utils/baseencoding.py +0 -29
  81. re_common/baselibrary/utils/baseesdsl.py +0 -86
  82. re_common/baselibrary/utils/baseexcel.py +0 -264
  83. re_common/baselibrary/utils/baseexcept.py +0 -109
  84. re_common/baselibrary/utils/basefile.py +0 -654
  85. re_common/baselibrary/utils/baseftp.py +0 -214
  86. re_common/baselibrary/utils/basegzip.py +0 -60
  87. re_common/baselibrary/utils/basehdfs.py +0 -135
  88. re_common/baselibrary/utils/basehttpx.py +0 -268
  89. re_common/baselibrary/utils/baseip.py +0 -87
  90. re_common/baselibrary/utils/basejson.py +0 -2
  91. re_common/baselibrary/utils/baselist.py +0 -32
  92. re_common/baselibrary/utils/basemotor.py +0 -190
  93. re_common/baselibrary/utils/basemssql.py +0 -98
  94. re_common/baselibrary/utils/baseodbc.py +0 -113
  95. re_common/baselibrary/utils/basepandas.py +0 -302
  96. re_common/baselibrary/utils/basepeewee.py +0 -11
  97. re_common/baselibrary/utils/basepika.py +0 -180
  98. re_common/baselibrary/utils/basepydash.py +0 -143
  99. re_common/baselibrary/utils/basepymongo.py +0 -230
  100. re_common/baselibrary/utils/basequeue.py +0 -22
  101. re_common/baselibrary/utils/baserar.py +0 -57
  102. re_common/baselibrary/utils/baserequest.py +0 -279
  103. re_common/baselibrary/utils/baseset.py +0 -8
  104. re_common/baselibrary/utils/basesmb.py +0 -403
  105. re_common/baselibrary/utils/basestring.py +0 -382
  106. re_common/baselibrary/utils/basetime.py +0 -320
  107. re_common/baselibrary/utils/basetuple.py +0 -0
  108. re_common/baselibrary/utils/baseurl.py +0 -121
  109. re_common/baselibrary/utils/basezip.py +0 -57
  110. re_common/baselibrary/utils/core/__init__.py +0 -8
  111. re_common/baselibrary/utils/core/bottomutils.py +0 -18
  112. re_common/baselibrary/utils/core/mdeprecated.py +0 -327
  113. re_common/baselibrary/utils/core/mlamada.py +0 -16
  114. re_common/baselibrary/utils/core/msginfo.py +0 -25
  115. re_common/baselibrary/utils/core/requests_core.py +0 -103
  116. re_common/baselibrary/utils/fateadm.py +0 -429
  117. re_common/baselibrary/utils/importfun.py +0 -123
  118. re_common/baselibrary/utils/mfaker.py +0 -57
  119. re_common/baselibrary/utils/my_abc/__init__.py +0 -3
  120. re_common/baselibrary/utils/my_abc/better_abc.py +0 -32
  121. re_common/baselibrary/utils/mylogger.py +0 -414
  122. re_common/baselibrary/utils/myredisclient.py +0 -861
  123. re_common/baselibrary/utils/pipupgrade.py +0 -21
  124. re_common/baselibrary/utils/ringlist.py +0 -85
  125. re_common/baselibrary/utils/version_compare.py +0 -36
  126. re_common/baselibrary/utils/ydmhttp.py +0 -126
  127. re_common/facade/__init__.py +0 -1
  128. re_common/facade/lazy_import.py +0 -11
  129. re_common/facade/loggerfacade.py +0 -25
  130. re_common/facade/mysqlfacade.py +0 -467
  131. re_common/facade/now.py +0 -31
  132. re_common/facade/sqlite3facade.py +0 -257
  133. re_common/facade/use/__init__.py +0 -0
  134. re_common/facade/use/mq_use_facade.py +0 -83
  135. re_common/facade/use/proxy_use_facade.py +0 -20
  136. re_common/libtest/__init__.py +0 -0
  137. re_common/libtest/base_dict_test.py +0 -19
  138. re_common/libtest/baseavro_test.py +0 -13
  139. re_common/libtest/basefile_test.py +0 -14
  140. re_common/libtest/basemssql_test.py +0 -77
  141. re_common/libtest/baseodbc_test.py +0 -8
  142. re_common/libtest/basepandas_test.py +0 -38
  143. re_common/libtest/get_attr_test/__init__.py +0 -0
  144. re_common/libtest/get_attr_test/get_attr_test_settings.py +0 -14
  145. re_common/libtest/get_attr_test/settings.py +0 -55
  146. re_common/libtest/idencode_test.py +0 -54
  147. re_common/libtest/iniconfig_test.py +0 -35
  148. re_common/libtest/ip_test.py +0 -35
  149. re_common/libtest/merge_file_test.py +0 -20
  150. re_common/libtest/mfaker_test.py +0 -9
  151. re_common/libtest/mm3_test.py +0 -32
  152. re_common/libtest/mylogger_test.py +0 -89
  153. re_common/libtest/myparsel_test.py +0 -28
  154. re_common/libtest/mysql_test.py +0 -151
  155. re_common/libtest/pymongo_test.py +0 -21
  156. re_common/libtest/split_test.py +0 -12
  157. re_common/libtest/sqlite3_merge_test.py +0 -6
  158. re_common/libtest/sqlite3_test.py +0 -34
  159. re_common/libtest/tomlconfig_test.py +0 -30
  160. re_common/libtest/use_tools_test/__init__.py +0 -3
  161. re_common/libtest/user/__init__.py +0 -5
  162. re_common/studio/__init__.py +0 -5
  163. re_common/studio/assignment_expressions.py +0 -37
  164. re_common/studio/mydash/__init__.py +0 -0
  165. re_common/studio/mydash/test1.py +0 -19
  166. re_common/studio/pydashstudio/__init__.py +0 -0
  167. re_common/studio/pydashstudio/first.py +0 -9
  168. re_common/studio/streamlitstudio/__init__.py +0 -0
  169. re_common/studio/streamlitstudio/first_app.py +0 -66
  170. re_common/studio/streamlitstudio/uber_pickups.py +0 -24
  171. re_common/studio/test.py +0 -19
  172. re_common/vip/__init__.py +0 -0
  173. re_common/vip/base_step_process.py +0 -11
  174. re_common/vip/baseencodeid.py +0 -91
  175. re_common/vip/changetaskname.py +0 -28
  176. re_common/vip/core_var.py +0 -24
  177. re_common/vip/mmh3Hash.py +0 -90
  178. re_common/vip/proxy/__init__.py +0 -0
  179. re_common/vip/proxy/allproxys.py +0 -127
  180. re_common/vip/proxy/allproxys_thread.py +0 -159
  181. re_common/vip/proxy/cnki_proxy.py +0 -153
  182. re_common/vip/proxy/kuaidaili.py +0 -87
  183. re_common/vip/proxy/proxy_all.py +0 -113
  184. re_common/vip/proxy/update_kuaidaili_0.py +0 -42
  185. re_common/vip/proxy/wanfang_proxy.py +0 -152
  186. re_common/vip/proxy/wp_proxy_all.py +0 -182
  187. re_common/vip/read_rawid_to_txt.py +0 -92
  188. re_common/vip/title/__init__.py +0 -5
  189. re_common/vip/title/transform/TransformBookTitleToZt.py +0 -125
  190. re_common/vip/title/transform/TransformConferenceTitleToZt.py +0 -139
  191. re_common/vip/title/transform/TransformCstadTitleToZt.py +0 -196
  192. re_common/vip/title/transform/TransformJournalTitleToZt.py +0 -203
  193. re_common/vip/title/transform/TransformPatentTitleToZt.py +0 -132
  194. re_common/vip/title/transform/TransformRegulationTitleToZt.py +0 -114
  195. re_common/vip/title/transform/TransformStandardTitleToZt.py +0 -135
  196. re_common/vip/title/transform/TransformThesisTitleToZt.py +0 -135
  197. re_common/vip/title/transform/__init__.py +0 -11
  198. re_common-0.2.54.dist-info/RECORD +0 -194
  199. /re_common/{baselibrary/database → v2}/__init__.py +0 -0
  200. /re_common/{baselibrary/pakge_other → v2/baselibrary}/__init__.py +0 -0
  201. /re_common/{baselibrary/readconfig → v2/baselibrary/s3object}/__init__.py +0 -0
  202. /re_common/{baselibrary/temporary → v2/baselibrary/tools}/__init__.py +0 -0
  203. /re_common/{baselibrary/tools/__init__.py → v2/baselibrary/tools/list_tools.py} +0 -0
  204. /re_common/{baselibrary/tools/all_requests → v2/baselibrary/utils}/__init__.py +0 -0
  205. {re_common-0.2.54.dist-info → re_common-2.0.1.dist-info}/LICENSE +0 -0
  206. {re_common-0.2.54.dist-info → re_common-2.0.1.dist-info}/WHEEL +0 -0
  207. {re_common-0.2.54.dist-info → re_common-2.0.1.dist-info}/top_level.txt +0 -0
@@ -1,404 +0,0 @@
1
- """SocksiPy - Python SOCKS module.
2
- Version 1.00
3
-
4
- Copyright 2006 Dan-Haim. All rights reserved.
5
-
6
- Redistribution and use in source and binary forms, with or without modification,
7
- are permitted provided that the following conditions are met:
8
- 1. Redistributions of source code must retain the above copyright notice, this
9
- list of conditions and the following disclaimer.
10
- 2. Redistributions in binary form must reproduce the above copyright notice,
11
- this list of conditions and the following disclaimer in the documentation
12
- and/or other materials provided with the distribution.
13
- 3. Neither the name of Dan Haim nor the names of his contributors may be used
14
- to endorse or promote products derived from this software without specific
15
- prior written permission.
16
-
17
- THIS SOFTWARE IS PROVIDED BY DAN HAIM "AS IS" AND ANY EXPRESS OR IMPLIED
18
- WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19
- MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
20
- EVENT SHALL DAN HAIM OR HIS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
21
- INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22
- LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA
23
- OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
24
- LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
25
- OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMANGE.
26
-
27
-
28
- This module provides a standard socket-like interface for Python
29
- for tunneling connections through SOCKS proxies.
30
-
31
- """
32
-
33
- import socket
34
- import struct
35
-
36
- PROXY_TYPE_SOCKS4 = 1
37
- PROXY_TYPE_SOCKS5 = 2
38
- PROXY_TYPE_HTTP = 3
39
-
40
- _defaultproxy = None
41
- _orgsocket = socket.socket
42
-
43
-
44
- class ProxyError(Exception):
45
- def __init__(self, value):
46
- self.value = value
47
-
48
- def __str__(self):
49
- return repr(self.value)
50
-
51
-
52
- class GeneralProxyError(ProxyError):
53
- def __init__(self, value):
54
- self.value = value
55
-
56
- def __str__(self):
57
- return repr(self.value)
58
-
59
-
60
- class Socks5AuthError(ProxyError):
61
- def __init__(self, value):
62
- self.value = value
63
-
64
- def __str__(self):
65
- return repr(self.value)
66
-
67
-
68
- class Socks5Error(ProxyError):
69
- def __init__(self, value):
70
- self.value = value
71
-
72
- def __str__(self):
73
- return repr(self.value)
74
-
75
-
76
- class Socks4Error(ProxyError):
77
- def __init__(self, value):
78
- self.value = value
79
-
80
- def __str__(self):
81
- return repr(self.value)
82
-
83
-
84
- class HTTPError(ProxyError):
85
- def __init__(self, value):
86
- self.value = value
87
-
88
- def __str__(self):
89
- return repr(self.value)
90
-
91
-
92
- _generalerrors = ("success",
93
- "invalid data",
94
- "not connected",
95
- "not available",
96
- "bad proxy type",
97
- "bad input")
98
-
99
- _socks5errors = ("succeeded",
100
- "general SOCKS server failure",
101
- "connection not allowed by ruleset",
102
- "Network unreachable",
103
- "Host unreachable",
104
- "Connection refused",
105
- "TTL expired",
106
- "Command not supported",
107
- "Address type not supported",
108
- "Unknown error")
109
-
110
- _socks5autherrors = ("succeeded",
111
- "authentication is required",
112
- "all offered authentication methods were rejected",
113
- "unknown username or invalid password",
114
- "unknown error")
115
-
116
- _socks4errors = ("request granted",
117
- "request rejected or failed",
118
- "request rejected because SOCKS server cannot connect to identd on the client",
119
- "request rejected because the client program and identd report different user-ids",
120
- "unknown error")
121
-
122
-
123
- def setdefaultproxy(proxytype=None, addr=None, port=None, rdns=True, username=None, password=None):
124
- """setdefaultproxy(proxytype, addr[, port[, rdns[, username[, password]]]])
125
- Sets a default proxy which all further socksocket objects will use,
126
- unless explicitly changed.
127
- """
128
- global _defaultproxy
129
- _defaultproxy = (proxytype, addr, port, rdns, username, password)
130
-
131
-
132
- class socksocket(socket.socket):
133
- """socksocket([family[, type[, proto]]]) -> socket object
134
-
135
- Open a SOCKS enabled socket. The parameters are the same as
136
- those of the standard socket init. In order for SOCKS to work,
137
- you must specify family=AF_INET, type=SOCK_STREAM and proto=0.
138
- """
139
-
140
- def __init__(self, family=socket.AF_INET, type=socket.SOCK_STREAM, proto=0, _sock=None):
141
- _orgsocket.__init__(self, family, type, proto, _sock)
142
- if _defaultproxy != None:
143
- self.__proxy = _defaultproxy
144
- else:
145
- self.__proxy = (None, None, None, None, None, None)
146
- self.__proxysockname = None
147
- self.__proxypeername = None
148
-
149
- def __recvall(self, bytes):
150
- """__recvall(bytes) -> data
151
- Receive EXACTLY the number of bytes requested from the socket.
152
- Blocks until the required number of bytes have been received.
153
- """
154
- data = ""
155
- while len(data) < bytes:
156
- data = data + self.recv(bytes - len(data))
157
- return data
158
-
159
- def setproxy(self, proxytype=None, addr=None, port=None, rdns=True, username=None, password=None):
160
- """setproxy(proxytype, addr[, port[, rdns[, username[, password]]]])
161
- Sets the proxy to be used.
162
- proxytype - The type of the proxy to be used. Three types
163
- are supported: PROXY_TYPE_SOCKS4 (including socks4a),
164
- PROXY_TYPE_SOCKS5 and PROXY_TYPE_HTTP
165
- addr - The address of the server (IP or DNS).
166
- port - The port of the server. Defaults to 1080 for SOCKS
167
- servers and 8080 for HTTP proxy servers.
168
- rdns - Should DNS queries be preformed on the remote side
169
- (rather than the local side). The default is True.
170
- Note: This has no effect with SOCKS4 servers.
171
- username - Username to authenticate with to the server.
172
- The default is no authentication.
173
- password - Password to authenticate with to the server.
174
- Only relevant when username is also provided.
175
- """
176
- self.__proxy = (proxytype, addr, port, rdns, username, password)
177
-
178
- def __negotiatesocks5(self, destaddr, destport):
179
- """__negotiatesocks5(self,destaddr,destport)
180
- Negotiates a connection through a SOCKS5 server.
181
- """
182
- # First we'll send the authentication packages we support.
183
- if (self.__proxy[4] != None) and (self.__proxy[5] != None):
184
- # The username/password details were supplied to the
185
- # setproxy method so we support the USERNAME/PASSWORD
186
- # authentication (in addition to the standard none).
187
- self.sendall("\x05\x02\x00\x02")
188
- else:
189
- # No username/password were entered, therefore we
190
- # only support connections with no authentication.
191
- self.sendall("\x05\x01\x00")
192
- # We'll receive the server's response to determine which
193
- # method was selected
194
- chosenauth = self.__recvall(2)
195
- if chosenauth[0] != "\x05":
196
- self.close()
197
- raise GeneralProxyError((1, _generalerrors[1]))
198
- # Check the chosen authentication method
199
- if chosenauth[1] == "\x00":
200
- # No authentication is required
201
- pass
202
- elif chosenauth[1] == "\x02":
203
- # Okay, we need to perform a basic username/password
204
- # authentication.
205
- self.sendall(
206
- "\x01" + chr(len(self.__proxy[4])) + self.__proxy[4] + chr(len(self.proxy[5])) + self.__proxy[5])
207
- authstat = self.__recvall(2)
208
- if authstat[0] != "\x01":
209
- # Bad response
210
- self.close()
211
- raise GeneralProxyError((1, _generalerrors[1]))
212
- if authstat[1] != "\x00":
213
- # Authentication failed
214
- self.close()
215
- raise Socks5AuthError((3, _socks5autherrors[3]))
216
- # Authentication succeeded
217
- else:
218
- # Reaching here is always bad
219
- self.close()
220
- if chosenauth[1] == "\xFF":
221
- raise Socks5AuthError((2, _socks5autherrors[2]))
222
- else:
223
- raise GeneralProxyError((1, _generalerrors[1]))
224
- # Now we can request the actual connection
225
- req = "\x05\x01\x00"
226
- # If the given destination address is an IP address, we'll
227
- # use the IPv4 address request even if remote resolving was specified.
228
- try:
229
- ipaddr = socket.inet_aton(destaddr)
230
- req = req + "\x01" + ipaddr
231
- except socket.error:
232
- # Well it's not an IP number, so it's probably a DNS name.
233
- if self.__proxy[3] == True:
234
- # Resolve remotely
235
- ipaddr = None
236
- req = req + "\x03" + chr(len(destaddr)) + destaddr
237
- else:
238
- # Resolve locally
239
- ipaddr = socket.inet_aton(socket.gethostbyname(destaddr))
240
- req = req + "\x01" + ipaddr
241
- req = req + struct.pack(">H", destport)
242
- self.sendall(req)
243
- # Get the response
244
- resp = self.__recvall(4)
245
- if resp[0] != "\x05":
246
- self.close()
247
- raise GeneralProxyError((1, _generalerrors[1]))
248
- elif resp[1] != "\x00":
249
- # Connection failed
250
- self.close()
251
- if ord(resp[1]) <= 8:
252
- raise Socks5Error(ord(resp[1]), _generalerrors[ord(resp[1])])
253
- else:
254
- raise Socks5Error(9, _generalerrors[9])
255
- # Get the bound address/port
256
- elif resp[3] == "\x01":
257
- boundaddr = self.__recvall(4)
258
- elif resp[3] == "\x03":
259
- resp = resp + self.recv(1)
260
- boundaddr = self.__recvall(resp[4])
261
- else:
262
- self.close()
263
- raise GeneralProxyError((1, _generalerrors[1]))
264
- boundport = struct.unpack(">H", self.__recvall(2))[0]
265
- self.__proxysockname = (boundaddr, boundport)
266
- if ipaddr != None:
267
- self.__proxypeername = (socket.inet_ntoa(ipaddr), destport)
268
- else:
269
- self.__proxypeername = (destaddr, destport)
270
-
271
- def getproxysockname(self):
272
- """getsockname() -> address info
273
- Returns the bound IP address and port number at the proxy.
274
- """
275
- return self.__proxysockname
276
-
277
- def getproxypeername(self):
278
- """getproxypeername() -> address info
279
- Returns the IP and port number of the proxy.
280
- """
281
- return _orgsocket.getpeername(self)
282
-
283
- def getpeername(self):
284
- """getpeername() -> address info
285
- Returns the IP address and port number of the destination
286
- machine (note: getproxypeername returns the proxy)
287
- """
288
- return self.__proxypeername
289
-
290
- def __negotiatesocks4(self, destaddr, destport):
291
- """__negotiatesocks4(self,destaddr,destport)
292
- Negotiates a connection through a SOCKS4 server.
293
- """
294
- # Check if the destination address provided is an IP address
295
- rmtrslv = False
296
- try:
297
- ipaddr = socket.inet_aton(destaddr)
298
- except socket.error:
299
- # It's a DNS name. Check where it should be resolved.
300
- if self.__proxy[3] == True:
301
- ipaddr = "\x00\x00\x00\x01"
302
- rmtrslv = True
303
- else:
304
- ipaddr = socket.inet_aton(socket.gethostbyname(destaddr))
305
- # Construct the request packet
306
- req = "\x04\x01" + struct.pack(">H", destport) + ipaddr
307
- # The username parameter is considered userid for SOCKS4
308
- if self.__proxy[4] != None:
309
- req = req + self.__proxy[4]
310
- req = req + "\x00"
311
- # DNS name if remote resolving is required
312
- # NOTE: This is actually an extension to the SOCKS4 protocol
313
- # called SOCKS4A and may not be supported in all cases.
314
- if rmtrslv == True:
315
- req = req + destaddr + "\x00"
316
- self.sendall(req)
317
- # Get the response from the server
318
- resp = self.__recvall(8)
319
- if resp[0] != "\x00":
320
- # Bad data
321
- self.close()
322
- raise GeneralProxyError((1, _generalerrors[1]))
323
- if resp[1] != "\x5A":
324
- # Server returned an error
325
- self.close()
326
- if ord(resp[1]) in (91, 92, 93):
327
- self.close()
328
- raise Socks4Error((ord(resp[1]), _socks4errors[ord(resp[1]) - 90]))
329
- else:
330
- raise Socks4Error((94, _socks4errors[4]))
331
- # Get the bound address/port
332
- self.__proxysockname = (socket.inet_ntoa(resp[4:]), struct.unpack(">H", resp[2:4])[0])
333
- if rmtrslv != None:
334
- self.__proxypeername = (socket.inet_ntoa(ipaddr), destport)
335
- else:
336
- self.__proxypeername = (destaddr, destport)
337
-
338
- def __negotiatehttp(self, destaddr, destport):
339
- """__negotiatehttp(self,destaddr,destport)
340
- Negotiates a connection through an HTTP server.
341
- """
342
- # If we need to resolve locally, we do this now
343
- if self.__proxy[3] == False:
344
- addr = socket.gethostbyname(destaddr)
345
- else:
346
- addr = destaddr
347
- self.sendall("CONNECT " + addr + ":" + str(destport) + " HTTP/1.1\r\n" + "Host: " + destaddr + "\r\n\r\n")
348
- # We read the response until we get the string "\r\n\r\n"
349
- resp = self.recv(1)
350
- while resp.find("\r\n\r\n") == -1:
351
- resp = resp + self.recv(1)
352
- # We just need the first line to check if the connection
353
- # was successful
354
- statusline = resp.splitlines()[0].split(" ", 2)
355
- if statusline[0] not in ("HTTP/1.0", "HTTP/1.1"):
356
- self.close()
357
- raise GeneralProxyError((1, _generalerrors[1]))
358
- try:
359
- statuscode = int(statusline[1])
360
- except ValueError:
361
- self.close()
362
- raise GeneralProxyError((1, _generalerrors[1]))
363
- if statuscode != 200:
364
- self.close()
365
- raise HTTPError((statuscode, statusline[2]))
366
- self.__proxysockname = ("0.0.0.0", 0)
367
- self.__proxypeername = (addr, destport)
368
-
369
- def connect(self, destpair):
370
- """connect(self,despair)
371
- Connects to the specified destination through a proxy.
372
- destpar - A tuple of the IP/DNS address and the port number.
373
- (identical to socket's connect).
374
- To select the proxy server use setproxy().
375
- """
376
- # Do a minimal input check first
377
- if (type(destpair) in (list, tuple) == False) or (len(destpair) < 2) or (type(destpair[0]) != str) or (
378
- type(destpair[1]) != int):
379
- raise GeneralProxyError((5, _generalerrors[5]))
380
- if self.__proxy[0] == PROXY_TYPE_SOCKS5:
381
- if self.__proxy[2] != None:
382
- portnum = self.__proxy[2]
383
- else:
384
- portnum = 1080
385
- _orgsocket.connect(self, (self.__proxy[1], portnum))
386
- self.__negotiatesocks5(destpair[0], destpair[1])
387
- elif self.__proxy[0] == PROXY_TYPE_SOCKS4:
388
- if self.__proxy[2] != None:
389
- portnum = self.__proxy[2]
390
- else:
391
- portnum = 1080
392
- _orgsocket.connect(self, (self.__proxy[1], portnum))
393
- self.__negotiatesocks4(destpair[0], destpair[1])
394
- elif self.__proxy[0] == PROXY_TYPE_HTTP:
395
- if self.__proxy[2] != None:
396
- portnum = self.__proxy[2]
397
- else:
398
- portnum = 8080
399
- _orgsocket.connect(self, (self.__proxy[1], portnum))
400
- self.__negotiatehttp(destpair[0], destpair[1])
401
- elif self.__proxy[0] == None:
402
- _orgsocket.connect(self, (destpair[0], destpair[1]))
403
- else:
404
- raise GeneralProxyError((4, _generalerrors[4]))
@@ -1,18 +0,0 @@
1
- from re_common.baselibrary.baseabs import BaseAbs
2
-
3
-
4
- class ConfigFactory(BaseAbs):
5
-
6
- @staticmethod
7
- def ini_factory(type='ini'):
8
- if type == 'ini':
9
- from re_common.baselibrary.readconfig.ini_config import IniConfig
10
- return IniConfig()
11
- assert 0, "err sql type please check: %s" % type
12
-
13
- @staticmethod
14
- def toml_factory(type='toml'):
15
- from re_common.baselibrary.readconfig.toml_config import TomlConfig
16
- if type == 'toml':
17
- return TomlConfig()
18
- assert 0, "err sql type please check: %s" % type