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 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")

View File

@ -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.