Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

REQUEST with unknown and undetectable encoding #600

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions sandbox/grist/functions/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -689,12 +689,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):
Expand Down
7 changes: 7 additions & 0 deletions sandbox/grist/test_requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,13 @@ def test_apparent_encoding(self):
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 TestRequestFunction(test_engine.EngineTestCase):
sample = testutil.parse_test_sample({
Expand Down