From 12dafd07b87e3412f48cfb3672c1804b3879464c Mon Sep 17 00:00:00 2001 From: huyuhan Date: Fri, 15 Sep 2017 18:34:56 +0800 Subject: [PATCH 1/4] add __repr__ for sanic request --- sanic/request.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/sanic/request.py b/sanic/request.py index 27ff011e..4e8a2e07 100644 --- a/sanic/request.py +++ b/sanic/request.py @@ -68,6 +68,11 @@ class Request(dict): self._cookies = None self.stream = None + def __repr__(self): + if self.method is None or not self._parsed_url: + return '<%s>' % self.__class__.__name__ + return '<%s: %s %r>' % (self.__class__.__name__, self.method, self.path) + @property def json(self): if self.parsed_json is None: From 77f70a0792eef25841039dcd1e2266f2d78e79f2 Mon Sep 17 00:00:00 2001 From: huyuhan Date: Fri, 15 Sep 2017 20:56:44 +0800 Subject: [PATCH 2/4] add __repr__ for sanic request --- sanic/request.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/sanic/request.py b/sanic/request.py index 4e8a2e07..fa80b47c 100644 --- a/sanic/request.py +++ b/sanic/request.py @@ -19,8 +19,9 @@ except ImportError: from sanic.exceptions import InvalidUsage from sanic.log import log - DEFAULT_HTTP_CONTENT_TYPE = "application/octet-stream" + + # HTTP/1.1: https://www.w3.org/Protocols/rfc2616/rfc2616-sec7.html#sec7.2.1 # > If the media type remains unknown, the recipient SHOULD treat it # > as type "application/octet-stream" @@ -69,9 +70,9 @@ class Request(dict): self.stream = None def __repr__(self): - if self.method is None or not self._parsed_url: + if self.method is None or not self.path: return '<%s>' % self.__class__.__name__ - return '<%s: %s %r>' % (self.__class__.__name__, self.method, self.path) + return '<%s: %s %s>' % (self.__class__.__name__, self.method, self.path) @property def json(self): @@ -175,8 +176,8 @@ class Request(dict): remote_addrs = [ addr for addr in [ addr.strip() for addr in forwarded_for - ] if addr - ] + ] if addr + ] if len(remote_addrs) > 0: self._remote_addr = remote_addrs[0] else: From f6eb35f67d6637fdd4b13e4d38ba17d4d21f1fb3 Mon Sep 17 00:00:00 2001 From: huyuhan Date: Fri, 15 Sep 2017 21:05:25 +0800 Subject: [PATCH 3/4] add __repr__ for sanic request --- sanic/request.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/sanic/request.py b/sanic/request.py index fa80b47c..ea5c071e 100644 --- a/sanic/request.py +++ b/sanic/request.py @@ -71,8 +71,10 @@ class Request(dict): def __repr__(self): if self.method is None or not self.path: - return '<%s>' % self.__class__.__name__ - return '<%s: %s %s>' % (self.__class__.__name__, self.method, self.path) + return '<{class_name}>'.format(class_name=self.__class__.__name__) + return '<{class_name}: {method} {path}>'.format(class_name=self.__class__.__name__, + method=self.method, + path=self.path) @property def json(self): From 074d36eeba5a793b0c87becfda81603fcc5cb824 Mon Sep 17 00:00:00 2001 From: huyuhan Date: Fri, 15 Sep 2017 21:15:05 +0800 Subject: [PATCH 4/4] add __repr__ for sanic request --- sanic/request.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/sanic/request.py b/sanic/request.py index ea5c071e..26b14fd9 100644 --- a/sanic/request.py +++ b/sanic/request.py @@ -71,10 +71,10 @@ class Request(dict): def __repr__(self): if self.method is None or not self.path: - return '<{class_name}>'.format(class_name=self.__class__.__name__) - return '<{class_name}: {method} {path}>'.format(class_name=self.__class__.__name__, - method=self.method, - path=self.path) + return '<{0}>'.format(self.__class__.__name__) + return '<{0}: {1} {2}>'.format(self.__class__.__name__, + self.method, + self.path) @property def json(self):