From 056180782c97152b372f0dbaf970d932253bcaae Mon Sep 17 00:00:00 2001 From: Andres Sanchez Date: Thu, 1 Nov 2018 10:53:53 -0600 Subject: [PATCH] Removed unnecessary changes to request and router files, changes to fix lint test --- sanic/request.py | 20 ++++++++------------ sanic/router.py | 17 +++++++---------- 2 files changed, 15 insertions(+), 22 deletions(-) diff --git a/sanic/request.py b/sanic/request.py index 67c78b46..013a27ea 100644 --- a/sanic/request.py +++ b/sanic/request.py @@ -1,11 +1,17 @@ -import sys import json +import sys + from cgi import parse_header from collections import namedtuple from http.cookies import SimpleCookie -from httptools import parse_url 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: from ujson import loads as json_loads except ImportError: @@ -18,8 +24,6 @@ except ImportError: else: json_loads = json.loads -from sanic.exceptions import InvalidUsage -from sanic.log import error_logger, logger DEFAULT_HTTP_CONTENT_TYPE = "application/octet-stream" @@ -67,7 +71,6 @@ class Request(dict): "_port", "__weakref__", "raw_url", - "_match_info", ) def __init__(self, url_bytes, headers, version, method, transport): @@ -90,7 +93,6 @@ class Request(dict): self.uri_template = None self._cookies = None self.stream = None - self._match_info = None def __repr__(self): if self.method is None or not self.path: @@ -271,14 +273,8 @@ class Request(dict): @property def match_info(self): """return matched info after resolving route""" - if self._match_info is not None: - return self._match_info return self.app.router.get(self)[2] - @match_info.setter - def match_info(self, value): - self._match_info = value - @property def path(self): return self._parsed_url.path.decode("utf-8") diff --git a/sanic/router.py b/sanic/router.py index e538d65c..78a90346 100644 --- a/sanic/router.py +++ b/sanic/router.py @@ -1,13 +1,15 @@ import re import uuid + from collections import defaultdict, namedtuple from collections.abc import Iterable from functools import lru_cache from urllib.parse import unquote -from sanic.exceptions import NotFound, MethodNotSupported +from sanic.exceptions import MethodNotSupported, NotFound from sanic.views import CompositionView + Route = namedtuple( "Route", ["handler", "methods", "pattern", "parameters", "name", "uri"] ) @@ -391,20 +393,15 @@ class Router: """ # No virtual hosts specified; default behavior 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 try: - processed = self._get( + return self._get( request.path, request.method, request.headers.get("Host", "") ) # try default hosts except NotFound: - processed = 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 + return self._get(request.path, request.method, "") def get_supported_methods(self, url): """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 = getattr(handler.view_class, request.method.lower()) - return hasattr(handler, "is_stream") \ No newline at end of file + return hasattr(handler, "is_stream")