Removed unnecessary changes to request and router files, changes to fix lint test

This commit is contained in:
Andres Sanchez 2018-11-01 10:53:53 -06:00
parent ff0d5870e9
commit 056180782c
2 changed files with 15 additions and 22 deletions

View File

@ -1,11 +1,17 @@
import sys
import json import json
import sys
from cgi import parse_header from cgi import parse_header
from collections import namedtuple from collections import namedtuple
from http.cookies import SimpleCookie from http.cookies import SimpleCookie
from httptools import parse_url
from urllib.parse import parse_qs, urlunparse from urllib.parse import parse_qs, urlunparse
from httptools import parse_url
from sanic.exceptions import InvalidUsage
from sanic.log import error_logger, logger
try: try:
from ujson import loads as json_loads from ujson import loads as json_loads
except ImportError: except ImportError:
@ -18,8 +24,6 @@ except ImportError:
else: else:
json_loads = json.loads json_loads = json.loads
from sanic.exceptions import InvalidUsage
from sanic.log import error_logger, logger
DEFAULT_HTTP_CONTENT_TYPE = "application/octet-stream" DEFAULT_HTTP_CONTENT_TYPE = "application/octet-stream"
@ -67,7 +71,6 @@ class Request(dict):
"_port", "_port",
"__weakref__", "__weakref__",
"raw_url", "raw_url",
"_match_info",
) )
def __init__(self, url_bytes, headers, version, method, transport): def __init__(self, url_bytes, headers, version, method, transport):
@ -90,7 +93,6 @@ class Request(dict):
self.uri_template = None self.uri_template = None
self._cookies = None self._cookies = None
self.stream = None self.stream = None
self._match_info = None
def __repr__(self): def __repr__(self):
if self.method is None or not self.path: if self.method is None or not self.path:
@ -271,14 +273,8 @@ class Request(dict):
@property @property
def match_info(self): def match_info(self):
"""return matched info after resolving route""" """return matched info after resolving route"""
if self._match_info is not None:
return self._match_info
return self.app.router.get(self)[2] return self.app.router.get(self)[2]
@match_info.setter
def match_info(self, value):
self._match_info = value
@property @property
def path(self): def path(self):
return self._parsed_url.path.decode("utf-8") return self._parsed_url.path.decode("utf-8")

View File

@ -1,13 +1,15 @@
import re import re
import uuid import uuid
from collections import defaultdict, namedtuple from collections import defaultdict, namedtuple
from collections.abc import Iterable from collections.abc import Iterable
from functools import lru_cache from functools import lru_cache
from urllib.parse import unquote from urllib.parse import unquote
from sanic.exceptions import NotFound, MethodNotSupported from sanic.exceptions import MethodNotSupported, NotFound
from sanic.views import CompositionView from sanic.views import CompositionView
Route = namedtuple( Route = namedtuple(
"Route", ["handler", "methods", "pattern", "parameters", "name", "uri"] "Route", ["handler", "methods", "pattern", "parameters", "name", "uri"]
) )
@ -391,20 +393,15 @@ class Router:
""" """
# No virtual hosts specified; default behavior # No virtual hosts specified; default behavior
if not self.hosts: if not self.hosts:
processed = self._get(request.path, request.method, "") return self._get(request.path, request.method, "")
# virtual hosts specified; try to match route to the host header # virtual hosts specified; try to match route to the host header
try: try:
processed = self._get( return self._get(
request.path, request.method, request.headers.get("Host", "") request.path, request.method, request.headers.get("Host", "")
) )
# try default hosts # try default hosts
except NotFound: except NotFound:
processed = self._get(request.path, request.method, "") return self._get(request.path, request.method, "")
handler, args, kwargs, uri = processed
kwargs = kwargs if request._match_info is None else request._match_info
return handler, args, kwargs, uri
def get_supported_methods(self, url): def get_supported_methods(self, url):
"""Get a list of supported methods for a url and optional host. """Get a list of supported methods for a url and optional host.
@ -482,4 +479,4 @@ class Router:
handler.view_class, request.method.lower() handler.view_class, request.method.lower()
): ):
handler = getattr(handler.view_class, request.method.lower()) handler = getattr(handler.view_class, request.method.lower())
return hasattr(handler, "is_stream") return hasattr(handler, "is_stream")