Fix: the Chinese URI

This commit is contained in:
howie6879 2018-01-07 10:59:12 +08:00
parent 9426e94314
commit 42cd424274

View File

@ -7,7 +7,7 @@ from collections import deque, defaultdict
from functools import partial from functools import partial
from inspect import isawaitable, stack, getmodulename from inspect import isawaitable, stack, getmodulename
from traceback import format_exc from traceback import format_exc
from urllib.parse import urlencode, urlunparse from urllib.parse import quote, urlencode, urlunparse
from ssl import create_default_context, Purpose from ssl import create_default_context, Purpose
from sanic.config import Config from sanic.config import Config
@ -25,7 +25,6 @@ from sanic.websocket import WebSocketProtocol, ConnectionClosed
class Sanic: class Sanic:
def __init__(self, name=None, router=None, error_handler=None, def __init__(self, name=None, router=None, error_handler=None,
load_env=True, request_class=None, load_env=True, request_class=None,
strict_slashes=False, log_config=None, strict_slashes=False, log_config=None,
@ -111,9 +110,11 @@ class Sanic:
:param event: event to listen to :param event: event to listen to
""" """
def decorator(listener): def decorator(listener):
self.listeners[event].append(listener) self.listeners[event].append(listener)
return listener return listener
return decorator return decorator
# Decorator # Decorator
@ -135,7 +136,7 @@ class Sanic:
# and will probably get confused as to why it's not working # and will probably get confused as to why it's not working
if not uri.startswith('/'): if not uri.startswith('/'):
uri = '/' + uri uri = '/' + uri
uri = quote(uri)
if stream: if stream:
self.is_request_stream = True self.is_request_stream = True
@ -428,7 +429,7 @@ class Sanic:
uri, route = self.router.find_route_by_view_name(view_name, **kw) uri, route = self.router.find_route_by_view_name(view_name, **kw)
if not (uri and route): if not (uri and route):
raise URLBuildError('Endpoint with name `{}` was not found'.format( raise URLBuildError('Endpoint with name `{}` was not found'.format(
view_name)) view_name))
if view_name == 'static' or view_name.endswith('.static'): if view_name == 'static' or view_name.endswith('.static'):
filename = kwargs.pop('filename', None) filename = kwargs.pop('filename', None)