cavisson-pythonagent 0.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 (180) hide show
  1. cavisson_pythonagent-0.0.1.dist-info/METADATA +32 -0
  2. cavisson_pythonagent-0.0.1.dist-info/RECORD +180 -0
  3. cavisson_pythonagent-0.0.1.dist-info/WHEEL +5 -0
  4. cavisson_pythonagent-0.0.1.dist-info/licenses/LICENSE +19 -0
  5. cavisson_pythonagent-0.0.1.dist-info/top_level.txt +1 -0
  6. pythonagent/__init__.py +22 -0
  7. pythonagent/agent/__init__.py +219 -0
  8. pythonagent/agent/internal/__init__.py +1 -0
  9. pythonagent/agent/internal/agent.py +1651 -0
  10. pythonagent/agent/internal/framesinfo.py +152 -0
  11. pythonagent/agent/internal/heap_dump.py +39 -0
  12. pythonagent/agent/internal/intercept_module.py +70 -0
  13. pythonagent/agent/internal/logs.py +122 -0
  14. pythonagent/agent/internal/metadata/__init__.py +0 -0
  15. pythonagent/agent/internal/metadata/agent_meta_data.py +276 -0
  16. pythonagent/agent/internal/proc_compat.py +75 -0
  17. pythonagent/agent/internal/profile.py +47 -0
  18. pythonagent/agent/internal/provider.py +83 -0
  19. pythonagent/agent/internal/thread_dump.py +85 -0
  20. pythonagent/agent/internal/udp.py +245 -0
  21. pythonagent/agent/internal/udp_message.py +800 -0
  22. pythonagent/agent/probes/Instrumentation/__init__.py +340 -0
  23. pythonagent/agent/probes/Instrumentation/find.py +243 -0
  24. pythonagent/agent/probes/Instrumentation/module_version_resolver.py +155 -0
  25. pythonagent/agent/probes/Instrumentation/new_parser.py +64 -0
  26. pythonagent/agent/probes/Instrumentation/parser.py +129 -0
  27. pythonagent/agent/probes/__init__.py +219 -0
  28. pythonagent/agent/probes/base.py +303 -0
  29. pythonagent/agent/probes/cache/__init__.py +51 -0
  30. pythonagent/agent/probes/cache/redis.py +119 -0
  31. pythonagent/agent/probes/cache/redis_asyncio.py +83 -0
  32. pythonagent/agent/probes/coroutines/__init__.py +1 -0
  33. pythonagent/agent/probes/coroutines/asyncio.py +63 -0
  34. pythonagent/agent/probes/elasticdb/__init__.py +7 -0
  35. pythonagent/agent/probes/elasticdb/aelastic.py +54 -0
  36. pythonagent/agent/probes/frameworks/__init__.py +27 -0
  37. pythonagent/agent/probes/frameworks/agentprofiler.py +105 -0
  38. pythonagent/agent/probes/frameworks/aiohttp_web.py +155 -0
  39. pythonagent/agent/probes/frameworks/aisess.py +151 -0
  40. pythonagent/agent/probes/frameworks/asgi.py +340 -0
  41. pythonagent/agent/probes/frameworks/bottle.py +27 -0
  42. pythonagent/agent/probes/frameworks/cherry.py +25 -0
  43. pythonagent/agent/probes/frameworks/django.py +128 -0
  44. pythonagent/agent/probes/frameworks/falcon.py +21 -0
  45. pythonagent/agent/probes/frameworks/fastapi.py +35 -0
  46. pythonagent/agent/probes/frameworks/flask.py +30 -0
  47. pythonagent/agent/probes/frameworks/pyramid.py +56 -0
  48. pythonagent/agent/probes/frameworks/test.py +108 -0
  49. pythonagent/agent/probes/frameworks/tornado_async_web.py +117 -0
  50. pythonagent/agent/probes/frameworks/tornado_web.py +133 -0
  51. pythonagent/agent/probes/frameworks/wsgi.py +353 -0
  52. pythonagent/agent/probes/grpc/__init__.py +76 -0
  53. pythonagent/agent/probes/grpc/client_interceptor.py +132 -0
  54. pythonagent/agent/probes/grpc/server_interceptor.py +129 -0
  55. pythonagent/agent/probes/havoc/__init__.py +0 -0
  56. pythonagent/agent/probes/havoc/custom_memory_stress.py +186 -0
  57. pythonagent/agent/probes/havoc/custom_thread_stress.py +187 -0
  58. pythonagent/agent/probes/havoc/havoc_constants.py +218 -0
  59. pythonagent/agent/probes/havoc/havoc_manager.py +981 -0
  60. pythonagent/agent/probes/http/__init__.py +49 -0
  61. pythonagent/agent/probes/http/aiohttp_client.py +59 -0
  62. pythonagent/agent/probes/http/boto.py +12 -0
  63. pythonagent/agent/probes/http/httplib.py +110 -0
  64. pythonagent/agent/probes/http/httpx_client.py +116 -0
  65. pythonagent/agent/probes/http/requests.py +15 -0
  66. pythonagent/agent/probes/http/tornado_httpclient.py +85 -0
  67. pythonagent/agent/probes/http/urllib3.py +16 -0
  68. pythonagent/agent/probes/langchain/__init__.py +21 -0
  69. pythonagent/agent/probes/langchain/base_tool.py +95 -0
  70. pythonagent/agent/probes/langchain/langchain_community.py +136 -0
  71. pythonagent/agent/probes/langchain/langchain_core.py +32 -0
  72. pythonagent/agent/probes/langchain/langchain_openai.py +110 -0
  73. pythonagent/agent/probes/logging/__init__.py +106 -0
  74. pythonagent/agent/probes/message_brokers/__init__.py +4 -0
  75. pythonagent/agent/probes/message_brokers/pika.py +126 -0
  76. pythonagent/agent/probes/mongodb/__init__.py +6 -0
  77. pythonagent/agent/probes/mongodb/pymongo.py +286 -0
  78. pythonagent/agent/probes/openai/__init__.py +3 -0
  79. pythonagent/agent/probes/openai/openai.py +797 -0
  80. pythonagent/agent/probes/span.py +101 -0
  81. pythonagent/agent/probes/sql/__init__.py +13 -0
  82. pythonagent/agent/probes/sql/botocores3.py +51 -0
  83. pythonagent/agent/probes/sql/dbapi.py +285 -0
  84. pythonagent/agent/probes/sql/dynamodb.py +90 -0
  85. pythonagent/agent/probes/sql/mysql_connector.py +24 -0
  86. pythonagent/agent/probes/sql/mysql_connector_cext.py +24 -0
  87. pythonagent/agent/probes/sql/mysqldb.py +43 -0
  88. pythonagent/agent/probes/sql/psycopg2.py +174 -0
  89. pythonagent/agent/probes/sql/pymysql.py +25 -0
  90. pythonagent/bootstrap/__init__.py +0 -0
  91. pythonagent/bootstrap/cav_gunicorn.py +26 -0
  92. pythonagent/bootstrap/cavagent_lambda_wrapper.py +291 -0
  93. pythonagent/bootstrap/run.py +47 -0
  94. pythonagent/bootstrap/sitecustomize.py +287 -0
  95. pythonagent/cavisson/netdiagnostics/CavAgent/instrumentationprofile.json +26 -0
  96. pythonagent/cavisson/netdiagnostics/CavAgent/interceptor_points.txt +29 -0
  97. pythonagent/cavisson/netdiagnostics/python/CavAgent/instrumentationprofile.json +42 -0
  98. pythonagent/cavisson/netdiagnostics/python/CavAgent/interceptor_points.txt +29 -0
  99. pythonagent/cavisson/netdiagnostics/python/config/ndsettings.conf +6 -0
  100. pythonagent/config.py +279 -0
  101. pythonagent/find.py +72 -0
  102. pythonagent/find_mod_cls_name.py +54 -0
  103. pythonagent/lang.py +131 -0
  104. pythonagent/lib.py +91 -0
  105. pythonagent/main/__init__.py +0 -0
  106. pythonagent/main/pytrace/__init__.py +79 -0
  107. pythonagent/main/pytrace/commands/__init__.py +0 -0
  108. pythonagent/main/pytrace/commands/auto_discovery.py +25 -0
  109. pythonagent/main/pytrace/commands/run.py +401 -0
  110. pythonagent/main/pytrace/pytrace.py +133 -0
  111. pythonagent/main/wsgi.py +6 -0
  112. pythonagent/main.py +27 -0
  113. pythonagent/run.py +46 -0
  114. pythonagent/sqins.py +8 -0
  115. pythonagent/test.py +73 -0
  116. pythonagent/utils.py +168 -0
  117. pythonagent/vendor/__init__.py +0 -0
  118. pythonagent/vendor/pympler/__init__.py +1 -0
  119. pythonagent/vendor/pympler/asizeof.py +2810 -0
  120. pythonagent/vendor/pympler/charts.py +62 -0
  121. pythonagent/vendor/pympler/classtracker.py +590 -0
  122. pythonagent/vendor/pympler/classtracker_stats.py +780 -0
  123. pythonagent/vendor/pympler/garbagegraph.py +80 -0
  124. pythonagent/vendor/pympler/mprofile.py +97 -0
  125. pythonagent/vendor/pympler/muppy.py +275 -0
  126. pythonagent/vendor/pympler/panels.py +115 -0
  127. pythonagent/vendor/pympler/process.py +238 -0
  128. pythonagent/vendor/pympler/py.typed +0 -0
  129. pythonagent/vendor/pympler/refbrowser.py +451 -0
  130. pythonagent/vendor/pympler/refgraph.py +350 -0
  131. pythonagent/vendor/pympler/summary.py +321 -0
  132. pythonagent/vendor/pympler/tracker.py +267 -0
  133. pythonagent/vendor/pympler/util/__init__.py +0 -0
  134. pythonagent/vendor/pympler/util/bottle.py +3809 -0
  135. pythonagent/vendor/pympler/util/compat.py +23 -0
  136. pythonagent/vendor/pympler/util/stringutils.py +77 -0
  137. pythonagent/vendor/pympler/web.py +346 -0
  138. pythonagent/vendor/werkzeug/__init__.py +20 -0
  139. pythonagent/vendor/werkzeug/_compat.py +228 -0
  140. pythonagent/vendor/werkzeug/_internal.py +473 -0
  141. pythonagent/vendor/werkzeug/_reloader.py +341 -0
  142. pythonagent/vendor/werkzeug/datastructures.py +3120 -0
  143. pythonagent/vendor/werkzeug/debug/__init__.py +498 -0
  144. pythonagent/vendor/werkzeug/debug/console.py +218 -0
  145. pythonagent/vendor/werkzeug/debug/repr.py +297 -0
  146. pythonagent/vendor/werkzeug/debug/tbtools.py +628 -0
  147. pythonagent/vendor/werkzeug/exceptions.py +829 -0
  148. pythonagent/vendor/werkzeug/filesystem.py +64 -0
  149. pythonagent/vendor/werkzeug/formparser.py +584 -0
  150. pythonagent/vendor/werkzeug/http.py +1307 -0
  151. pythonagent/vendor/werkzeug/local.py +420 -0
  152. pythonagent/vendor/werkzeug/middleware/__init__.py +25 -0
  153. pythonagent/vendor/werkzeug/middleware/dispatcher.py +66 -0
  154. pythonagent/vendor/werkzeug/middleware/http_proxy.py +219 -0
  155. pythonagent/vendor/werkzeug/middleware/lint.py +408 -0
  156. pythonagent/vendor/werkzeug/middleware/profiler.py +132 -0
  157. pythonagent/vendor/werkzeug/middleware/proxy_fix.py +169 -0
  158. pythonagent/vendor/werkzeug/middleware/shared_data.py +293 -0
  159. pythonagent/vendor/werkzeug/posixemulation.py +117 -0
  160. pythonagent/vendor/werkzeug/routing.py +2210 -0
  161. pythonagent/vendor/werkzeug/security.py +249 -0
  162. pythonagent/vendor/werkzeug/serving.py +1117 -0
  163. pythonagent/vendor/werkzeug/test.py +1123 -0
  164. pythonagent/vendor/werkzeug/testapp.py +241 -0
  165. pythonagent/vendor/werkzeug/urls.py +1138 -0
  166. pythonagent/vendor/werkzeug/useragents.py +202 -0
  167. pythonagent/vendor/werkzeug/utils.py +778 -0
  168. pythonagent/vendor/werkzeug/wrappers/__init__.py +36 -0
  169. pythonagent/vendor/werkzeug/wrappers/accept.py +50 -0
  170. pythonagent/vendor/werkzeug/wrappers/auth.py +33 -0
  171. pythonagent/vendor/werkzeug/wrappers/base_request.py +673 -0
  172. pythonagent/vendor/werkzeug/wrappers/base_response.py +700 -0
  173. pythonagent/vendor/werkzeug/wrappers/common_descriptors.py +341 -0
  174. pythonagent/vendor/werkzeug/wrappers/cors.py +100 -0
  175. pythonagent/vendor/werkzeug/wrappers/etag.py +304 -0
  176. pythonagent/vendor/werkzeug/wrappers/json.py +145 -0
  177. pythonagent/vendor/werkzeug/wrappers/request.py +49 -0
  178. pythonagent/vendor/werkzeug/wrappers/response.py +84 -0
  179. pythonagent/vendor/werkzeug/wrappers/user_agent.py +14 -0
  180. pythonagent/vendor/werkzeug/wsgi.py +1000 -0
