本文整理汇总了Python中werkzeug.http.parse_date方法的典型用法代码示例。如果您正苦于以下问题:Python http.parse_date方法的具体用法?Python http.parse_date怎么用?Python http.parse_date使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类werkzeug.http
的用法示例。
在下文中一共展示了http.parse_date方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: loads
# 需要导入模块: from werkzeug import http [as 别名]
# 或者: from werkzeug.http import parse_date [as 别名]
def loads(self, value):
def object_hook(obj):
if len(obj) != 1:
return obj
the_key, the_value = next(iteritems(obj))
if the_key == ' t':
return tuple(the_value)
elif the_key == ' u':
return uuid.UUID(the_value)
elif the_key == ' b':
return b64decode(the_value)
elif the_key == ' m':
return Markup(the_value)
elif the_key == ' d':
return parse_date(the_value)
return obj
return json.loads(value, object_hook=object_hook)
示例2: test_environ_property
# 需要导入模块: from werkzeug import http [as 别名]
# 或者: from werkzeug.http import parse_date [as 别名]
def test_environ_property(self):
class A(object):
environ = {'string': 'abc', 'number': '42'}
string = utils.environ_property('string')
missing = utils.environ_property('missing', 'spam')
read_only = utils.environ_property('number')
number = utils.environ_property('number', load_func=int)
broken_number = utils.environ_property('broken_number', load_func=int)
date = utils.environ_property('date', None, parse_date, http_date,
read_only=False)
foo = utils.environ_property('foo')
a = A()
self.assert_equal(a.string, 'abc')
self.assert_equal(a.missing, 'spam')
def test_assign():
a.read_only = 'something'
self.assert_raises(AttributeError, test_assign)
self.assert_equal(a.number, 42)
self.assert_equal(a.broken_number, None)
self.assert_is_none(a.date)
a.date = datetime(2008, 1, 22, 10, 0, 0, 0)
self.assert_equal(a.environ['date'], 'Tue, 22 Jan 2008 10:00:00 GMT')
示例3: _parse_datetime
# 需要导入模块: from werkzeug import http [as 别名]
# 或者: from werkzeug.http import parse_date [as 别名]
def _parse_datetime(value: str) -> datetime:
try:
return datetime.fromisoformat(value)
except ValueError:
return parse_date(value)
示例4: to_python
# 需要导入模块: from werkzeug import http [as 别名]
# 或者: from werkzeug.http import parse_date [as 别名]
def to_python(self, value):
return parse_date(value)
示例5: object_hook
# 需要导入模块: from werkzeug import http [as 别名]
# 或者: from werkzeug.http import parse_date [as 别名]
def object_hook(obj):
"""Checks to see if the `__type`-hinting field is available in the object being de-serialized. If present, and
the class referenced has a `from_json` function it will return the generated object, else a standard dic
will be returned
Args:
obj: Object to be deserialized
Returns:
Deserialized object or regular python objec
"""
try:
if '__type' in obj:
obj_type = obj['__type']
cls = getattr(cloud_inquisitor.schema, obj_type)
if hasattr(cls, 'from_json'):
return cls.from_json(obj)
key, value = next(iter(obj.items()))
if key == ' t':
return tuple(value)
elif key == ' u':
return uuid.UUID(value)
elif key == ' b':
return b64decode(value)
elif key == ' m':
return Markup(value)
elif key == ' d':
return parse_date(value)
return obj
except Exception:
log.exception('Error during data deserialization')
示例6: wait_retry_after_header
# 需要导入模块: from werkzeug import http [as 别名]
# 或者: from werkzeug.http import parse_date [as 别名]
def wait_retry_after_header(retry_state):
exc = retry_state.outcome.exception()
if exc is None or not getattr(exc, "response", None):
return 0
value = exc.response.headers.get("retry-after")
if value is None:
return 0
elif value.isdigit():
return int(value)
d = parse_date(value)
if d is None:
return 0
return max(0, (d - datetime.datetime.utcnow()).total_seconds())
示例7: test_session_expiration
# 需要导入模块: from werkzeug import http [as 别名]
# 或者: from werkzeug.http import parse_date [as 别名]
def test_session_expiration(self):
permanent = True
app = flask.Flask(__name__)
app.secret_key = 'testkey'
@app.route('/')
def index():
flask.session['test'] = 42
flask.session.permanent = permanent
return ''
@app.route('/test')
def test():
return text_type(flask.session.permanent)
client = app.test_client()
rv = client.get('/')
self.assert_in('set-cookie', rv.headers)
match = re.search(r'\bexpires=([^;]+)(?i)', rv.headers['set-cookie'])
expires = parse_date(match.group())
expected = datetime.utcnow() + app.permanent_session_lifetime
self.assert_equal(expires.year, expected.year)
self.assert_equal(expires.month, expected.month)
self.assert_equal(expires.day, expected.day)
rv = client.get('/test')
self.assert_equal(rv.data, b'True')
permanent = False
rv = app.test_client().get('/')
self.assert_in('set-cookie', rv.headers)
match = re.search(r'\bexpires=([^;]+)', rv.headers['set-cookie'])
self.assert_true(match is None)
示例8: loads
# 需要导入模块: from werkzeug import http [as 别名]
# 或者: from werkzeug.http import parse_date [as 别名]
def loads(self, value):
def object_hook(obj):
if len(obj) != 1:
return obj
the_key, the_value = next(iteritems(obj))
if the_key == ' t':
return tuple(the_value)
elif the_key == ' u':
return uuid.UUID(the_value)
elif the_key == ' m':
return Markup(the_value)
elif the_key == ' d':
return parse_date(the_value)
return obj
return json.loads(value, object_hook=object_hook)