whatap-python 2.1.0__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 (227) hide show
  1. whatap/LICENSE +0 -0
  2. whatap/README.rst +49 -0
  3. whatap/__init__.py +923 -0
  4. whatap/__main__.py +4 -0
  5. whatap/agent/darwin/amd64/whatap_python +0 -0
  6. whatap/agent/darwin/arm64/whatap_python +0 -0
  7. whatap/agent/linux/amd64/whatap_python +0 -0
  8. whatap/agent/linux/arm64/whatap_python +0 -0
  9. whatap/agent/windows/whatap_python.exe +0 -0
  10. whatap/bootstrap/__init__.py +0 -0
  11. whatap/bootstrap/sitecustomize.py +19 -0
  12. whatap/build.py +4 -0
  13. whatap/conf/__init__.py +0 -0
  14. whatap/conf/configuration.py +280 -0
  15. whatap/conf/configure.py +105 -0
  16. whatap/conf/license.py +49 -0
  17. whatap/control/__init__.py +0 -0
  18. whatap/counter/__init__.py +14 -0
  19. whatap/counter/counter_manager.py +45 -0
  20. whatap/counter/tasks/__init__.py +3 -0
  21. whatap/counter/tasks/base_task.py +26 -0
  22. whatap/counter/tasks/llm_evaluator_task.py +501 -0
  23. whatap/counter/tasks/llm_log_sink_task.py +309 -0
  24. whatap/counter/tasks/llm_stat_task.py +78 -0
  25. whatap/counter/tasks/openfiledescriptor.py +67 -0
  26. whatap/io/__init__.py +1 -0
  27. whatap/io/data_inputx.py +161 -0
  28. whatap/io/data_outputx.py +262 -0
  29. whatap/llm/__init__.py +17 -0
  30. whatap/llm/definitions.py +43 -0
  31. whatap/llm/evaluators/__init__.py +136 -0
  32. whatap/llm/evaluators/base.py +114 -0
  33. whatap/llm/evaluators/builtins/__init__.py +91 -0
  34. whatap/llm/evaluators/builtins/answer_relevance.py +46 -0
  35. whatap/llm/evaluators/builtins/combined_judge.py +271 -0
  36. whatap/llm/evaluators/builtins/factuality.py +71 -0
  37. whatap/llm/evaluators/builtins/hallucination.py +97 -0
  38. whatap/llm/evaluators/builtins/llm_judge.py +516 -0
  39. whatap/llm/evaluators/builtins/pii_leak.py +214 -0
  40. whatap/llm/evaluators/builtins/prompt_injection.py +71 -0
  41. whatap/llm/evaluators/builtins/toxicity.py +53 -0
  42. whatap/llm/evaluators/builtins/url_scan.py +194 -0
  43. whatap/llm/evaluators/registry.py +192 -0
  44. whatap/llm/evaluators/sampler.py +83 -0
  45. whatap/llm/evaluators/scope.py +334 -0
  46. whatap/llm/features.py +66 -0
  47. whatap/llm/log_sink_packs/__init__.py +9 -0
  48. whatap/llm/log_sink_packs/llm_input_message.py +16 -0
  49. whatap/llm/log_sink_packs/llm_log_sink_pack.py +72 -0
  50. whatap/llm/log_sink_packs/llm_output_message.py +19 -0
  51. whatap/llm/log_sink_packs/llm_step_eval_status.py +94 -0
  52. whatap/llm/log_sink_packs/llm_step_status.py +118 -0
  53. whatap/llm/log_sink_packs/llm_system_message.py +16 -0
  54. whatap/llm/log_sink_packs/llm_tool_calls.py +44 -0
  55. whatap/llm/log_sink_packs/llm_tool_results.py +16 -0
  56. whatap/llm/log_sink_packs/llm_tx_status.py +108 -0
  57. whatap/llm/pricing.py +236 -0
  58. whatap/llm/prompt_meta.py +288 -0
  59. whatap/llm/providers/__init__.py +0 -0
  60. whatap/llm/providers/anthropic/__init__.py +37 -0
  61. whatap/llm/providers/anthropic/messages/__init__.py +0 -0
  62. whatap/llm/providers/anthropic/messages/messages.py +70 -0
  63. whatap/llm/providers/anthropic/messages/messages_context.py +76 -0
  64. whatap/llm/providers/anthropic/messages/messages_extractor.py +126 -0
  65. whatap/llm/providers/interceptor.py +182 -0
  66. whatap/llm/providers/openai/__init__.py +133 -0
  67. whatap/llm/providers/openai/chat/__init__.py +0 -0
  68. whatap/llm/providers/openai/chat/chat.py +82 -0
  69. whatap/llm/providers/openai/chat/chat_context.py +78 -0
  70. whatap/llm/providers/openai/chat/chat_extractor.py +127 -0
  71. whatap/llm/providers/openai/completions/__init__.py +0 -0
  72. whatap/llm/providers/openai/completions/completions.py +70 -0
  73. whatap/llm/providers/openai/completions/completions_context.py +31 -0
  74. whatap/llm/providers/openai/completions/completions_extractor.py +61 -0
  75. whatap/llm/providers/openai/content_parser.py +41 -0
  76. whatap/llm/providers/openai/embeddings/__init__.py +0 -0
  77. whatap/llm/providers/openai/embeddings/embeddings.py +59 -0
  78. whatap/llm/providers/openai/embeddings/embeddings_context.py +25 -0
  79. whatap/llm/providers/openai/embeddings/embeddings_extractor.py +26 -0
  80. whatap/llm/providers/openai/responses/__init__.py +0 -0
  81. whatap/llm/providers/openai/responses/responses.py +70 -0
  82. whatap/llm/providers/openai/responses/responses_context.py +88 -0
  83. whatap/llm/providers/openai/responses/responses_extractor.py +126 -0
  84. whatap/llm/providers/stream_accumulator.py +73 -0
  85. whatap/llm/stats/__init__.py +35 -0
  86. whatap/llm/stats/active_stat.py +86 -0
  87. whatap/llm/stats/answer_relevance_eval_stat.py +10 -0
  88. whatap/llm/stats/api_status_stat.py +35 -0
  89. whatap/llm/stats/base_stat.py +107 -0
  90. whatap/llm/stats/combined_judge_eval_stat.py +11 -0
  91. whatap/llm/stats/error_stat.py +59 -0
  92. whatap/llm/stats/eval_stat.py +225 -0
  93. whatap/llm/stats/factuality_eval_stat.py +10 -0
  94. whatap/llm/stats/feature_stat.py +104 -0
  95. whatap/llm/stats/finish_stat.py +105 -0
  96. whatap/llm/stats/hallucination_eval_stat.py +10 -0
  97. whatap/llm/stats/meter.py +18 -0
  98. whatap/llm/stats/perf_stat.py +117 -0
  99. whatap/llm/stats/pii_leak_eval_stat.py +12 -0
  100. whatap/llm/stats/prompt_injection_eval_stat.py +10 -0
  101. whatap/llm/stats/token_usage_stat.py +133 -0
  102. whatap/llm/stats/toxicity_eval_stat.py +10 -0
  103. whatap/llm/stats/url_scan_eval_stat.py +12 -0
  104. whatap/net/__init__.py +0 -0
  105. whatap/net/async_sender.py +107 -0
  106. whatap/net/packet_enum.py +44 -0
  107. whatap/net/packet_type_enum.py +31 -0
  108. whatap/net/param_def.py +69 -0
  109. whatap/net/stackhelper.py +87 -0
  110. whatap/net/udp_session.py +394 -0
  111. whatap/net/udp_thread.py +54 -0
  112. whatap/pack/__init__.py +0 -0
  113. whatap/pack/logSinkPack.py +77 -0
  114. whatap/pack/pack.py +34 -0
  115. whatap/pack/pack_enum.py +41 -0
  116. whatap/pack/tagCountPack.py +61 -0
  117. whatap/scripts/__init__.py +208 -0
  118. whatap/trace/__init__.py +12 -0
  119. whatap/trace/mod/__init__.py +0 -0
  120. whatap/trace/mod/amqp/__init__.py +0 -0
  121. whatap/trace/mod/amqp/kombu.py +122 -0
  122. whatap/trace/mod/amqp/pika.py +62 -0
  123. whatap/trace/mod/application/__init__.py +0 -0
  124. whatap/trace/mod/application/bottle.py +34 -0
  125. whatap/trace/mod/application/celery.py +81 -0
  126. whatap/trace/mod/application/cherrypy.py +30 -0
  127. whatap/trace/mod/application/django.py +287 -0
  128. whatap/trace/mod/application/django_asgi.py +266 -0
  129. whatap/trace/mod/application/django_py3.py +251 -0
  130. whatap/trace/mod/application/fastapi/__init__.py +31 -0
  131. whatap/trace/mod/application/fastapi/endpoint.py +73 -0
  132. whatap/trace/mod/application/fastapi/exception_log.py +63 -0
  133. whatap/trace/mod/application/fastapi/instrumentation.py +204 -0
  134. whatap/trace/mod/application/fastapi/scope.py +115 -0
  135. whatap/trace/mod/application/fastapi/transaction.py +67 -0
  136. whatap/trace/mod/application/flask.py +52 -0
  137. whatap/trace/mod/application/frappe.py +224 -0
  138. whatap/trace/mod/application/graphql.py +170 -0
  139. whatap/trace/mod/application/nameko.py +39 -0
  140. whatap/trace/mod/application/odoo.py +63 -0
  141. whatap/trace/mod/application/starlette.py +126 -0
  142. whatap/trace/mod/application/tornado.py +163 -0
  143. whatap/trace/mod/application/wsgi.py +195 -0
  144. whatap/trace/mod/database/__init__.py +0 -0
  145. whatap/trace/mod/database/cxoracle.py +49 -0
  146. whatap/trace/mod/database/mongo.py +169 -0
  147. whatap/trace/mod/database/mysql.py +80 -0
  148. whatap/trace/mod/database/neo4j.py +90 -0
  149. whatap/trace/mod/database/psycopg2.py +45 -0
  150. whatap/trace/mod/database/psycopg3.py +359 -0
  151. whatap/trace/mod/database/redis.py +122 -0
  152. whatap/trace/mod/database/sqlalchemy.py +213 -0
  153. whatap/trace/mod/database/sqlite3.py +130 -0
  154. whatap/trace/mod/database/util.py +630 -0
  155. whatap/trace/mod/email/__init__.py +0 -0
  156. whatap/trace/mod/email/smtp.py +78 -0
  157. whatap/trace/mod/httpc/__init__.py +0 -0
  158. whatap/trace/mod/httpc/django.py +31 -0
  159. whatap/trace/mod/httpc/httplib.py +70 -0
  160. whatap/trace/mod/httpc/httpx.py +62 -0
  161. whatap/trace/mod/httpc/requests.py +20 -0
  162. whatap/trace/mod/httpc/urllib3.py +27 -0
  163. whatap/trace/mod/httpc/util.py +388 -0
  164. whatap/trace/mod/logging.py +161 -0
  165. whatap/trace/mod/plugin.py +84 -0
  166. whatap/trace/mod/standalone/__init__.py +0 -0
  167. whatap/trace/mod/standalone/multiple.py +293 -0
  168. whatap/trace/mod/standalone/single.py +135 -0
  169. whatap/trace/simple_trace_context.py +18 -0
  170. whatap/trace/trace_context.py +212 -0
  171. whatap/trace/trace_context_manager.py +244 -0
  172. whatap/trace/trace_error.py +84 -0
  173. whatap/trace/trace_handler.py +89 -0
  174. whatap/trace/trace_import.py +91 -0
  175. whatap/trace/trace_module_definition.py +156 -0
  176. whatap/util/__init__.py +0 -0
  177. whatap/util/bit_util.py +49 -0
  178. whatap/util/cardinality/__init__.py +0 -0
  179. whatap/util/cardinality/hyperloglog.py +84 -0
  180. whatap/util/cardinality/murmurhash.py +20 -0
  181. whatap/util/cardinality/registerset.py +60 -0
  182. whatap/util/compare_util.py +19 -0
  183. whatap/util/date_util.py +55 -0
  184. whatap/util/debug_util.py +73 -0
  185. whatap/util/escape_literal_sql.py +233 -0
  186. whatap/util/frame_util.py +20 -0
  187. whatap/util/hash_util.py +103 -0
  188. whatap/util/hexa32.py +66 -0
  189. whatap/util/int_set.py +199 -0
  190. whatap/util/ip_util.py +63 -0
  191. whatap/util/keygen.py +11 -0
  192. whatap/util/linked_list.py +113 -0
  193. whatap/util/linked_map.py +359 -0
  194. whatap/util/metering_util.py +103 -0
  195. whatap/util/request_double_queue.py +68 -0
  196. whatap/util/request_queue.py +60 -0
  197. whatap/util/string_util.py +20 -0
  198. whatap/util/throttle_util.py +99 -0
  199. whatap/util/userid_util.py +134 -0
  200. whatap/value/__init__.py +1 -0
  201. whatap/value/blob_value.py +38 -0
  202. whatap/value/boolean_value.py +33 -0
  203. whatap/value/decimal_value.py +36 -0
  204. whatap/value/double_summary.py +86 -0
  205. whatap/value/double_value.py +33 -0
  206. whatap/value/float_array.py +42 -0
  207. whatap/value/float_value.py +34 -0
  208. whatap/value/int_array.py +42 -0
  209. whatap/value/ip4_value.py +50 -0
  210. whatap/value/list_value.py +105 -0
  211. whatap/value/long_array.py +44 -0
  212. whatap/value/long_summary.py +83 -0
  213. whatap/value/map_value.py +154 -0
  214. whatap/value/null_value.py +21 -0
  215. whatap/value/number_value.py +33 -0
  216. whatap/value/summary_value.py +39 -0
  217. whatap/value/text_array.py +58 -0
  218. whatap/value/text_hash_value.py +37 -0
  219. whatap/value/text_value.py +43 -0
  220. whatap/value/value.py +26 -0
  221. whatap/value/value_enum.py +80 -0
  222. whatap/whatap.conf +14 -0
  223. whatap_python-2.1.0.dist-info/METADATA +87 -0
  224. whatap_python-2.1.0.dist-info/RECORD +227 -0
  225. whatap_python-2.1.0.dist-info/WHEEL +5 -0
  226. whatap_python-2.1.0.dist-info/entry_points.txt +6 -0
  227. whatap_python-2.1.0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,233 @@
