Skip to content

Commit

Permalink
Merge branch 'master' of github.com:KeepSafe/aiohttp
Browse files Browse the repository at this point in the history
  • Loading branch information
asvetlov committed Jun 3, 2016
2 parents e53e269 + 21241bb commit c4564ef
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 2 deletions.
11 changes: 10 additions & 1 deletion aiohttp/client_reqrep.py
Original file line number Diff line number Diff line change
Expand Up @@ -568,8 +568,17 @@ def __del__(self, _warnings=warnings):

def __repr__(self):
out = io.StringIO()
ascii_encodable_url = self.url.encode('ascii', 'backslashreplace') \
.decode('ascii')
if self.reason:
ascii_encodable_reason = self.reason.encode('ascii',
'backslashreplace') \
.decode('ascii')
else:
ascii_encodable_reason = self.reason
print('<ClientResponse({}) [{} {}]>'.format(
self.url, self.status, self.reason), file=out)
ascii_encodable_url, self.status, ascii_encodable_reason),
file=out)
print(self.headers, file=out)
return out.getvalue()

Expand Down
4 changes: 3 additions & 1 deletion aiohttp/web_reqrep.py
Original file line number Diff line number Diff line change
Expand Up @@ -399,8 +399,10 @@ def copy(self):
raise NotImplementedError

def __repr__(self):
ascii_encodable_path = self.path.encode('ascii', 'backslashreplace') \
.decode('ascii')
return "<{} {} {} >".format(self.__class__.__name__,
self.method, self.path)
self.method, ascii_encodable_path)


############################################################
Expand Down
15 changes: 15 additions & 0 deletions tests/test_client_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,21 @@ def test_repr(self):
'<ClientResponse(http://def-cl-resp.org) [200 Ok]>',
repr(self.response))

def test_repr_non_ascii_url(self):
response = ClientResponse('get', 'http://fake-host.org/\u03bb')
self.assertIn(
"<ClientResponse(http://fake-host.org/\\u03bb) [None None]>",
repr(response))
response.close()

def test_repr_non_ascii_reason(self):
response = ClientResponse('get', 'http://fake-host.org/path')
response.reason = '\u03bb'
self.assertIn(
"<ClientResponse(http://fake-host.org/path) [None \\u03bb]>",
repr(response))
response.close()

def test_read_and_release_connection(self):
def side_effect(*args, **kwargs):
fut = helpers.create_future(self.loop)
Expand Down
5 changes: 5 additions & 0 deletions tests/test_web_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,11 @@ def test___repr__(make_request):
assert "<Request GET /path/to >" == repr(req)


def test___repr___non_ascii_path(make_request):
req = make_request('GET', '/path/\U0001f415\U0001f308')
assert "<Request GET /path/\\U0001f415\\U0001f308 >" == repr(req)


def test_http_scheme(make_request):
req = make_request('GET', '/')
assert "http" == req.scheme
Expand Down

0 comments on commit c4564ef

Please sign in to comment.