-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcompression.diff
More file actions
270 lines (250 loc) · 10.4 KB
/
Copy pathcompression.diff
File metadata and controls
270 lines (250 loc) · 10.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
--- input/input.py
+++ output/output.py
@@ -98,56 +98,18 @@
)
def _set_content_type_params(self, meta):
- """Set content_type, content_params, and encoding."""
- self.content_type, self.content_params = parse_header_parameters(
- meta.get("CONTENT_TYPE", "")
- )
- if "charset" in self.content_params:
- try:
- codecs.lookup(self.content_params["charset"])
- except LookupError:
- pass
- else:
- self.encoding = self.content_params["charset"]
+ ... # 11 line(s) collapsed ⟦tj:318f71979ba5bf1615ad7516e3d9d795⟧
def _get_raw_host(self):
"""
Return the HTTP host using the environment or request headers. Skip
- allowed hosts protection, so may return an insecure host.
- """
- # We try three options, in order of decreasing preference.
- if settings.USE_X_FORWARDED_HOST and ("HTTP_X_FORWARDED_HOST" in self.META):
- host = self.META["HTTP_X_FORWARDED_HOST"]
- elif "HTTP_HOST" in self.META:
- host = self.META["HTTP_HOST"]
- else:
- # Reconstruct the host using the algorithm from PEP 333.
- host = self.META["SERVER_NAME"]
- server_port = self.get_port()
- if server_port != ("443" if self.is_secure() else "80"):
- host = "%s:%s" % (host, server_port)
+... # 13 line(s) collapsed ⟦tj:ae3998ffd7f8984b619ad34f1c2c0a84⟧
return host
def get_host(self):
"""Return the HTTP host using the environment or request headers."""
host = self._get_raw_host()
-
- # Allow variants of localhost if ALLOWED_HOSTS is empty and DEBUG=True.
- allowed_hosts = settings.ALLOWED_HOSTS
- if settings.DEBUG and not allowed_hosts:
- allowed_hosts = [".localhost", "127.0.0.1", "[::1]"]
-
- domain, port = split_domain_port(host)
- if domain and validate_host(domain, allowed_hosts):
- return host
- else:
- msg = "Invalid HTTP_HOST header: %r." % host
- if domain:
- msg += " You may need to add %r to ALLOWED_HOSTS." % domain
- else:
- msg += (
- " The domain name provided is not valid according to RFC 1034/1035."
- )
+... # 17 line(s) collapsed ⟦tj:92ead705017835fa7e977416b6ebe742⟧
raise DisallowedHost(msg)
def get_port(self):
@@ -167,15 +129,7 @@
def _get_full_path(self, path, force_append_slash):
# RFC 3986 requires query string arguments to be in the ASCII range.
# Rather than crash if this doesn't happen, we encode defensively.
- return "%s%s%s" % (
- escape_uri_path(path),
- "/" if force_append_slash and not path.endswith("/") else "",
- (
- ("?" + iri_to_uri(self.META.get("QUERY_STRING", "")))
- if self.META.get("QUERY_STRING", "")
- else ""
- ),
- )
+ ... # 9 line(s) collapsed ⟦tj:8ae0640bc4a6e039ca6a1d6d8d248489⟧
def get_signed_cookie(self, key, default=RAISE_ERROR, salt="", max_age=None):
"""
@@ -204,40 +158,7 @@
def build_absolute_uri(self, location=None):
"""
Build an absolute URI from the location and the variables available in
- this request. If no ``location`` is specified, build the absolute URI
- using request.get_full_path(). If the location is absolute, convert it
- to an RFC 3987 compliant URI and return it. If location is relative or
- is scheme-relative (i.e., ``//example.com/``), urljoin() it to a base
- URL constructed from the request variables.
- """
- if location is None:
- # Make it an absolute url (but schemeless and domainless) for the
- # edge case that the path starts with '//'.
- location = "//%s" % self.get_full_path()
- else:
- # Coerce lazy locations.
- location = str(location)
- bits = urlsplit(location)
- if not (bits.scheme and bits.netloc):
- # Handle the simple, most common case. If the location is absolute
- # and a scheme or host (netloc) isn't provided, skip an expensive
- # urljoin() as long as no path segments are '.' or '..'.
- if (
- bits.path.startswith("/")
- and not bits.scheme
- and not bits.netloc
- and "/./" not in bits.path
- and "/../" not in bits.path
- ):
- # If location starts with '//' but has no netloc, reuse the
- # schema and netloc from the current request. Strip the double
- # slashes and continue as if it wasn't specified.
- location = self._current_scheme_host + location.removeprefix("//")
- else:
- # Join the constructed URL with the provided location, which
- # allows the provided location to apply query strings to the
- # base path.
- location = urljoin(self._current_scheme_host + self.path, location)
+... # 34 line(s) collapsed ⟦tj:9dcce7c20e41e6f5e6522f07bfeba41f⟧
return iri_to_uri(location)
@cached_property
@@ -276,16 +197,7 @@
@encoding.setter
def encoding(self, val):
- """
- Set the encoding used for GET/POST accesses. If the GET or POST
- dictionary has already been created, remove and recreate it on the
- next access (so that it is decoded correctly).
- """
- self._encoding = val
- if hasattr(self, "GET"):
- del self.GET
- if hasattr(self, "_post"):
- del self._post
+ ... # 10 line(s) collapsed ⟦tj:c9804e728bfd4632633920a7843a9b8b⟧
def _initialize_handlers(self):
self._upload_handlers = [
@@ -310,16 +222,7 @@
self._upload_handlers = upload_handlers
def parse_file_upload(self, META, post_data):
- """Return a tuple of (POST QueryDict, FILES MultiValueDict)."""
- self.upload_handlers = ImmutableList(
- self.upload_handlers,
- warning=(
- "You cannot alter upload handlers after the upload has been "
- "processed."
- ),
- )
- parser = MultiPartParser(META, post_data, self.upload_handlers, self.encoding)
- return parser.parse()
+ ... # 10 line(s) collapsed ⟦tj:e45198db389c45d59776c6840cee3e5e⟧
@property
def body(self):
@@ -533,16 +436,7 @@
@classmethod
def fromkeys(cls, iterable, value="", mutable=False, encoding=None):
- """
- Return a new QueryDict with keys (may be repeated) from an iterable and
- values from value.
- """
- q = cls("", mutable=True, encoding=encoding)
- for key in iterable:
- q.appendlist(key, value)
- if not mutable:
- q._mutable = False
- return q
+ ... # 10 line(s) collapsed ⟦tj:ea89dde0f66ac8216d01388e25ec01d4⟧
@property
def encoding(self):
@@ -622,33 +516,7 @@
def urlencode(self, safe=None):
"""
Return an encoded string of all query string arguments.
-
- `safe` specifies characters which don't require quoting, for example::
-
- >>> q = QueryDict(mutable=True)
- >>> q['next'] = '/a&b/'
- >>> q.urlencode()
- 'next=%2Fa%26b%2F'
- >>> q.urlencode(safe='/')
- 'next=/a%26b/'
- """
- output = []
- if safe:
- safe = safe.encode(self.encoding)
-
- def encode(k, v):
- return "%s=%s" % ((quote(k, safe), quote(v, safe)))
-
- else:
-
- def encode(k, v):
- return urlencode({k: v})
-
- for k, list_ in self.lists():
- output.extend(
- encode(k.encode(self.encoding), str(v).encode(self.encoding))
- for v in list_
- )
+... # 27 line(s) collapsed ⟦tj:077d124acdf701eb6f0c0cf9ff26860f⟧
return "&".join(output)
@@ -687,52 +555,22 @@
# django.utils.encoding.force_str() for parsing URLs and form inputs. Thus,
# this slightly more restricted function, used by QueryDict.
def bytes_to_text(s, encoding):
- """
- Convert bytes objects to strings, using the given encoding. Illegally
- encoded input characters are replaced with Unicode "unknown" codepoint
- (\ufffd).
+ ... # 11 line(s) collapsed ⟦tj:ec78e83a35a56554122206f8f2467627⟧
- Return any non-bytes objects without change.
- """
- if isinstance(s, bytes):
- return str(s, encoding, "replace")
- else:
- return s
-
def split_domain_port(host):
- """
- Return a (domain, port) tuple from a given host.
+ ... # 11 line(s) collapsed ⟦tj:4997cd3dd5f1aee3a5966b311967fba3⟧
- Returned domain is lowercased. If the host is invalid, the domain will be
- empty.
- """
- if match := host_validation_re.fullmatch(host.lower()):
- domain, port = match.groups(default="")
- # Remove a trailing dot (if present) from the domain.
- return domain.removesuffix("."), port
- return "", ""
-
def validate_host(host, allowed_hosts):
"""
Validate the given host for this site.
-
- Check that the host looks valid and matches a host or host pattern in the
- given list of ``allowed_hosts``. Any pattern beginning with a period
- matches a domain and all its subdomains (e.g. ``.example.com`` matches
- ``example.com`` and any subdomain), ``*`` matches anything, and anything
- else must match exactly.
-
- Note: This function assumes that the given host is lowercased and has
- already had the port, if any, stripped off.
-
- Return ``True`` for a valid host, ``False`` otherwise.
- """
- return any(
- pattern == "*" or is_same_domain(host, pattern) for pattern in allowed_hosts
+... # 14 line(s) collapsed ⟦tj:29bd899770727238f6dd31965295822f⟧
)
def parse_accept_header(header):
return [MediaType(token) for token in header.split(",") if token.strip()]
+[omitted blocks are individually retrievable: call tinyjuice_retrieve with the token inside an omission marker to expand just that block]
+
+[PARTIAL view — full original (25750 bytes): call tinyjuice_retrieve with token "48f28b669ac2435fad75241abaca52f4"]
\ No newline at end of file