本文整理匯總了Python中werkzeug.http.http_date方法的典型用法代碼示例。如果您正苦於以下問題:Python http.http_date方法的具體用法?Python http.http_date怎麽用?Python http.http_date使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類werkzeug.http
的用法示例。
在下文中一共展示了http.http_date方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: default
# 需要導入模塊: from werkzeug import http [as 別名]
# 或者: from werkzeug.http import http_date [as 別名]
def default(self, o):
"""Implement this method in a subclass such that it returns a
serializable object for ``o``, or calls the base implementation (to
raise a :exc:`TypeError`).
For example, to support arbitrary iterators, you could implement
default like this::
def default(self, o):
try:
iterable = iter(o)
except TypeError:
pass
else:
return list(iterable)
return JSONEncoder.default(self, o)
"""
if isinstance(o, date):
return http_date(o.timetuple())
if isinstance(o, uuid.UUID):
return str(o)
if hasattr(o, '__html__'):
return text_type(o.__html__())
return _json.JSONEncoder.default(self, o)
示例2: _tag
# 需要導入模塊: from werkzeug import http [as 別名]
# 或者: from werkzeug.http import http_date [as 別名]
def _tag(value):
if isinstance(value, tuple):
return {' t': [_tag(x) for x in value]}
elif isinstance(value, uuid.UUID):
return {' u': value.hex}
elif isinstance(value, bytes):
return {' b': b64encode(value).decode('ascii')}
elif callable(getattr(value, '__html__', None)):
return {' m': text_type(value.__html__())}
elif isinstance(value, list):
return [_tag(x) for x in value]
elif isinstance(value, datetime):
return {' d': http_date(value)}
elif isinstance(value, dict):
return dict((k, _tag(v)) for k, v in iteritems(value))
elif isinstance(value, str):
try:
return text_type(value)
except UnicodeError:
from flask.debughelpers import UnexpectedUnicodeError
raise UnexpectedUnicodeError(u'A byte string with '
u'non-ASCII data was passed to the session system '
u'which can only store unicode strings. Consider '
u'base64 encoding your string (String was %r)' % value)
return value
示例3: sign_headers
# 需要導入模塊: from werkzeug import http [as 別名]
# 或者: from werkzeug.http import http_date [as 別名]
def sign_headers(u, headers):
"""
"""
key_id = u['publicKey']['@id']
secret = u['privateKey']
hs = HeaderSigner(key_id, secret, algorithm='rsa-sha256')
auth = hs.sign({"Date": http_date()})
# thanks to https://github.com/snarfed for the authorization -> signature headers hack
# this is necessary because httpsig.HeaderSigner returns an Authorization header instead of Signature
auth['Signature'] = auth.pop('authorization')
assert auth['Signature'].startswith('Signature ')
auth['Signature'] = auth['Signature'][len('Signature '):]
auth.update(headers)
auth.update(DEFAULT_HEADERS)
return auth
示例4: default
# 需要導入模塊: from werkzeug import http [as 別名]
# 或者: from werkzeug.http import http_date [as 別名]
def default(self, o):
"""Implement this method in a subclass such that it returns a
serializable object for ``o``, or calls the base implementation (to
raise a ``TypeError``).
For example, to support arbitrary iterators, you could implement
default like this::
def default(self, o):
try:
iterable = iter(o)
except TypeError:
pass
else:
return list(iterable)
return JSONEncoder.default(self, o)
"""
if isinstance(o, datetime):
return http_date(o)
if isinstance(o, uuid.UUID):
return str(o)
if hasattr(o, '__html__'):
return text_type(o.__html__())
return _json.JSONEncoder.default(self, o)
示例5: test_list_tokens
# 需要導入模塊: from werkzeug import http [as 別名]
# 或者: from werkzeug.http import http_date [as 別名]
def test_list_tokens(client, auth, test_admin):
uid, uname, upass = test_admin
# Log in first
response, csrf_cookie = auth.login(uname, upass)
response = client.get("/tokens/tokens", headers={"X-CSRF-Token": csrf_cookie})
assert 200 == response.status_code # Should get an OK
result = response.get_json()
assert [
{
"id": 1,
"name": "DUMMY_TOKEN",
"token": "DUMMY_TOKEN_STRING",
"expires": http_date(
(
datetime.datetime.now().date() + datetime.timedelta(days=1)
).timetuple()
),
"server_name": "DUMMY_SERVER_B",
"username": "TEST_ADMIN",
}
] == result
示例6: test_group_server_time_limits
# 需要導入模塊: from werkzeug import http [as 別名]
# 或者: from werkzeug.http import http_date [as 別名]
def test_group_server_time_limits(client, auth, test_admin, test_group):
uid, uname, upass = test_admin
response, csrf_cookie = auth.login(uname, upass)
response = client.get(
f"/admin/groups/{test_group.id}/servers/1/time_limits",
headers={"X-CSRF-Token": csrf_cookie},
)
assert 200 == response.status_code
json = response.get_json()
assert 2 == json["longest_token_life"]
assert (
http_date(
(datetime.datetime.now().date() + datetime.timedelta(days=365)).timetuple()
)
== json["latest_token_expiry"]
)
示例7: dumps
# 需要導入模塊: from werkzeug import http [as 別名]
# 或者: from werkzeug.http import http_date [as 別名]
def dumps(self, value):
def _tag(value):
if isinstance(value, tuple):
return {' t': [_tag(x) for x in value]}
elif isinstance(value, uuid.UUID):
return {' u': value.hex}
elif callable(getattr(value, '__html__', None)):
return {' m': text_type(value.__html__())}
elif isinstance(value, list):
return [_tag(x) for x in value]
elif isinstance(value, datetime):
return {' d': http_date(value)}
elif isinstance(value, dict):
return dict((k, _tag(v)) for k, v in iteritems(value))
elif isinstance(value, str):
try:
return text_type(value)
except UnicodeError:
raise UnexpectedUnicodeError(u'A byte string with '
u'non-ASCII data was passed to the session system '
u'which can only store unicode strings. Consider '
u'base64 encoding your string (String was %r)' % value)
return value
return json.dumps(_tag(value), separators=(',', ':'))
示例8: test_info
# 需要導入模塊: from werkzeug import http [as 別名]
# 或者: from werkzeug.http import http_date [as 別名]
def test_info(self):
resp = self.client.get("/user-info")
self.assertEqual(resp.json, {
"user": None,
})
# With logged in user
self.temporary_login(self.test_user_id)
resp = self.client.get("/user-info")
self.assertEqual(resp.json, {
"user": {
"id": self.test_user["id"],
"created": http_date(self.test_user["created"]),
"musicbrainz_id": self.test_user["musicbrainz_id"],
},
})