passed flake8
This commit is contained in:
parent
2ed246518c
commit
4260b115e2
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -15,3 +15,4 @@ docs/_build/
|
||||||
docs/_api/
|
docs/_api/
|
||||||
build/*
|
build/*
|
||||||
.DS_Store
|
.DS_Store
|
||||||
|
.vscode
|
|
@ -26,6 +26,7 @@ from sanic.websocket import WebSocketProtocol, ConnectionClosed
|
||||||
|
|
||||||
session_interface = SecureCookieSessionInterface()
|
session_interface = SecureCookieSessionInterface()
|
||||||
|
|
||||||
|
|
||||||
class Sanic:
|
class Sanic:
|
||||||
|
|
||||||
def __init__(self, name=None, router=None, error_handler=None,
|
def __init__(self, name=None, router=None, error_handler=None,
|
||||||
|
|
|
@ -3,10 +3,12 @@
|
||||||
import hashlib
|
import hashlib
|
||||||
|
|
||||||
from itsdangerous import URLSafeTimedSerializer
|
from itsdangerous import URLSafeTimedSerializer
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
import ujson as json
|
import ujson as json
|
||||||
from sanic.exceptions import BadSignature
|
from sanic.exceptions import BadSignature
|
||||||
|
|
||||||
|
|
||||||
def total_seconds(td):
|
def total_seconds(td):
|
||||||
"""Returns the total seconds from a timedelta object.
|
"""Returns the total seconds from a timedelta object.
|
||||||
:param timedelta td: the timedelta to be converted in seconds
|
:param timedelta td: the timedelta to be converted in seconds
|
||||||
|
@ -15,6 +17,7 @@ def total_seconds(td):
|
||||||
"""
|
"""
|
||||||
return td.days * 60 * 60 * 24 + td.seconds
|
return td.days * 60 * 60 * 24 + td.seconds
|
||||||
|
|
||||||
|
|
||||||
class SessionMixin(object):
|
class SessionMixin(object):
|
||||||
"""Expands a basic dictionary with an accessors that are expected
|
"""Expands a basic dictionary with an accessors that are expected
|
||||||
by Flask extensions and users for the session.
|
by Flask extensions and users for the session.
|
||||||
|
@ -146,27 +149,12 @@ class SessionInterface(object):
|
||||||
# Chrome doesn't allow names without a '.'
|
# Chrome doesn't allow names without a '.'
|
||||||
# this should only come up with localhost
|
# this should only come up with localhost
|
||||||
# hack around this by not setting the name, and show a warning
|
# hack around this by not setting the name, and show a warning
|
||||||
warnings.warn(
|
|
||||||
'"{rv}" is not a valid cookie domain, it must contain a ".".'
|
|
||||||
' Add an entry to your hosts file, for example'
|
|
||||||
' "{rv}.localdomain", and use that instead.'.format(rv=rv)
|
|
||||||
)
|
|
||||||
app.config['SESSION_COOKIE_DOMAIN'] = False
|
app.config['SESSION_COOKIE_DOMAIN'] = False
|
||||||
return None
|
return None
|
||||||
|
|
||||||
# ip = is_ip(rv)
|
|
||||||
|
|
||||||
# if ip:
|
|
||||||
# warnings.warn(
|
|
||||||
# 'The session cookie domain is an IP address. This may not work'
|
|
||||||
# ' as intended in some browsers. Add an entry to your hosts'
|
|
||||||
# ' file, for example "localhost.localdomain", and use that'
|
|
||||||
# ' instead.'
|
|
||||||
# )
|
|
||||||
|
|
||||||
# if this is not an ip and app is mounted at the root, allow subdomain
|
# if this is not an ip and app is mounted at the root, allow subdomain
|
||||||
# matching by adding a '.' prefix
|
# matching by adding a '.' prefix
|
||||||
if self.get_cookie_path(app) == '/' and not ip:
|
if self.get_cookie_path(app) == '/':
|
||||||
rv = '.' + rv
|
rv = '.' + rv
|
||||||
|
|
||||||
app.config['SESSION_COOKIE_DOMAIN'] = rv
|
app.config['SESSION_COOKIE_DOMAIN'] = rv
|
||||||
|
@ -214,7 +202,8 @@ class SessionInterface(object):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
return session.modified or (
|
return session.modified or (
|
||||||
session.permanent and app.config.get('SESSION_REFRESH_EACH_REQUEST', False)
|
session.permanent and app.config.get(
|
||||||
|
'SESSION_REFRESH_EACH_REQUEST', False)
|
||||||
)
|
)
|
||||||
|
|
||||||
def open_session(self, app, request):
|
def open_session(self, app, request):
|
||||||
|
@ -303,10 +292,12 @@ class SecureCookieSessionInterface(SessionInterface):
|
||||||
secure = self.get_cookie_secure(app)
|
secure = self.get_cookie_secure(app)
|
||||||
expires = self.get_expiration_time(app, session)
|
expires = self.get_expiration_time(app, session)
|
||||||
val = self.get_signing_serializer(app).dumps(dict(session))
|
val = self.get_signing_serializer(app).dumps(dict(session))
|
||||||
|
session_cookie_name = app.config.SESSION_COOKIE_NAME
|
||||||
response.cookies[app.config.SESSION_COOKIE_NAME] = val
|
response.cookies[session_cookie_name] = val
|
||||||
# response.cookies[app.config.SESSION_COOKIE_NAME]["expires"] = expires
|
if expires:
|
||||||
# response.cookies[app.config.SESSION_COOKIE_NAME]["httponly"] = httponly
|
response.cookies[session_cookie_name]["expires"] = expires
|
||||||
# response.cookies[app.config.SESSION_COOKIE_NAME]["domain"] = domain
|
response.cookies[session_cookie_name]["httponly"] = httponly
|
||||||
# response.cookies[app.config.SESSION_COOKIE_NAME]["path"] = path
|
if domain:
|
||||||
# response.cookies[app.config.SESSION_COOKIE_NAME]["secure"] = secure
|
response.cookies[session_cookie_name]["domain"] = domain
|
||||||
|
response.cookies[session_cookie_name]["path"] = path
|
||||||
|
response.cookies[session_cookie_name]["secure"] = secure
|
||||||
|
|
Loading…
Reference in New Issue
Block a user