1
+ class STAT(object):
2
+ NORMAL = 0
3
+ COMMENT = 1
4
+ ALPHABET = 2
5
+ NUMBER = 3
6
+ QUTATION = 4
7
+ COLON = 5
8
+
9
+
10
+ class EscapeLiteralSQL(object):
11
+ def __init__(self, sql=''):
12
+ self.substitute = '#'
13
+ self.substitute_num = '#'
14
+ self.substitute_str_mode = False
15
+ self.pos = 0
16
+ self.chars = list(sql)
17
+ self.length = len(self.chars)
18
+ self.parsedSql = ''
19
+ self.param = ''
20
+ self.status = -1
21
+ self.sqlType = 0
22
+
23
+ def setSubstitute(self, chr):
24
+ self.substitute = chr
25
+
26
+ if self.substitute_str_mode:
27
+ self.substitute_num = '"' + chr + '"'
28
+ else:
29
+ self.substitute_num = self.substitute
30
+
31
+ return self
32
+
33
+ def setSubstituteStringMode(self, b):
34
+ if self.substitute_str_mode == b:
35
+ return self
36
+
37
+ self.substitute_str_mode = b
38
+ if self.substitute_str_mode:
39
+ self.substitute_num = '"' + self.substitute + '"'
40
+ else:
41
+ self.substitute_num = self.substitute
42
+ return self
43
+
44
+ def process(self):
45
+ self.status = STAT.NORMAL
46
+
47
+ for c in self.chars:
48
+ if c in ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']:
49
+ self._number()
50
+ elif c == ':':
51
+ self._colon()
52
+ elif c == '.':
53
+ self._dot()
54
+ elif c == '-':
55
+ self._minus()
56
+ elif c == '/':
57
+ self._slash()
58
+ elif c == '*':
59
+ self._astar()
60
+ elif c in ['\'', '\"']:
61
+ self._quotation()
62
+ else:
63
+ self._others()
64
+
65
+ self.pos += 1
66
+
67
+ return self
68
+
69
+ def _others(self):
70
+ status = self.status
71
+
72
+ if status == STAT.COMMENT:
73
+ self.parsedSql += self.chars[self.pos]
74
+ elif status == STAT.ALPHABET:
75
+ self.parsedSql += self.chars[self.pos]
76
+ if not self.isProgLetter(self.chars[self.pos]):
77
+ self.status = STAT.NORMAL
78
+ elif status == STAT.NUMBER:
79
+ self.parsedSql += self.chars[self.pos]
80
+ self.status = STAT.NORMAL
81
+ elif status == STAT.QUTATION:
82
+ self.param += self.chars[self.pos]
83
+ else:
84
+ if self.isProgLetter(self.chars[self.pos]):
85
+ self.status = STAT.ALPHABET
86
+ if not self.sqlType:
87
+ self.define_crud()
88
+ else:
89
+ self.status = STAT.NORMAL
90
+ self.parsedSql += self.chars[self.pos]
91
+
92
+ def isProgLetter(self, ch):
93
+ return isLetter(ch) or ch == '_'
94
+
95
+ def define_crud(self):
96
+ self.sqlType = self.chars[self.pos].upper()
97
+
98
+ if self.sqlType not in ['S', 'D', 'U', 'I']:
99
+ self.sqlType = '*'
100
+
101
+ def _colon(self):
102
+ status = self.status
103
+
104
+ if status == STAT.COMMENT:
105
+ self.parsedSql += self.chars[self.pos]
106
+ elif status == STAT.QUTATION:
107
+ self.param += self.chars[self.pos]
108
+ else:
109
+ self.parsedSql += self.chars[self.pos]
110
+ self.status = STAT.COLON
111
+
112
+ def _quotation(self):
113
+ status = self.status
114
+
115
+ if status == STAT.NORMAL:
116
+ if len(self.param) > 0:
117
+ self.param += ','
118
+ self.param += self.chars[self.pos]
119
+ self.status = STAT.QUTATION
120
+ elif status == STAT.COMMENT:
121
+ self.parsedSql += self.chars[self.pos]
122
+ elif status == STAT.ALPHABET:
123
+ self.parsedSql += self.chars[self.pos]
124
+ self.status = STAT.QUTATION
125
+ elif status == STAT.NUMBER:
126
+ self.parsedSql += self.chars[self.pos]
127
+ self.status = STAT.QUTATION
128
+ elif status == STAT.QUTATION:
129
+ self.param += '"'
130
+ self.parsedSql = self.parsedSql + '\'' + self.substitute + '\''
131
+ self.status = STAT.NORMAL
132
+
133
+ def _astar(self):
134
+ status = self.status
135
+
136
+ if status == STAT.COMMENT:
137
+ self.parsedSql += self.chars[self.pos]
138
+ if self.getNext(self.pos) == '/':
139
+ self.parsedSql += '/'
140
+ self.pos += 1
141
+ self.status = STAT.NORMAL
142
+ elif status == STAT.QUTATION:
143
+ self.param += self.chars[self.pos]
144
+ else:
145
+ self.parsedSql += self.chars[self.pos]
146
+ self.status = STAT.NORMAL
147
+
148
+ def _slash(self):
149
+
150
+ status = self.status
151
+
152
+ if status == STAT.COMMENT:
153
+ self.parsedSql += self.chars[self.pos]
154
+ elif status == STAT.QUTATION:
155
+ self.param += self.chars[self.pos]
156
+ else:
157
+ if self.getNext(self.pos) == '*':
158
+ self.pos += 1
159
+ self.parsedSql += '/*'
160
+ self.status = STAT.COMMENT
161
+
162
+ def _minus(self):
163
+
164
+ status = self.status
165
+
166
+ if status == STAT.COMMENT:
167
+ self.parsedSql += self.chars[self.pos]
168
+ elif status == STAT.QUTATION:
169
+ self.param += self.chars[self.pos]
170
+ else:
171
+ if self.getNext(self.pos) == '-':
172
+ self.parsedSql += self.chars[self.pos]
173
+ while self.chars[self.pos] != '\n':
174
+ self.pos += 1
175
+ if self.pos < self.length:
176
+ self.parsedSql += self.chars[self.pos]
177
+ else:
178
+ break
179
+ else:
180
+ self.parsedSql += self.chars[self.pos]
181
+ self.status = STAT.NORMAL
182
+
183
+ def _dot(self):
184
+
185
+ status = self.status
186
+
187
+ if status == STAT.NORMAL:
188
+ self.parsedSql += self.chars[self.pos]
189
+ elif status == STAT.COMMENT:
190
+ self.parsedSql += self.chars[self.pos]
191
+ elif status == STAT.ALPHABET:
192
+ self.parsedSql += self.chars[self.pos]
193
+ self.status = STAT.NORMAL
194
+ elif status == STAT.NUMBER:
195
+ self.param += self.chars[self.pos]
196
+ elif status == STAT.QUTATION:
197
+ self.param += self.chars[self.pos]
198
+
199
+ def _number(self):
200
+
201
+ status = self.status
202
+
203
+ if status == STAT.NORMAL:
204
+ if len(self.param):
205
+ self.param += ','
206
+ self.param += self.chars[self.pos]
207
+ self.parsedSql += self.substitute_num
208
+ self.status = STAT.NUMBER
209
+ elif status in [STAT.COMMENT, STAT.COLON, STAT.ALPHABET]:
210
+ self.parsedSql += self.chars[self.pos]
211
+ elif status in [STAT.NUMBER, STAT.QUTATION]:
212
+ self.param += self.chars[self.pos]
213
+
214
+ def getNext(self, x):
215
+ return self.chars[x + 1] if x < self.length else 0
216
+
217
+ def getParsedSql(self):
218
+ return self.parsedSql
219
+
220
+ def getParameter(self):
221
+ return self.param
222
+
223
+
224
+ ASCII_a = 97
225
+ ASCII_z = 122
226
+ ASCII_A = 65
227
+ ASCII_Z = 90
228
+
229
+
230
+ def isLetter(ch):
231
+ str = ord(ch[0])
232
+ return ((str >= ASCII_a) and (str <= ASCII_z)) or (
233
+ (str >= ASCII_A) and (str <= ASCII_Z))
@@ -0,0 +1,20 @@
1
+ """greenlet/gevent 환경 지원 유틸리티"""
2
+ import sys
3
+ import threading
4
+
5
+
6
+ def get_current_frame(ctx=None):
7
+ """현재 실행 frame 가져오기"""
8
+ return sys._getframe()
9
+
10
+
11
+ def set_greenlet_info(ctx):
12
+ """greenlet 환경이면 context에 greenlet 정보 저장"""
13
+ greenlet_module = sys.modules.get('greenlet')
14
+ if greenlet_module:
15
+ current_greenlet = greenlet_module.getcurrent()
16
+ if current_greenlet is not None:
17
+ ctx.greenlet = current_greenlet
18
+ ctx.greenlet_id = id(current_greenlet)
19
+ return True
20
+ return False
@@ -0,0 +1,103 @@
1
+ import io
2
+ from operator import xor
3
+
4
+ _TABLE = [0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419,
5
+ 0x706af48f, 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e,
6
+ 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91, 0x1db71064,
7
+ 0x6ab020f2, 0xf3b97148, 0x84be41de, 0x1adad47d, 0x6ddde4eb, 0xf4d4b551,
8
+ 0x83d385c7, 0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f,
9
+ 0x63066cd9, 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4,
10
+ 0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, 0x35b5a8fa,
11
+ 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3, 0x45df5c75, 0xdcd60dcf,
12
+ 0xabd13d59, 0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116, 0x21b4f4b5,
13
+ 0x56b3c423, 0xcfba9599, 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2,
14
+ 0xb10be924, 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190,
15
+ 0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f, 0x9fbfe4a5,
16
+ 0xe8b8d433, 0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818, 0x7f6a0dbb,
17
+ 0x086d3d2d, 0x91646c97, 0xe6635c01, 0x6b6b51f4, 0x1c6c6162, 0x856530d8,
18
+ 0xf262004e, 0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6,
19
+ 0x12b7e950, 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3,
20
+ 0xfbd44c65, 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, 0x4adfa541,
21
+ 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a, 0x346ed9fc, 0xad678846,
22
+ 0xda60b8d0, 0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c,
23
+ 0x270241aa, 0xbe0b1010, 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409,
24
+ 0xce61e49f, 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17,
25
+ 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6, 0x03b6e20c,
26
+ 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683, 0xe3630b12,
27
+ 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8, 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27,
28
+ 0x7d079eb1, 0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d,
29
+ 0x806567cb, 0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a,
30
+ 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, 0xd6d6a3e8,
31
+ 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd,
32
+ 0x48b2364b, 0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60, 0xdf60efc3,
33
+ 0xa867df55, 0x316e8eef, 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0,
34
+ 0x5268e236, 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe,
35
+ 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b,
36
+ 0x5bdeae1d, 0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a, 0x9c0906a9,
37
+ 0xeb0e363f, 0x72076785, 0x05005713, 0x95bf4a82, 0xe2b87a14, 0x7bb12bae,
38
+ 0x0cb61b38, 0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4,
39
+ 0xf1d4e242, 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1,
40
+ 0x18b74777, 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, 0x8f659eff,
41
+ 0xf862ae69, 0x616bffd3, 0x166ccf45, 0xa00ae278, 0xd70dd2ee, 0x4e048354,
42
+ 0x3903b3c2, 0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db, 0xaed16a4a,
43
+ 0xd9d65adc, 0x40df0b66, 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f,
44
+ 0x30b5ffe9, 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605,
45
+ 0xcdd70693, 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8, 0x5d681b02,
46
+ 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d]
47
+
48
+
49
+ def hex_to_int(hex):
50
+ hex = format(hex, 'x')
51
+ if len(hex) % 2 != 0:
52
+ hex = "0" + hex
53
+
54
+ num = int(str(hex), 16)
55
+ maxVal = int(pow(2, len(str(hex)) / 2 * 8))
56
+ if num > maxVal / 2 - 1:
57
+ num = num - maxVal
58
+
59
+ return num
60
+
61
+
62
+ for i, hex in enumerate(_TABLE):
63
+ _TABLE[i] = hex_to_int(hex)
64
+
65
+
66
+ class HashUtil(object):
67
+ @classmethod
68
+ def crc32(cls, s):
69
+ buf = io.BytesIO(len(s))
70
+ buf.write(s, 'utf-8')
71
+ crc = 0
72
+ crc = crc ^ (-1)
73
+ for b in buf:
74
+ crc = _TABLE[(crc ^ b) & 0xff] ^ (crc >> 8)
75
+ return crc ^ (-1)
76
+
77
+ @classmethod
78
+ def hashFromString(cls, s):
79
+ buffer = s if isinstance(s, str) else ''
80
+ return cls.hash(bytearray(buffer, 'utf-8'))
81
+
82
+ @classmethod
83
+ def toInt(cls, buf):
84
+ ch1 = buf[0] & 255
85
+ ch2 = buf[1] & 255
86
+ ch3 = buf[2] & 255
87
+ ch4 = buf[3] & 255
88
+ return (ch1 << 24) + (ch2 << 16) + (ch3 << 8) + (ch4 << 0)
89
+
90
+ @classmethod
91
+ def hash(cls, bytes):
92
+ crc = -1
93
+ if bytes:
94
+ l = list(bytes)
95
+
96
+ if l[0] == '-':
97
+ l.remove('-')
98
+ l[0] = int(l[0]) * -1
99
+
100
+ for b in l:
101
+ crc = ((crc % 0x100000000) >> 8) ^ _TABLE[(crc ^ int(b)) & 255]
102
+ crc = crc
103
+ return ~crc
whatap/util/hexa32.py ADDED
@@ -0,0 +1,66 @@
1
+ class Hexa32(object):
2
+ PLUS = 'x'
3
+ MINUS = 'z'
4
+ min = "z8000000000000"
5
+
6
+ @classmethod
7
+ def toString32(cls, num):
8
+ minus = num < 0
9
+ if minus:
10
+ if num == cls.MINUS:
11
+ return cls.min
12
+ return cls.MINUS + encode(-num)
13
+ else:
14
+ if num < 10:
15
+ return encode(num)
16
+ else:
17
+ return cls.PLUS + encode(num)
18
+
19
+ @classmethod
20
+ def toLong32(cls, str):
21
+ if not str or not len(str):
22
+ return 0
23
+
24
+ first_str = str[0]
25
+ if first_str == cls.MINUS:
26
+ return -1 * decode(str[1:])
27
+ elif first_str == cls.PLUS:
28
+ return decode(str[1:])
29
+ else:
30
+ return decode(str)
31
+
32
+
33
+ CHARS = "0123456789abcdefghijklmnopqrstuvwxyz"
34
+
35
+
36
+ def encode(num):
37
+ encoded_chars = []
38
+ while num > 0:
39
+ remainder = num % 32
40
+ num //= 32
41
+ encoded_chars.append(CHARS[remainder])
42
+ return ''.join(encoded_chars[::-1])
43
+
44
+
45
+ def decode(string):
46
+ num = 0
47
+ for power, char in enumerate(string[::-1]):
48
+ try:
49
+ val = CHARS.index(char)
50
+ except ValueError:
51
+ raise ValueError('invalid character: %s' % char)
52
+ num += 32 ** power * val
53
+ return num
54
+
55
+
56
+ if __name__=='__main__':
57
+
58
+ n=-7329592890664812990
59
+ s = 'z6bdvhspq4s0du'
60
+
61
+
62
+ print(Hexa32.toString32(n))
63
+ print(Hexa32.toLong32(s))
64
+
65
+ print(s==Hexa32.toString32(n))
66
+ print(n == Hexa32.toLong32(s))
whatap/util/int_set.py ADDED
@@ -0,0 +1,199 @@
1
+ import threading
2
+ import whatap.io.data_outputx as data_outputx
3
+ from io import StringIO
4
+
5
+ class IntSetry(object):
6
+ def __init__(self, key=0, next= None):
7
+ self.key = key
8
+ self.next = next
9
+
10
+ def clone(self):
11
+ return IntSetry(self.key, None if self.next is None else next.clone())
12
+
13
+ def getKey(self):
14
+ return self.key
15
+
16
+ def equals(self, o):
17
+ if not instance(o,IntSetry):
18
+ return False
19
+
20
+ return self.key == o.getKey()
21
+
22
+ def hashCode(self):
23
+ return self.key
24
+
25
+ def toString(self):
26
+ return str(key)
27
+
28
+ class Enumer(object):
29
+ def __init__(self, table):
30
+ self.table = table
31
+ self.index = len(table)
32
+ self.entry = None
33
+ self.lastReturned = None
34
+
35
+ def hasMoreElements(self):
36
+ while self.entry is None and self.index > 0:
37
+ self.index -= 1
38
+ self.entry = self.table[self.index]
39
+
40
+ return self.entry is not None
41
+
42
+ def nextInt(self):
43
+ while self.entry is None and self.index > 0:
44
+ self.index -= 1
45
+ self.entry = self.table[self.index]
46
+ if self.entry is not None:
47
+ e = self.lastReturned = self.entry
48
+ self.entry = e.next
49
+ return e.key
50
+ raise Exception("no more next")
51
+
52
+
53
+ class EmptyEnumer(object):
54
+ def hasMoreElements(self):
55
+ return 0
56
+
57
+ def nextInt(self):
58
+ return False
59
+
60
+ class IntSet(object):
61
+ emptyEnumer = EmptyEnumer()
62
+
63
+ def __init__(self, initCapacity = int(101), loadFactor = float(0.75)):
64
+ self.count = 0
65
+ if initCapacity < 0:
66
+ raise Exception("Capacity Error: " + initCapacity)
67
+ if loadFactor <= 0:
68
+ raise Exception("Load Count Error: " + loadFactor)
69
+ if initCapacity == 0:
70
+ initCapacity = 1
71
+ self.loadFactor = loadFactor;
72
+ self.table = [None]*initCapacity
73
+ self.threshold = int(initCapacity * loadFactor)
74
+
75
+ self.lock = threading.Lock()
76
+
77
+ def size(self):
78
+ return self.count
79
+
80
+ def values(self):
81
+ try:
82
+ self.lock.acquire()
83
+ return Enumer(self.table)
84
+ finally:
85
+ self.lock.release()
86
+
87
+ def contains(self, key):
88
+ buk = self.table
89
+ index = (key & data_outputx.INT_MAX_VALUE) % len(buk)
90
+ e = buk[index]
91
+ while e is not None:
92
+ if e.key == key:
93
+ return True
94
+ e = e.next
95
+
96
+ return False
97
+
98
+ def get(self, key):
99
+ buk = self.table
100
+ index = (key & data_outputx.INT_MAX_VALUE) % len(buk)
101
+
102
+ e = buk[index]
103
+ while e is not None:
104
+ if e.key == key:
105
+ return e.key
106
+
107
+ return 0
108
+
109
+ def rehash(self):
110
+ oldCapacity = len(self.table)
111
+ oldMap = self.table
112
+ newCapacity = oldCapacity * 2 + 1
113
+ newMap = [None]*newCapacity
114
+ self.threshold = int(newCapacity * loadFactor)
115
+ self.table = newMap
116
+
117
+ for i in range(oldCapacity, 1, -1):
118
+ old = oldMap[i]
119
+ while old is not None:
120
+ e = old
121
+ old = old.next
122
+ index = (e.key & data_outputx.INT_MAX_VALUE) % newCapacity
123
+ e.next = newMap[index]
124
+ newMap[index] = e
125
+
126
+ def putAll(self, values):
127
+ if not values :
128
+ return
129
+ for v in values:
130
+ self.put(v)
131
+
132
+ def put(self, value):
133
+ buk = self.table
134
+ index = (value & data_outputx.INT_MAX_VALUE) % len(buk)
135
+ e = buk[index]
136
+ while e is not None:
137
+ if e.key == value:
138
+ return False
139
+ e = e.next
140
+ if self.count >= self.threshold:
141
+ self.rehash()
142
+ buk = self.table
143
+ index = (value & Integer.MAX_VALUE) % len(buk)
144
+
145
+ e = IntSetry(value, buk[index])
146
+ buk[index] = e
147
+ self.count +=1
148
+ return True
149
+
150
+ def remove(self, key):
151
+ buk = self.table
152
+ index = (key & data_outputx.INT_MAX_VALUE) % len(buk)
153
+ e = buk[index]
154
+ prev = None
155
+ while e is not None:
156
+ if e.key == key:
157
+ if prev is not None:
158
+ prev.next = e.next
159
+ else:
160
+ buk[index] = e.next
161
+ self.count-=1
162
+ return key
163
+ prev = e, e = e.next
164
+
165
+ return 0
166
+
167
+ def clear(self):
168
+ buk = table
169
+ for index in range(len(buk), 0, -1):
170
+ buk[index] = None
171
+ self.count = 0
172
+
173
+ def toString(self):
174
+ max = self.size() - 1
175
+ buf = StringIO()
176
+ it = this.values()
177
+ buf.write("{")
178
+ for i in range(max):
179
+ key = it.nextInt()
180
+ buf.write(str(key))
181
+ if i < max:
182
+ buf.write(", ")
183
+ buf.write("}")
184
+
185
+ return buf.getvalue()
186
+
187
+ def toArray(self):
188
+ _keys = int[self.size()]
189
+ en = self.values()
190
+ for i in range(len(_keys)):
191
+ _keys[i] = en.nextInt()
192
+ return _keys
193
+
194
+ def isExistElseAdd(self, value):
195
+ return self.put(value) == False
196
+
197
+ def putStrHash(self, s):
198
+ if s is not None:
199
+ self.put(hash(s))
whatap/util/ip_util.py ADDED
@@ -0,0 +1,63 @@
1
+ from whatap.io.data_inputx import DataInputX
2
+ from whatap.io.data_outputx import DataOutputX
3
+
4
+
5
+ class IPUtil(object):
6
+ empty = bytearray([0, 0, 0, 0])
7
+
8
+ @classmethod
9
+ def toString(cls, ip):
10
+ if isinstance(ip, int):
11
+ return cls.toString(DataOutputX.toBytes(ip))
12
+ elif isinstance(ip, bytes) or isinstance(ip, bytearray):
13
+ try:
14
+ to_str = '{0}.{1}.{2}.{3}'.format(ip[0] & 0xff, ip[1] & 0xff,
15
+ ip[2] & 0xff, ip[3] & 0xff)
16
+ return to_str
17
+ except Exception:
18
+ return '0.0.0.0'
19
+
20
+ @classmethod
21
+ def toBytes(cls, ip):
22
+ if isinstance(ip, int):
23
+ return DataOutputX.toBytes(ip)
24
+ elif isinstance(ip, str):
25
+ # if not ip:
26
+ # return cls.empty
27
+
28
+ try:
29
+ ss = ip.split('.')
30
+ ss_ln = len(ss)
31
+ if ss_ln != 4:
32
+ return cls.empty
33
+
34
+ result = bytearray(ss_ln)
35
+ for i in range(ss_ln):
36
+ s = int(ss[i])
37
+ if s < 0 or s > 0xff:
38
+ return cls.empty
39
+
40
+ result[i] = s & 0xff
41
+ return result
42
+ except Exception as e:
43
+ import traceback
44
+ traceback.print_stack()
45
+ return cls.empty
46
+
47
+ @classmethod
48
+ def toInt(cls, ip):
49
+ if isinstance(ip, bytes):
50
+ if cls.isOK(ip):
51
+ return DataInputX.toInt(ip, 0)
52
+ else:
53
+ return 0
54
+ elif isinstance(ip, str):
55
+ return DataInputX.toInt(cls.toBytes(ip), 0)
56
+
57
+ @classmethod
58
+ def isOK(cls, ip):
59
+ return ip is not None and len(ip) == 4
60
+
61
+ @classmethod
62
+ def isNotLocal(cls, ip):
63
+ return cls.isOK(ip) and (ip[0] & 0xff) != 127
whatap/util/keygen.py ADDED
@@ -0,0 +1,11 @@
1
+ from whatap.util.date_util import DateUtil
2
+ import random
3
+ try:
4
+ random.seed(DateUtil.nowSystem())
5
+ except:
6
+ pass
7
+
8
+ class KeyGen(object):
9
+ @classmethod
10
+ def next(cls):
11
+ return int(random.random()*0x7fffffff)