mirror of
https://github.com/django/daphne.git
synced 2025-07-13 09:22:17 +03:00
Python 3 fixes
This commit is contained in:
parent
13766a3027
commit
fa58375a51
|
@ -71,7 +71,7 @@ class DatabaseChannelLayer(object):
|
|||
# Keep making channel names till one isn't present.
|
||||
while True:
|
||||
random_string = "".join(random.choice(string.ascii_letters) for i in range(8))
|
||||
new_name = pattern.replace(b"?", random_string)
|
||||
new_name = pattern.replace("?", random_string)
|
||||
if not self.channel_model.objects.filter(channel=new_name).exists():
|
||||
return new_name
|
||||
|
||||
|
|
|
@ -58,12 +58,14 @@ class AsgiRequest(http.HttpRequest):
|
|||
corrected_name = "CONTENT_TYPE"
|
||||
else:
|
||||
corrected_name = 'HTTP_%s' % name.upper().replace("-", "_")
|
||||
self.META[corrected_name] = value
|
||||
# TODO: Look at request encoding for unicode decode
|
||||
self.META[corrected_name] = value.decode("latin1")
|
||||
# Pull out content length info
|
||||
if self.META.get('CONTENT_LENGTH', None):
|
||||
try:
|
||||
self._content_length = int(self.META['CONTENT_LENGTH'])
|
||||
except (ValueError, TypeError):
|
||||
except (ValueError, TypeError) as e:
|
||||
print (self.META)
|
||||
pass
|
||||
# Body handling
|
||||
self._body = message.get("body", b"")
|
||||
|
@ -164,9 +166,25 @@ class AsgiHandler(base.BaseHandler):
|
|||
# Collect cookies into headers.
|
||||
# Note that we have to preserve header case as there are some non-RFC
|
||||
# compliant clients that want things like Content-Type correct. Ugh.
|
||||
response_headers = [(str(k), str(v)) for k, v in response.items()]
|
||||
response_headers = []
|
||||
for header, value in response.items():
|
||||
if isinstance(header, six.binary_type):
|
||||
header = header.decode("latin1")
|
||||
if isinstance(value, six.text_type):
|
||||
value = value.encode("latin1")
|
||||
response_headers.append(
|
||||
(
|
||||
six.text_type(header),
|
||||
six.binary_type(value),
|
||||
)
|
||||
)
|
||||
for c in response.cookies.values():
|
||||
response_headers.append((str('Set-Cookie'), str(c.output(header=''))))
|
||||
response_headers.append(
|
||||
(
|
||||
'Set-Cookie',
|
||||
six.binary_type(c.output(header='')),
|
||||
)
|
||||
)
|
||||
# Make initial response message
|
||||
message = {
|
||||
"status": response.status_code,
|
||||
|
|
|
@ -159,7 +159,7 @@ class RequestTests(SimpleTestCase):
|
|||
"body_channel": "test-input",
|
||||
"headers": {
|
||||
"content-type": b"multipart/form-data; boundary=BOUNDARY",
|
||||
"content-length": six.binary_type(len(body)),
|
||||
"content-length": six.text_type(len(body)).encode("ascii"),
|
||||
},
|
||||
}, "test")
|
||||
self.channel_layer.send("test-input", {
|
||||
|
@ -175,4 +175,4 @@ class RequestTests(SimpleTestCase):
|
|||
self.assertTrue(request.META["CONTENT_TYPE"].startswith("multipart/form-data"))
|
||||
self.assertFalse(request._post_parse_error)
|
||||
self.assertEqual(request.POST["title"], "My First Book")
|
||||
self.assertEqual(request.FILES["pdf"].read(), "FAKEPDFBYTESGOHERE")
|
||||
self.assertEqual(request.FILES["pdf"].read(), b"FAKEPDFBYTESGOHERE")
|
||||
|
|
Loading…
Reference in New Issue
Block a user