mirror of
https://github.com/gristlabs/grist-core.git
synced 2024-10-27 20:44:07 +00:00
REQUEST with unknown and undetectable encoding (#600)
This commit is contained in:
parent
5119ce92cb
commit
57380190bc
@ -740,12 +740,12 @@ class Response(object):
|
||||
"""
|
||||
Similar to the Response class from the `requests` library.
|
||||
"""
|
||||
def __init__(self, content, status, statusText, headers, encoding):
|
||||
def __init__(self, content, status, statusText, headers, encoding=None):
|
||||
self.content = content # raw bytes
|
||||
self.status_code = status # e.g. 404
|
||||
self.reason = statusText # e.g. "Not Found"
|
||||
self.headers = CaseInsensitiveDict(headers)
|
||||
self.encoding = encoding or self.apparent_encoding
|
||||
self.encoding = encoding or self.apparent_encoding or "utf-8"
|
||||
|
||||
@property
|
||||
def text(self):
|
||||
|
@ -73,6 +73,13 @@ class TestResponse(unittest.TestCase):
|
||||
self.assertEqual(r.content, content)
|
||||
self.assertEqual(r.text, text)
|
||||
|
||||
def test_unknown_undetectable_encoding(self):
|
||||
content = b''
|
||||
r = Response(content, 200, "OK", {}, encoding=None)
|
||||
|
||||
# Not knowing the encoding should not break text
|
||||
self.assertEqual(r.text, "")
|
||||
|
||||
|
||||
class TestRequestsPostInterface(unittest.TestCase):
|
||||
def test_no_post_args(self):
|
||||
|
Loading…
Reference in New Issue
Block a user