Merge remote-tracking branch 'upstream/master'

This commit is contained in:
monobot 2017-04-02 00:02:49 +01:00
commit e148b50d6a
6 changed files with 56 additions and 36 deletions

View File

@ -59,6 +59,13 @@ Installation
- ``python -m pip install sanic`` - ``python -m pip install sanic``
To install sanic without uvloop or json using bash, you can provide either or both of these environmental variables
using any truthy string like `'y', 'yes', 't', 'true', 'on', '1'` and setting the NO_X to true will stop that features
installation.
- ``SANIC_NO_UVLOOP=true SANIC_NO_UJSON=true python -m pip install sanic``
Documentation Documentation
------------- -------------

View File

@ -5,7 +5,7 @@ both read and write cookies, which are stored as key-value pairs.
## Reading cookies ## Reading cookies
A user's cookies can be accessed `Request` object's `cookie` dictionary. A user's cookies can be accessed via the `Request` object's `cookies` dictionary.
```python ```python
from sanic.response import text from sanic.response import text
@ -42,20 +42,20 @@ from sanic.response import text
@app.route("/cookie") @app.route("/cookie")
async def test(request): async def test(request):
response = text("Time to eat some cookies muahaha") response = text("Time to eat some cookies muahaha")
# This cookie will be set to expire in 0 seconds # This cookie will be set to expire in 0 seconds
del response.cookies['kill_me'] del response.cookies['kill_me']
# This cookie will self destruct in 5 seconds # This cookie will self destruct in 5 seconds
response.cookies['short_life'] = 'Glad to be here' response.cookies['short_life'] = 'Glad to be here'
response.cookies['short_life']['max-age'] = 5 response.cookies['short_life']['max-age'] = 5
del response.cookies['favorite_color'] del response.cookies['favorite_color']
# This cookie will remain unchanged # This cookie will remain unchanged
response.cookies['favorite_color'] = 'blue' response.cookies['favorite_color'] = 'blue'
response.cookies['favorite_color'] = 'pink' response.cookies['favorite_color'] = 'pink'
del response.cookies['favorite_color'] del response.cookies['favorite_color']
return response return response
``` ```

View File

@ -1,4 +1,5 @@
import os import os
import types import types
SANIC_PREFIX = 'SANIC_' SANIC_PREFIX = 'SANIC_'

View File

@ -1,5 +1,6 @@
from mimetypes import guess_type from mimetypes import guess_type
from os import path from os import path
try: try:
from ujson import dumps as json_dumps from ujson import dumps as json_dumps
except: except:
@ -167,12 +168,12 @@ class StreamingHTTPResponse(BaseHTTPResponse):
return (b'HTTP/%b %d %b\r\n' return (b'HTTP/%b %d %b\r\n'
b'%b' b'%b'
b'%b\r\n') % ( b'%b\r\n') % (
version.encode(), version.encode(),
self.status, self.status,
status, status,
timeout_header, timeout_header,
headers headers
) )
class HTTPResponse(BaseHTTPResponse): class HTTPResponse(BaseHTTPResponse):
@ -216,14 +217,14 @@ class HTTPResponse(BaseHTTPResponse):
b'%b' b'%b'
b'%b\r\n' b'%b\r\n'
b'%b') % ( b'%b') % (
version.encode(), version.encode(),
self.status, self.status,
status, status,
b'keep-alive' if keep_alive else b'close', b'keep-alive' if keep_alive else b'close',
timeout_header, timeout_header,
headers, headers,
self.body self.body
) )
@property @property
def cookies(self): def cookies(self):

View File

@ -4,8 +4,10 @@ Sanic
import codecs import codecs
import os import os
import re import re
from setuptools import setup from distutils.errors import DistutilsPlatformError
from distutils.util import strtobool
from setuptools import setup
with codecs.open(os.path.join(os.path.abspath(os.path.dirname( with codecs.open(os.path.join(os.path.abspath(os.path.dirname(
__file__)), 'sanic', '__init__.py'), 'r', 'latin1') as fp: __file__)), 'sanic', '__init__.py'), 'r', 'latin1') as fp:
@ -15,7 +17,7 @@ with codecs.open(os.path.join(os.path.abspath(os.path.dirname(
except IndexError: except IndexError:
raise RuntimeError('Unable to determine version.') raise RuntimeError('Unable to determine version.')
setup_kwargs = { setup_kwargs = {
'name': 'sanic', 'name': 'sanic',
'version': version, 'version': version,
'url': 'http://github.com/channelcat/sanic/', 'url': 'http://github.com/channelcat/sanic/',
@ -35,23 +37,32 @@ setup_kwargs = {
], ],
} }
ujson = 'ujson>=1.35'
uvloop = 'uvloop>=0.5.3'
requirements = [
'httptools>=0.0.9',
uvloop,
ujson,
'aiofiles>=0.3.0',
'websockets>=3.2',
]
if strtobool(os.environ.get("SANIC_NO_UJSON", "no")):
print("Installing without uJSON")
requirements.remove(ujson)
if strtobool(os.environ.get("SANIC_NO_UVLOOP", "no")):
print("Installing without uvLoop")
requirements.remove(uvloop)
try: try:
normal_requirements = [ setup_kwargs['install_requires'] = requirements
'httptools>=0.0.9',
'uvloop>=0.5.3',
'ujson>=1.35',
'aiofiles>=0.3.0',
'websockets>=3.2',
]
setup_kwargs['install_requires'] = normal_requirements
setup(**setup_kwargs) setup(**setup_kwargs)
except DistutilsPlatformError as exception: except DistutilsPlatformError as exception:
windows_requirements = [ requirements.remove(ujson)
'httptools>=0.0.9', requirements.remove(uvloop)
'aiofiles>=0.3.0', print("Installing without uJSON or uvLoop")
'websockets>=3.2', setup_kwargs['install_requires'] = requirements
]
setup_kwargs['install_requires'] = windows_requirements
setup(**setup_kwargs) setup(**setup_kwargs)
# Installation was successful # Installation was successful

View File

@ -1,6 +1,6 @@
from sanic import Sanic from sanic import Sanic
from sanic.response import text
from sanic.exceptions import PayloadTooLarge from sanic.exceptions import PayloadTooLarge
from sanic.response import text
def test_payload_too_large_from_error_handler(): def test_payload_too_large_from_error_handler():