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.
- cavisson_pythonagent-0.0.1.dist-info/METADATA +32 -0
- cavisson_pythonagent-0.0.1.dist-info/RECORD +180 -0
- cavisson_pythonagent-0.0.1.dist-info/WHEEL +5 -0
- cavisson_pythonagent-0.0.1.dist-info/licenses/LICENSE +19 -0
- cavisson_pythonagent-0.0.1.dist-info/top_level.txt +1 -0
- pythonagent/__init__.py +22 -0
- pythonagent/agent/__init__.py +219 -0
- pythonagent/agent/internal/__init__.py +1 -0
- pythonagent/agent/internal/agent.py +1651 -0
- pythonagent/agent/internal/framesinfo.py +152 -0
- pythonagent/agent/internal/heap_dump.py +39 -0
- pythonagent/agent/internal/intercept_module.py +70 -0
- pythonagent/agent/internal/logs.py +122 -0
- pythonagent/agent/internal/metadata/__init__.py +0 -0
- pythonagent/agent/internal/metadata/agent_meta_data.py +276 -0
- pythonagent/agent/internal/proc_compat.py +75 -0
- pythonagent/agent/internal/profile.py +47 -0
- pythonagent/agent/internal/provider.py +83 -0
- pythonagent/agent/internal/thread_dump.py +85 -0
- pythonagent/agent/internal/udp.py +245 -0
- pythonagent/agent/internal/udp_message.py +800 -0
- pythonagent/agent/probes/Instrumentation/__init__.py +340 -0
- pythonagent/agent/probes/Instrumentation/find.py +243 -0
- pythonagent/agent/probes/Instrumentation/module_version_resolver.py +155 -0
- pythonagent/agent/probes/Instrumentation/new_parser.py +64 -0
- pythonagent/agent/probes/Instrumentation/parser.py +129 -0
- pythonagent/agent/probes/__init__.py +219 -0
- pythonagent/agent/probes/base.py +303 -0
- pythonagent/agent/probes/cache/__init__.py +51 -0
- pythonagent/agent/probes/cache/redis.py +119 -0
- pythonagent/agent/probes/cache/redis_asyncio.py +83 -0
- pythonagent/agent/probes/coroutines/__init__.py +1 -0
- pythonagent/agent/probes/coroutines/asyncio.py +63 -0
- pythonagent/agent/probes/elasticdb/__init__.py +7 -0
- pythonagent/agent/probes/elasticdb/aelastic.py +54 -0
- pythonagent/agent/probes/frameworks/__init__.py +27 -0
- pythonagent/agent/probes/frameworks/agentprofiler.py +105 -0
- pythonagent/agent/probes/frameworks/aiohttp_web.py +155 -0
- pythonagent/agent/probes/frameworks/aisess.py +151 -0
- pythonagent/agent/probes/frameworks/asgi.py +340 -0
- pythonagent/agent/probes/frameworks/bottle.py +27 -0
- pythonagent/agent/probes/frameworks/cherry.py +25 -0
- pythonagent/agent/probes/frameworks/django.py +128 -0
- pythonagent/agent/probes/frameworks/falcon.py +21 -0
- pythonagent/agent/probes/frameworks/fastapi.py +35 -0
- pythonagent/agent/probes/frameworks/flask.py +30 -0
- pythonagent/agent/probes/frameworks/pyramid.py +56 -0
- pythonagent/agent/probes/frameworks/test.py +108 -0
- pythonagent/agent/probes/frameworks/tornado_async_web.py +117 -0
- pythonagent/agent/probes/frameworks/tornado_web.py +133 -0
- pythonagent/agent/probes/frameworks/wsgi.py +353 -0
- pythonagent/agent/probes/grpc/__init__.py +76 -0
- pythonagent/agent/probes/grpc/client_interceptor.py +132 -0
- pythonagent/agent/probes/grpc/server_interceptor.py +129 -0
- pythonagent/agent/probes/havoc/__init__.py +0 -0
- pythonagent/agent/probes/havoc/custom_memory_stress.py +186 -0
- pythonagent/agent/probes/havoc/custom_thread_stress.py +187 -0
- pythonagent/agent/probes/havoc/havoc_constants.py +218 -0
- pythonagent/agent/probes/havoc/havoc_manager.py +981 -0
- pythonagent/agent/probes/http/__init__.py +49 -0
- pythonagent/agent/probes/http/aiohttp_client.py +59 -0
- pythonagent/agent/probes/http/boto.py +12 -0
- pythonagent/agent/probes/http/httplib.py +110 -0
- pythonagent/agent/probes/http/httpx_client.py +116 -0
- pythonagent/agent/probes/http/requests.py +15 -0
- pythonagent/agent/probes/http/tornado_httpclient.py +85 -0
- pythonagent/agent/probes/http/urllib3.py +16 -0
- pythonagent/agent/probes/langchain/__init__.py +21 -0
- pythonagent/agent/probes/langchain/base_tool.py +95 -0
- pythonagent/agent/probes/langchain/langchain_community.py +136 -0
- pythonagent/agent/probes/langchain/langchain_core.py +32 -0
- pythonagent/agent/probes/langchain/langchain_openai.py +110 -0
- pythonagent/agent/probes/logging/__init__.py +106 -0
- pythonagent/agent/probes/message_brokers/__init__.py +4 -0
- pythonagent/agent/probes/message_brokers/pika.py +126 -0
- pythonagent/agent/probes/mongodb/__init__.py +6 -0
- pythonagent/agent/probes/mongodb/pymongo.py +286 -0
- pythonagent/agent/probes/openai/__init__.py +3 -0
- pythonagent/agent/probes/openai/openai.py +797 -0
- pythonagent/agent/probes/span.py +101 -0
- pythonagent/agent/probes/sql/__init__.py +13 -0
- pythonagent/agent/probes/sql/botocores3.py +51 -0
- pythonagent/agent/probes/sql/dbapi.py +285 -0
- pythonagent/agent/probes/sql/dynamodb.py +90 -0
- pythonagent/agent/probes/sql/mysql_connector.py +24 -0
- pythonagent/agent/probes/sql/mysql_connector_cext.py +24 -0
- pythonagent/agent/probes/sql/mysqldb.py +43 -0
- pythonagent/agent/probes/sql/psycopg2.py +174 -0
- pythonagent/agent/probes/sql/pymysql.py +25 -0
- pythonagent/bootstrap/__init__.py +0 -0
- pythonagent/bootstrap/cav_gunicorn.py +26 -0
- pythonagent/bootstrap/cavagent_lambda_wrapper.py +291 -0
- pythonagent/bootstrap/run.py +47 -0
- pythonagent/bootstrap/sitecustomize.py +287 -0
- pythonagent/cavisson/netdiagnostics/CavAgent/instrumentationprofile.json +26 -0
- pythonagent/cavisson/netdiagnostics/CavAgent/interceptor_points.txt +29 -0
- pythonagent/cavisson/netdiagnostics/python/CavAgent/instrumentationprofile.json +42 -0
- pythonagent/cavisson/netdiagnostics/python/CavAgent/interceptor_points.txt +29 -0
- pythonagent/cavisson/netdiagnostics/python/config/ndsettings.conf +6 -0
- pythonagent/config.py +279 -0
- pythonagent/find.py +72 -0
- pythonagent/find_mod_cls_name.py +54 -0
- pythonagent/lang.py +131 -0
- pythonagent/lib.py +91 -0
- pythonagent/main/__init__.py +0 -0
- pythonagent/main/pytrace/__init__.py +79 -0
- pythonagent/main/pytrace/commands/__init__.py +0 -0
- pythonagent/main/pytrace/commands/auto_discovery.py +25 -0
- pythonagent/main/pytrace/commands/run.py +401 -0
- pythonagent/main/pytrace/pytrace.py +133 -0
- pythonagent/main/wsgi.py +6 -0
- pythonagent/main.py +27 -0
- pythonagent/run.py +46 -0
- pythonagent/sqins.py +8 -0
- pythonagent/test.py +73 -0
- pythonagent/utils.py +168 -0
- pythonagent/vendor/__init__.py +0 -0
- pythonagent/vendor/pympler/__init__.py +1 -0
- pythonagent/vendor/pympler/asizeof.py +2810 -0
- pythonagent/vendor/pympler/charts.py +62 -0
- pythonagent/vendor/pympler/classtracker.py +590 -0
- pythonagent/vendor/pympler/classtracker_stats.py +780 -0
- pythonagent/vendor/pympler/garbagegraph.py +80 -0
- pythonagent/vendor/pympler/mprofile.py +97 -0
- pythonagent/vendor/pympler/muppy.py +275 -0
- pythonagent/vendor/pympler/panels.py +115 -0
- pythonagent/vendor/pympler/process.py +238 -0
- pythonagent/vendor/pympler/py.typed +0 -0
- pythonagent/vendor/pympler/refbrowser.py +451 -0
- pythonagent/vendor/pympler/refgraph.py +350 -0
- pythonagent/vendor/pympler/summary.py +321 -0
- pythonagent/vendor/pympler/tracker.py +267 -0
- pythonagent/vendor/pympler/util/__init__.py +0 -0
- pythonagent/vendor/pympler/util/bottle.py +3809 -0
- pythonagent/vendor/pympler/util/compat.py +23 -0
- pythonagent/vendor/pympler/util/stringutils.py +77 -0
- pythonagent/vendor/pympler/web.py +346 -0
- pythonagent/vendor/werkzeug/__init__.py +20 -0
- pythonagent/vendor/werkzeug/_compat.py +228 -0
- pythonagent/vendor/werkzeug/_internal.py +473 -0
- pythonagent/vendor/werkzeug/_reloader.py +341 -0
- pythonagent/vendor/werkzeug/datastructures.py +3120 -0
- pythonagent/vendor/werkzeug/debug/__init__.py +498 -0
- pythonagent/vendor/werkzeug/debug/console.py +218 -0
- pythonagent/vendor/werkzeug/debug/repr.py +297 -0
- pythonagent/vendor/werkzeug/debug/tbtools.py +628 -0
- pythonagent/vendor/werkzeug/exceptions.py +829 -0
- pythonagent/vendor/werkzeug/filesystem.py +64 -0
- pythonagent/vendor/werkzeug/formparser.py +584 -0
- pythonagent/vendor/werkzeug/http.py +1307 -0
- pythonagent/vendor/werkzeug/local.py +420 -0
- pythonagent/vendor/werkzeug/middleware/__init__.py +25 -0
- pythonagent/vendor/werkzeug/middleware/dispatcher.py +66 -0
- pythonagent/vendor/werkzeug/middleware/http_proxy.py +219 -0
- pythonagent/vendor/werkzeug/middleware/lint.py +408 -0
- pythonagent/vendor/werkzeug/middleware/profiler.py +132 -0
- pythonagent/vendor/werkzeug/middleware/proxy_fix.py +169 -0
- pythonagent/vendor/werkzeug/middleware/shared_data.py +293 -0
- pythonagent/vendor/werkzeug/posixemulation.py +117 -0
- pythonagent/vendor/werkzeug/routing.py +2210 -0
- pythonagent/vendor/werkzeug/security.py +249 -0
- pythonagent/vendor/werkzeug/serving.py +1117 -0
- pythonagent/vendor/werkzeug/test.py +1123 -0
- pythonagent/vendor/werkzeug/testapp.py +241 -0
- pythonagent/vendor/werkzeug/urls.py +1138 -0
- pythonagent/vendor/werkzeug/useragents.py +202 -0
- pythonagent/vendor/werkzeug/utils.py +778 -0
- pythonagent/vendor/werkzeug/wrappers/__init__.py +36 -0
- pythonagent/vendor/werkzeug/wrappers/accept.py +50 -0
- pythonagent/vendor/werkzeug/wrappers/auth.py +33 -0
- pythonagent/vendor/werkzeug/wrappers/base_request.py +673 -0
- pythonagent/vendor/werkzeug/wrappers/base_response.py +700 -0
- pythonagent/vendor/werkzeug/wrappers/common_descriptors.py +341 -0
- pythonagent/vendor/werkzeug/wrappers/cors.py +100 -0
- pythonagent/vendor/werkzeug/wrappers/etag.py +304 -0
- pythonagent/vendor/werkzeug/wrappers/json.py +145 -0
- pythonagent/vendor/werkzeug/wrappers/request.py +49 -0
- pythonagent/vendor/werkzeug/wrappers/response.py +84 -0
- pythonagent/vendor/werkzeug/wrappers/user_agent.py +14 -0
- pythonagent/vendor/werkzeug/wsgi.py +1000 -0
|
@@ -0,0 +1,341 @@
|
|
|
1
|
+
from datetime import datetime
|
|
2
|
+
from datetime import timedelta
|
|
3
|
+
|
|
4
|
+
from .._compat import string_types
|
|
5
|
+
from ..datastructures import CallbackDict
|
|
6
|
+
from ..http import dump_age
|
|
7
|
+
from ..http import dump_csp_header
|
|
8
|
+
from ..http import dump_header
|
|
9
|
+
from ..http import dump_options_header
|
|
10
|
+
from ..http import http_date
|
|
11
|
+
from ..http import parse_age
|
|
12
|
+
from ..http import parse_csp_header
|
|
13
|
+
from ..http import parse_date
|
|
14
|
+
from ..http import parse_options_header
|
|
15
|
+
from ..http import parse_set_header
|
|
16
|
+
from ..utils import cached_property
|
|
17
|
+
from ..utils import environ_property
|
|
18
|
+
from ..utils import get_content_type
|
|
19
|
+
from ..utils import header_property
|
|
20
|
+
from ..wsgi import get_content_length
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
class CommonRequestDescriptorsMixin(object):
|
|
24
|
+
"""A mixin for :class:`BaseRequest` subclasses. Request objects that
|
|
25
|
+
mix this class in will automatically get descriptors for a couple of
|
|
26
|
+
HTTP headers with automatic type conversion.
|
|
27
|
+
|
|
28
|
+
.. versionadded:: 0.5
|
|
29
|
+
"""
|
|
30
|
+
|
|
31
|
+
content_type = environ_property(
|
|
32
|
+
"CONTENT_TYPE",
|
|
33
|
+
doc="""The Content-Type entity-header field indicates the media
|
|
34
|
+
type of the entity-body sent to the recipient or, in the case of
|
|
35
|
+
the HEAD method, the media type that would have been sent had
|
|
36
|
+
the request been a GET.""",
|
|
37
|
+
)
|
|
38
|
+
|
|
39
|
+
@cached_property
|
|
40
|
+
def content_length(self):
|
|
41
|
+
"""The Content-Length entity-header field indicates the size of the
|
|
42
|
+
entity-body in bytes or, in the case of the HEAD method, the size of
|
|
43
|
+
the entity-body that would have been sent had the request been a
|
|
44
|
+
GET.
|
|
45
|
+
"""
|
|
46
|
+
return get_content_length(self.environ)
|
|
47
|
+
|
|
48
|
+
content_encoding = environ_property(
|
|
49
|
+
"HTTP_CONTENT_ENCODING",
|
|
50
|
+
doc="""The Content-Encoding entity-header field is used as a
|
|
51
|
+
modifier to the media-type. When present, its value indicates
|
|
52
|
+
what additional content codings have been applied to the
|
|
53
|
+
entity-body, and thus what decoding mechanisms must be applied
|
|
54
|
+
in order to obtain the media-type referenced by the Content-Type
|
|
55
|
+
header field.
|
|
56
|
+
|
|
57
|
+
.. versionadded:: 0.9""",
|
|
58
|
+
)
|
|
59
|
+
content_md5 = environ_property(
|
|
60
|
+
"HTTP_CONTENT_MD5",
|
|
61
|
+
doc="""The Content-MD5 entity-header field, as defined in
|
|
62
|
+
RFC 1864, is an MD5 digest of the entity-body for the purpose of
|
|
63
|
+
providing an end-to-end message integrity check (MIC) of the
|
|
64
|
+
entity-body. (Note: a MIC is good for detecting accidental
|
|
65
|
+
modification of the entity-body in transit, but is not proof
|
|
66
|
+
against malicious attacks.)
|
|
67
|
+
|
|
68
|
+
.. versionadded:: 0.9""",
|
|
69
|
+
)
|
|
70
|
+
referrer = environ_property(
|
|
71
|
+
"HTTP_REFERER",
|
|
72
|
+
doc="""The Referer[sic] request-header field allows the client
|
|
73
|
+
to specify, for the server's benefit, the address (URI) of the
|
|
74
|
+
resource from which the Request-URI was obtained (the
|
|
75
|
+
"referrer", although the header field is misspelled).""",
|
|
76
|
+
)
|
|
77
|
+
date = environ_property(
|
|
78
|
+
"HTTP_DATE",
|
|
79
|
+
None,
|
|
80
|
+
parse_date,
|
|
81
|
+
doc="""The Date general-header field represents the date and
|
|
82
|
+
time at which the message was originated, having the same
|
|
83
|
+
semantics as orig-date in RFC 822.""",
|
|
84
|
+
)
|
|
85
|
+
max_forwards = environ_property(
|
|
86
|
+
"HTTP_MAX_FORWARDS",
|
|
87
|
+
None,
|
|
88
|
+
int,
|
|
89
|
+
doc="""The Max-Forwards request-header field provides a
|
|
90
|
+
mechanism with the TRACE and OPTIONS methods to limit the number
|
|
91
|
+
of proxies or gateways that can forward the request to the next
|
|
92
|
+
inbound server.""",
|
|
93
|
+
)
|
|
94
|
+
|
|
95
|
+
def _parse_content_type(self):
|
|
96
|
+
if not hasattr(self, "_parsed_content_type"):
|
|
97
|
+
self._parsed_content_type = parse_options_header(
|
|
98
|
+
self.environ.get("CONTENT_TYPE", "")
|
|
99
|
+
)
|
|
100
|
+
|
|
101
|
+
@property
|
|
102
|
+
def mimetype(self):
|
|
103
|
+
"""Like :attr:`content_type`, but without parameters (eg, without
|
|
104
|
+
charset, type etc.) and always lowercase. For example if the content
|
|
105
|
+
type is ``text/HTML; charset=utf-8`` the mimetype would be
|
|
106
|
+
``'text/html'``.
|
|
107
|
+
"""
|
|
108
|
+
self._parse_content_type()
|
|
109
|
+
return self._parsed_content_type[0].lower()
|
|
110
|
+
|
|
111
|
+
@property
|
|
112
|
+
def mimetype_params(self):
|
|
113
|
+
"""The mimetype parameters as dict. For example if the content
|
|
114
|
+
type is ``text/html; charset=utf-8`` the params would be
|
|
115
|
+
``{'charset': 'utf-8'}``.
|
|
116
|
+
"""
|
|
117
|
+
self._parse_content_type()
|
|
118
|
+
return self._parsed_content_type[1]
|
|
119
|
+
|
|
120
|
+
@cached_property
|
|
121
|
+
def pragma(self):
|
|
122
|
+
"""The Pragma general-header field is used to include
|
|
123
|
+
implementation-specific directives that might apply to any recipient
|
|
124
|
+
along the request/response chain. All pragma directives specify
|
|
125
|
+
optional behavior from the viewpoint of the protocol; however, some
|
|
126
|
+
systems MAY require that behavior be consistent with the directives.
|
|
127
|
+
"""
|
|
128
|
+
return parse_set_header(self.environ.get("HTTP_PRAGMA", ""))
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
class CommonResponseDescriptorsMixin(object):
|
|
132
|
+
"""A mixin for :class:`BaseResponse` subclasses. Response objects that
|
|
133
|
+
mix this class in will automatically get descriptors for a couple of
|
|
134
|
+
HTTP headers with automatic type conversion.
|
|
135
|
+
"""
|
|
136
|
+
|
|
137
|
+
@property
|
|
138
|
+
def mimetype(self):
|
|
139
|
+
"""The mimetype (content type without charset etc.)"""
|
|
140
|
+
ct = self.headers.get("content-type")
|
|
141
|
+
if ct:
|
|
142
|
+
return ct.split(";")[0].strip()
|
|
143
|
+
|
|
144
|
+
@mimetype.setter
|
|
145
|
+
def mimetype(self, value):
|
|
146
|
+
self.headers["Content-Type"] = get_content_type(value, self.charset)
|
|
147
|
+
|
|
148
|
+
@property
|
|
149
|
+
def mimetype_params(self):
|
|
150
|
+
"""The mimetype parameters as dict. For example if the
|
|
151
|
+
content type is ``text/html; charset=utf-8`` the params would be
|
|
152
|
+
``{'charset': 'utf-8'}``.
|
|
153
|
+
|
|
154
|
+
.. versionadded:: 0.5
|
|
155
|
+
"""
|
|
156
|
+
|
|
157
|
+
def on_update(d):
|
|
158
|
+
self.headers["Content-Type"] = dump_options_header(self.mimetype, d)
|
|
159
|
+
|
|
160
|
+
d = parse_options_header(self.headers.get("content-type", ""))[1]
|
|
161
|
+
return CallbackDict(d, on_update)
|
|
162
|
+
|
|
163
|
+
location = header_property(
|
|
164
|
+
"Location",
|
|
165
|
+
doc="""The Location response-header field is used to redirect
|
|
166
|
+
the recipient to a location other than the Request-URI for
|
|
167
|
+
completion of the request or identification of a new
|
|
168
|
+
resource.""",
|
|
169
|
+
)
|
|
170
|
+
age = header_property(
|
|
171
|
+
"Age",
|
|
172
|
+
None,
|
|
173
|
+
parse_age,
|
|
174
|
+
dump_age,
|
|
175
|
+
doc="""The Age response-header field conveys the sender's
|
|
176
|
+
estimate of the amount of time since the response (or its
|
|
177
|
+
revalidation) was generated at the origin server.
|
|
178
|
+
|
|
179
|
+
Age values are non-negative decimal integers, representing time
|
|
180
|
+
in seconds.""",
|
|
181
|
+
)
|
|
182
|
+
content_type = header_property(
|
|
183
|
+
"Content-Type",
|
|
184
|
+
doc="""The Content-Type entity-header field indicates the media
|
|
185
|
+
type of the entity-body sent to the recipient or, in the case of
|
|
186
|
+
the HEAD method, the media type that would have been sent had
|
|
187
|
+
the request been a GET.""",
|
|
188
|
+
)
|
|
189
|
+
content_length = header_property(
|
|
190
|
+
"Content-Length",
|
|
191
|
+
None,
|
|
192
|
+
int,
|
|
193
|
+
str,
|
|
194
|
+
doc="""The Content-Length entity-header field indicates the size
|
|
195
|
+
of the entity-body, in decimal number of OCTETs, sent to the
|
|
196
|
+
recipient or, in the case of the HEAD method, the size of the
|
|
197
|
+
entity-body that would have been sent had the request been a
|
|
198
|
+
GET.""",
|
|
199
|
+
)
|
|
200
|
+
content_location = header_property(
|
|
201
|
+
"Content-Location",
|
|
202
|
+
doc="""The Content-Location entity-header field MAY be used to
|
|
203
|
+
supply the resource location for the entity enclosed in the
|
|
204
|
+
message when that entity is accessible from a location separate
|
|
205
|
+
from the requested resource's URI.""",
|
|
206
|
+
)
|
|
207
|
+
content_encoding = header_property(
|
|
208
|
+
"Content-Encoding",
|
|
209
|
+
doc="""The Content-Encoding entity-header field is used as a
|
|
210
|
+
modifier to the media-type. When present, its value indicates
|
|
211
|
+
what additional content codings have been applied to the
|
|
212
|
+
entity-body, and thus what decoding mechanisms must be applied
|
|
213
|
+
in order to obtain the media-type referenced by the Content-Type
|
|
214
|
+
header field.""",
|
|
215
|
+
)
|
|
216
|
+
content_md5 = header_property(
|
|
217
|
+
"Content-MD5",
|
|
218
|
+
doc="""The Content-MD5 entity-header field, as defined in
|
|
219
|
+
RFC 1864, is an MD5 digest of the entity-body for the purpose of
|
|
220
|
+
providing an end-to-end message integrity check (MIC) of the
|
|
221
|
+
entity-body. (Note: a MIC is good for detecting accidental
|
|
222
|
+
modification of the entity-body in transit, but is not proof
|
|
223
|
+
against malicious attacks.)""",
|
|
224
|
+
)
|
|
225
|
+
content_security_policy = header_property(
|
|
226
|
+
"Content-Security-Policy",
|
|
227
|
+
None,
|
|
228
|
+
parse_csp_header,
|
|
229
|
+
dump_csp_header,
|
|
230
|
+
doc="""The Content-Security-Policy header adds an additional layer of
|
|
231
|
+
security to help detect and mitigate certain types of attacks.""",
|
|
232
|
+
)
|
|
233
|
+
content_security_policy_report_only = header_property(
|
|
234
|
+
"Content-Security-Policy-Report-Only",
|
|
235
|
+
None,
|
|
236
|
+
parse_csp_header,
|
|
237
|
+
dump_csp_header,
|
|
238
|
+
doc="""The Content-Security-Policy-Report-Only header adds a csp policy
|
|
239
|
+
that is not enforced but is reported thereby helping detect
|
|
240
|
+
certain types of attacks.""",
|
|
241
|
+
)
|
|
242
|
+
date = header_property(
|
|
243
|
+
"Date",
|
|
244
|
+
None,
|
|
245
|
+
parse_date,
|
|
246
|
+
http_date,
|
|
247
|
+
doc="""The Date general-header field represents the date and
|
|
248
|
+
time at which the message was originated, having the same
|
|
249
|
+
semantics as orig-date in RFC 822.""",
|
|
250
|
+
)
|
|
251
|
+
expires = header_property(
|
|
252
|
+
"Expires",
|
|
253
|
+
None,
|
|
254
|
+
parse_date,
|
|
255
|
+
http_date,
|
|
256
|
+
doc="""The Expires entity-header field gives the date/time after
|
|
257
|
+
which the response is considered stale. A stale cache entry may
|
|
258
|
+
not normally be returned by a cache.""",
|
|
259
|
+
)
|
|
260
|
+
last_modified = header_property(
|
|
261
|
+
"Last-Modified",
|
|
262
|
+
None,
|
|
263
|
+
parse_date,
|
|
264
|
+
http_date,
|
|
265
|
+
doc="""The Last-Modified entity-header field indicates the date
|
|
266
|
+
and time at which the origin server believes the variant was
|
|
267
|
+
last modified.""",
|
|
268
|
+
)
|
|
269
|
+
|
|
270
|
+
@property
|
|
271
|
+
def retry_after(self):
|
|
272
|
+
"""The Retry-After response-header field can be used with a
|
|
273
|
+
503 (Service Unavailable) response to indicate how long the
|
|
274
|
+
service is expected to be unavailable to the requesting client.
|
|
275
|
+
|
|
276
|
+
Time in seconds until expiration or date.
|
|
277
|
+
"""
|
|
278
|
+
value = self.headers.get("retry-after")
|
|
279
|
+
if value is None:
|
|
280
|
+
return
|
|
281
|
+
elif value.isdigit():
|
|
282
|
+
return datetime.utcnow() + timedelta(seconds=int(value))
|
|
283
|
+
return parse_date(value)
|
|
284
|
+
|
|
285
|
+
@retry_after.setter
|
|
286
|
+
def retry_after(self, value):
|
|
287
|
+
if value is None:
|
|
288
|
+
if "retry-after" in self.headers:
|
|
289
|
+
del self.headers["retry-after"]
|
|
290
|
+
return
|
|
291
|
+
elif isinstance(value, datetime):
|
|
292
|
+
value = http_date(value)
|
|
293
|
+
else:
|
|
294
|
+
value = str(value)
|
|
295
|
+
self.headers["Retry-After"] = value
|
|
296
|
+
|
|
297
|
+
def _set_property(name, doc=None): # noqa: B902
|
|
298
|
+
def fget(self):
|
|
299
|
+
def on_update(header_set):
|
|
300
|
+
if not header_set and name in self.headers:
|
|
301
|
+
del self.headers[name]
|
|
302
|
+
elif header_set:
|
|
303
|
+
self.headers[name] = header_set.to_header()
|
|
304
|
+
|
|
305
|
+
return parse_set_header(self.headers.get(name), on_update)
|
|
306
|
+
|
|
307
|
+
def fset(self, value):
|
|
308
|
+
if not value:
|
|
309
|
+
del self.headers[name]
|
|
310
|
+
elif isinstance(value, string_types):
|
|
311
|
+
self.headers[name] = value
|
|
312
|
+
else:
|
|
313
|
+
self.headers[name] = dump_header(value)
|
|
314
|
+
|
|
315
|
+
return property(fget, fset, doc=doc)
|
|
316
|
+
|
|
317
|
+
vary = _set_property(
|
|
318
|
+
"Vary",
|
|
319
|
+
doc="""The Vary field value indicates the set of request-header
|
|
320
|
+
fields that fully determines, while the response is fresh,
|
|
321
|
+
whether a cache is permitted to use the response to reply to a
|
|
322
|
+
subsequent request without revalidation.""",
|
|
323
|
+
)
|
|
324
|
+
content_language = _set_property(
|
|
325
|
+
"Content-Language",
|
|
326
|
+
doc="""The Content-Language entity-header field describes the
|
|
327
|
+
natural language(s) of the intended audience for the enclosed
|
|
328
|
+
entity. Note that this might not be equivalent to all the
|
|
329
|
+
languages used within the entity-body.""",
|
|
330
|
+
)
|
|
331
|
+
allow = _set_property(
|
|
332
|
+
"Allow",
|
|
333
|
+
doc="""The Allow entity-header field lists the set of methods
|
|
334
|
+
supported by the resource identified by the Request-URI. The
|
|
335
|
+
purpose of this field is strictly to inform the recipient of
|
|
336
|
+
valid methods associated with the resource. An Allow header
|
|
337
|
+
field MUST be present in a 405 (Method Not Allowed)
|
|
338
|
+
response.""",
|
|
339
|
+
)
|
|
340
|
+
|
|
341
|
+
del _set_property
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
from ..http import dump_header
|
|
2
|
+
from ..http import parse_set_header
|
|
3
|
+
from ..utils import environ_property
|
|
4
|
+
from ..utils import header_property
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class CORSRequestMixin(object):
|
|
8
|
+
"""A mixin for :class:`~werkzeug.wrappers.BaseRequest` subclasses
|
|
9
|
+
that adds descriptors for Cross Origin Resource Sharing (CORS)
|
|
10
|
+
headers.
|
|
11
|
+
|
|
12
|
+
.. versionadded:: 1.0
|
|
13
|
+
"""
|
|
14
|
+
|
|
15
|
+
origin = environ_property(
|
|
16
|
+
"HTTP_ORIGIN",
|
|
17
|
+
doc=(
|
|
18
|
+
"The host that the request originated from. Set"
|
|
19
|
+
" :attr:`~CORSResponseMixin.access_control_allow_origin` on"
|
|
20
|
+
" the response to indicate which origins are allowed."
|
|
21
|
+
),
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
access_control_request_headers = environ_property(
|
|
25
|
+
"HTTP_ACCESS_CONTROL_REQUEST_HEADERS",
|
|
26
|
+
load_func=parse_set_header,
|
|
27
|
+
doc=(
|
|
28
|
+
"Sent with a preflight request to indicate which headers"
|
|
29
|
+
" will be sent with the cross origin request. Set"
|
|
30
|
+
" :attr:`~CORSResponseMixin.access_control_allow_headers`"
|
|
31
|
+
" on the response to indicate which headers are allowed."
|
|
32
|
+
),
|
|
33
|
+
)
|
|
34
|
+
|
|
35
|
+
access_control_request_method = environ_property(
|
|
36
|
+
"HTTP_ACCESS_CONTROL_REQUEST_METHOD",
|
|
37
|
+
doc=(
|
|
38
|
+
"Sent with a preflight request to indicate which method"
|
|
39
|
+
" will be used for the cross origin request. Set"
|
|
40
|
+
" :attr:`~CORSResponseMixin.access_control_allow_methods`"
|
|
41
|
+
" on the response to indicate which methods are allowed."
|
|
42
|
+
),
|
|
43
|
+
)
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
class CORSResponseMixin(object):
|
|
47
|
+
"""A mixin for :class:`~werkzeug.wrappers.BaseResponse` subclasses
|
|
48
|
+
that adds descriptors for Cross Origin Resource Sharing (CORS)
|
|
49
|
+
headers.
|
|
50
|
+
|
|
51
|
+
.. versionadded:: 1.0
|
|
52
|
+
"""
|
|
53
|
+
|
|
54
|
+
@property
|
|
55
|
+
def access_control_allow_credentials(self):
|
|
56
|
+
"""Whether credentials can be shared by the browser to
|
|
57
|
+
JavaScript code. As part of the preflight request it indicates
|
|
58
|
+
whether credentials can be used on the cross origin request.
|
|
59
|
+
"""
|
|
60
|
+
return "Access-Control-Allow-Credentials" in self.headers
|
|
61
|
+
|
|
62
|
+
@access_control_allow_credentials.setter
|
|
63
|
+
def access_control_allow_credentials(self, value):
|
|
64
|
+
if value is True:
|
|
65
|
+
self.headers["Access-Control-Allow-Credentials"] = "true"
|
|
66
|
+
else:
|
|
67
|
+
self.headers.pop("Access-Control-Allow-Credentials", None)
|
|
68
|
+
|
|
69
|
+
access_control_allow_headers = header_property(
|
|
70
|
+
"Access-Control-Allow-Headers",
|
|
71
|
+
load_func=parse_set_header,
|
|
72
|
+
dump_func=dump_header,
|
|
73
|
+
doc="Which headers can be sent with the cross origin request.",
|
|
74
|
+
)
|
|
75
|
+
|
|
76
|
+
access_control_allow_methods = header_property(
|
|
77
|
+
"Access-Control-Allow-Methods",
|
|
78
|
+
load_func=parse_set_header,
|
|
79
|
+
dump_func=dump_header,
|
|
80
|
+
doc="Which methods can be used for the cross origin request.",
|
|
81
|
+
)
|
|
82
|
+
|
|
83
|
+
access_control_allow_origin = header_property(
|
|
84
|
+
"Access-Control-Allow-Origin",
|
|
85
|
+
doc="The origin or '*' for any origin that may make cross origin requests.",
|
|
86
|
+
)
|
|
87
|
+
|
|
88
|
+
access_control_expose_headers = header_property(
|
|
89
|
+
"Access-Control-Expose-Headers",
|
|
90
|
+
load_func=parse_set_header,
|
|
91
|
+
dump_func=dump_header,
|
|
92
|
+
doc="Which headers can be shared by the browser to JavaScript code.",
|
|
93
|
+
)
|
|
94
|
+
|
|
95
|
+
access_control_max_age = header_property(
|
|
96
|
+
"Access-Control-Max-Age",
|
|
97
|
+
load_func=int,
|
|
98
|
+
dump_func=str,
|
|
99
|
+
doc="The maximum age in seconds the access control settings can be cached for.",
|
|
100
|
+
)
|