@@ -0,0 +1,473 @@
1
+ # -*- coding: utf-8 -*-
2
+ """
3
+ werkzeug._internal
4
+ ~~~~~~~~~~~~~~~~~~
5
+
6
+ This module provides internally used helpers and constants.
7
+
8
+ :copyright: 2007 Pallets
9
+ :license: BSD-3-Clause
10
+ """
11
+ import inspect
12
+ import logging
13
+ import re
14
+ import string
15
+ from datetime import date
16
+ from datetime import datetime
17
+ from itertools import chain
18
+ from weakref import WeakKeyDictionary
19
+
20
+ from ._compat import int_to_byte
21
+ from ._compat import integer_types
22
+ from ._compat import iter_bytes
23
+ from ._compat import range_type
24
+ from ._compat import text_type
25
+
26
+
27
+ _logger = None
28
+ _signature_cache = WeakKeyDictionary()
29
+ _epoch_ord = date(1970, 1, 1).toordinal()
30
+ _legal_cookie_chars = (
31
+ string.ascii_letters + string.digits + u"/=!#$%&'*+-.^_`|~:"
32
+ ).encode("ascii")
33
+
34
+ _cookie_quoting_map = {b",": b"\\054", b";": b"\\073", b'"': b'\\"', b"\\": b"\\\\"}
35
+ for _i in chain(range_type(32), range_type(127, 256)):
36
+ _cookie_quoting_map[int_to_byte(_i)] = ("\\%03o" % _i).encode("latin1")
37
+
38
+ _octal_re = re.compile(br"\\[0-3][0-7][0-7]")
39
+ _quote_re = re.compile(br"[\\].")
40
+ _legal_cookie_chars_re = br"[\w\d!#%&\'~_`><@,:/\$\*\+\-\.\^\|\)\(\?\}\{\=]"
41
+ _cookie_re = re.compile(
42
+ br"""
43
+ (?P<key>[^=;]+)
44
+ (?:\s*=\s*
45
+ (?P<val>
46
+ "(?:[^\\"]|\\.)*" |
47
+ (?:.*?)
48
+ )
49
+ )?
50
+ \s*;
51
+ """,
52
+ flags=re.VERBOSE,
53
+ )
54
+
55
+
56
+ class _Missing(object):
57
+ def __repr__(self):
58
+ return "no value"
59
+
60
+ def __reduce__(self):
61
+ return "_missing"
62
+
63
+
64
+ _missing = _Missing()
65
+
66
+
67
+ def _get_environ(obj):
68
+ env = getattr(obj, "environ", obj)
69
+ assert isinstance(env, dict), (
70
+ "%r is not a WSGI environment (has to be a dict)" % type(obj).__name__
71
+ )
72
+ return env
73
+
74
+
75
+ def _has_level_handler(logger):
76
+ """Check if there is a handler in the logging chain that will handle
77
+ the given logger's effective level.
78
+ """
79
+ level = logger.getEffectiveLevel()
80
+ current = logger
81
+
82
+ while current:
83
+ if any(handler.level <= level for handler in current.handlers):
84
+ return True
85
+
86
+ if not current.propagate:
87
+ break
88
+
89
+ current = current.parent
90
+
91
+ return False
92
+
93
+
94
+ def _log(type, message, *args, **kwargs):
95
+ """Log a message to the 'werkzeug' logger.
96
+
97
+ The logger is created the first time it is needed. If there is no
98
+ level set, it is set to :data:`logging.INFO`. If there is no handler
99
+ for the logger's effective level, a :class:`logging.StreamHandler`
100
+ is added.
101
+ """
102
+ global _logger
103
+
104
+ if _logger is None:
105
+ _logger = logging.getLogger("werkzeug")
106
+
107
+ if _logger.level == logging.NOTSET:
108
+ _logger.setLevel(logging.INFO)
109
+
110
+ if not _has_level_handler(_logger):
111
+ _logger.addHandler(logging.StreamHandler())
112
+
113
+ getattr(_logger, type)(message.rstrip(), *args, **kwargs)
114
+
115
+
116
+ def _parse_signature(func):
117
+ """Return a signature object for the function."""
118
+ if hasattr(func, "im_func"):
119
+ func = func.im_func
120
+
121
+ # if we have a cached validator for this function, return it
122
+ parse = _signature_cache.get(func)
123
+ if parse is not None:
124
+ return parse
125
+
126
+ # inspect the function signature and collect all the information
127
+ if hasattr(inspect, "getfullargspec"):
128
+ tup = inspect.getfullargspec(func)
129
+ else:
130
+ tup = inspect.getargspec(func)
131
+ positional, vararg_var, kwarg_var, defaults = tup[:4]
132
+ defaults = defaults or ()
133
+ arg_count = len(positional)
134
+ arguments = []
135
+ for idx, name in enumerate(positional):
136
+ if isinstance(name, list):
137
+ raise TypeError(
138
+ "cannot parse functions that unpack tuples in the function signature"
139
+ )
140
+ try:
141
+ default = defaults[idx - arg_count]
142
+ except IndexError:
143
+ param = (name, False, None)
144
+ else:
145
+ param = (name, True, default)
146
+ arguments.append(param)
147
+ arguments = tuple(arguments)
148
+
149
+ def parse(args, kwargs):
150
+ new_args = []
151
+ missing = []
152
+ extra = {}
153
+
154
+ # consume as many arguments as positional as possible
155
+ for idx, (name, has_default, default) in enumerate(arguments):
156
+ try:
157
+ new_args.append(args[idx])
158
+ except IndexError:
159
+ try:
160
+ new_args.append(kwargs.pop(name))
161
+ except KeyError:
162
+ if has_default:
163
+ new_args.append(default)
164
+ else:
165
+ missing.append(name)
166
+ else:
167
+ if name in kwargs:
168
+ extra[name] = kwargs.pop(name)
169
+
170
+ # handle extra arguments
171
+ extra_positional = args[arg_count:]
172
+ if vararg_var is not None:
173
+ new_args.extend(extra_positional)
174
+ extra_positional = ()
175
+ if kwargs and kwarg_var is None:
176
+ extra.update(kwargs)
177
+ kwargs = {}
178
+
179
+ return (
180
+ new_args,
181
+ kwargs,
182
+ missing,
183
+ extra,
184
+ extra_positional,
185
+ arguments,
186
+ vararg_var,
187
+ kwarg_var,
188
+ )
189
+
190
+ _signature_cache[func] = parse
191
+ return parse
192
+
193
+
194
+ def _date_to_unix(arg):
195
+ """Converts a timetuple, integer or datetime object into the seconds from
196
+ epoch in utc.
197
+ """
198
+ if isinstance(arg, datetime):
199
+ arg = arg.utctimetuple()
200
+ elif isinstance(arg, integer_types + (float,)):
201
+ return int(arg)
202
+ year, month, day, hour, minute, second = arg[:6]
203
+ days = date(year, month, 1).toordinal() - _epoch_ord + day - 1
204
+ hours = days * 24 + hour
205
+ minutes = hours * 60 + minute
206
+ seconds = minutes * 60 + second
207
+ return seconds
208
+
209
+
210
+ class _DictAccessorProperty(object):
211
+ """Baseclass for `environ_property` and `header_property`."""
212
+
213
+ read_only = False
214
+
215
+ def __init__(
216
+ self,
217
+ name,
218
+ default=None,
219
+ load_func=None,
220
+ dump_func=None,
221
+ read_only=None,
222
+ doc=None,
223
+ ):
224
+ self.name = name
225
+ self.default = default
226
+ self.load_func = load_func
227
+ self.dump_func = dump_func
228
+ if read_only is not None:
229
+ self.read_only = read_only
230
+ self.__doc__ = doc
231
+
232
+ def __get__(self, obj, type=None):
233
+ if obj is None:
234
+ return self
235
+ storage = self.lookup(obj)
236
+ if self.name not in storage:
237
+ return self.default
238
+ rv = storage[self.name]
239
+ if self.load_func is not None:
240
+ try:
241
+ rv = self.load_func(rv)
242
+ except (ValueError, TypeError):
243
+ rv = self.default
244
+ return rv
245
+
246
+ def __set__(self, obj, value):
247
+ if self.read_only:
248
+ raise AttributeError("read only property")
249
+ if self.dump_func is not None:
250
+ value = self.dump_func(value)
251
+ self.lookup(obj)[self.name] = value
252
+
253
+ def __delete__(self, obj):
254
+ if self.read_only:
255
+ raise AttributeError("read only property")
256
+ self.lookup(obj).pop(self.name, None)
257
+
258
+ def __repr__(self):
259
+ return "<%s %s>" % (self.__class__.__name__, self.name)
260
+
261
+
262
+ def _cookie_quote(b):
263
+ buf = bytearray()
264
+ all_legal = True
265
+ _lookup = _cookie_quoting_map.get
266
+ _push = buf.extend
267
+
268
+ for char in iter_bytes(b):
269
+ if char not in _legal_cookie_chars:
270
+ all_legal = False
271
+ char = _lookup(char, char)
272
+ _push(char)
273
+
274
+ if all_legal:
275
+ return bytes(buf)
276
+ return bytes(b'"' + buf + b'"')
277
+
278
+
279
+ def _cookie_unquote(b):
280
+ if len(b) < 2:
281
+ return b
282
+ if b[:1] != b'"' or b[-1:] != b'"':
283
+ return b
284
+
285
+ b = b[1:-1]
286
+
287
+ i = 0
288
+ n = len(b)
289
+ rv = bytearray()
290
+ _push = rv.extend
291
+
292
+ while 0 <= i < n:
293
+ o_match = _octal_re.search(b, i)
294
+ q_match = _quote_re.search(b, i)
295
+ if not o_match and not q_match:
296
+ rv.extend(b[i:])
297
+ break
298
+ j = k = -1
299
+ if o_match:
300
+ j = o_match.start(0)
301
+ if q_match:
302
+ k = q_match.start(0)
303
+ if q_match and (not o_match or k < j):
304
+ _push(b[i:k])
305
+ _push(b[k + 1 : k + 2])
306
+ i = k + 2
307
+ else:
308
+ _push(b[i:j])
309
+ rv.append(int(b[j + 1 : j + 4], 8))
310
+ i = j + 4
311
+
312
+ return bytes(rv)
313
+
314
+
315
+ def _cookie_parse_impl(b):
316
+ """Lowlevel cookie parsing facility that operates on bytes."""
317
+ i = 0
318
+ n = len(b)
319
+
320
+ while i < n:
321
+ match = _cookie_re.search(b + b";", i)
322
+ if not match:
323
+ break
324
+
325
+ key = match.group("key").strip()
326
+ value = match.group("val") or b""
327
+ i = match.end(0)
328
+
329
+ yield _cookie_unquote(key), _cookie_unquote(value)
330
+
331
+
332
+ def _encode_idna(domain):
333
+ # If we're given bytes, make sure they fit into ASCII
334
+ if not isinstance(domain, text_type):
335
+ domain.decode("ascii")
336
+ return domain
337
+
338
+ # Otherwise check if it's already ascii, then return
339
+ try:
340
+ return domain.encode("ascii")
341
+ except UnicodeError:
342
+ pass
343
+
344
+ # Otherwise encode each part separately
345
+ parts = domain.split(".")
346
+ for idx, part in enumerate(parts):
347
+ parts[idx] = part.encode("idna")
348
+ return b".".join(parts)
349
+
350
+
351
+ def _decode_idna(domain):
352
+ # If the input is a string try to encode it to ascii to
353
+ # do the idna decoding. if that fails because of an
354
+ # unicode error, then we already have a decoded idna domain
355
+ if isinstance(domain, text_type):
356
+ try:
357
+ domain = domain.encode("ascii")
358
+ except UnicodeError:
359
+ return domain
360
+
361
+ # Decode each part separately. If a part fails, try to
362
+ # decode it with ascii and silently ignore errors. This makes
363
+ # most sense because the idna codec does not have error handling
364
+ parts = domain.split(b".")
365
+ for idx, part in enumerate(parts):
366
+ try:
367
+ parts[idx] = part.decode("idna")
368
+ except UnicodeError:
369
+ parts[idx] = part.decode("ascii", "ignore")
370
+
371
+ return ".".join(parts)
372
+
373
+
374
+ def _make_cookie_domain(domain):
375
+ if domain is None:
376
+ return None
377
+ domain = _encode_idna(domain)
378
+ if b":" in domain:
379
+ domain = domain.split(b":", 1)[0]
380
+ if b"." in domain:
381
+ return domain
382
+ raise ValueError(
383
+ "Setting 'domain' for a cookie on a server running locally (ex: "
384
+ "localhost) is not supported by complying browsers. You should "
385
+ "have something like: '127.0.0.1 localhost dev.localhost' on "
386
+ "your hosts file and then point your server to run on "
387
+ "'dev.localhost' and also set 'domain' for 'dev.localhost'"
388
+ )
389
+
390
+
391
+ def _easteregg(app=None):
392
+ """Like the name says. But who knows how it works?"""
393
+
394
+ def bzzzzzzz(gyver):
395
+ import base64
396
+ import zlib
397
+
398
+ return zlib.decompress(base64.b64decode(gyver)).decode("ascii")
399
+
400
+ gyver = u"\n".join(
401
+ [
402
+ x + (77 - len(x)) * u" "
403
+ for x in bzzzzzzz(
404
+ b"""
405
+ eJyFlzuOJDkMRP06xRjymKgDJCDQStBYT8BCgK4gTwfQ2fcFs2a2FzvZk+hvlcRvRJD148efHt9m
406
+ 9Xz94dRY5hGt1nrYcXx7us9qlcP9HHNh28rz8dZj+q4rynVFFPdlY4zH873NKCexrDM6zxxRymzz
407
+ 4QIxzK4bth1PV7+uHn6WXZ5C4ka/+prFzx3zWLMHAVZb8RRUxtFXI5DTQ2n3Hi2sNI+HK43AOWSY
408
+ jmEzE4naFp58PdzhPMdslLVWHTGUVpSxImw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YwDZ6jApe3wUjFQobghvW9p
435
+ 7f2zLkGNv8b191cD/3vs9Q833z8t"""
436
+ ).splitlines()
437
+ ]
438
+ )
439
+
440
+ def easteregged(environ, start_response):
441
+ def injecting_start_response(status, headers, exc_info=None):
442
+ headers.append(("X-Powered-By", "Werkzeug"))
443
+ return start_response(status, headers, exc_info)
444
+
445
+ if app is not None and environ.get("QUERY_STRING") != "macgybarchakku":
446
+ return app(environ, injecting_start_response)
447
+ injecting_start_response("200 OK", [("Content-Type", "text/html")])
448
+ return [
449
+ (
450
+ u"""
451
+ <!DOCTYPE html>
452
+ <html>
453
+ <head>
454
+ <title>About Werkzeug</title>
455
+ <style type="text/css">
456
+ body { font: 15px Georgia, serif; text-align: center; }
457
+ a { color: #333; text-decoration: none; }
458
+ h1 { font-size: 30px; margin: 20px 0 10px 0; }
459
+ p { margin: 0 0 30px 0; }
460
+ pre { font: 11px 'Consolas', 'Monaco', monospace; line-height: 0.95; }
461
+ </style>
462
+ </head>
463
+ <body>
464
+ <h1><a href="http://werkzeug.pocoo.org/">Werkzeug</a></h1>
465
+ <p>the Swiss Army knife of Python web development.</p>
466
+ <pre>%s\n\n\n</pre>
467
+ </body>
468
+ </html>"""
469
+ % gyver
470
+ ).encode("latin1")
471
+ ]
472
+
473
+ return easteregged