本文整理匯總了Python中twisted.web.http.stringToDatetime方法的典型用法代碼示例。如果您正苦於以下問題:Python http.stringToDatetime方法的具體用法?Python http.stringToDatetime怎麽用?Python http.stringToDatetime使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類twisted.web.http
的用法示例。
在下文中一共展示了http.stringToDatetime方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: testStringToDatetime
# 需要導入模塊: from twisted.web import http [as 別名]
# 或者: from twisted.web.http import stringToDatetime [as 別名]
def testStringToDatetime(self):
dateStrings = [
b"Sun, 06 Nov 1994 08:49:37 GMT",
b"06 Nov 1994 08:49:37 GMT",
b"Sunday, 06-Nov-94 08:49:37 GMT",
b"06-Nov-94 08:49:37 GMT",
b"Sunday, 06-Nov-1994 08:49:37 GMT",
b"06-Nov-1994 08:49:37 GMT",
b"Sun Nov 6 08:49:37 1994",
b"Nov 6 08:49:37 1994",
]
dateInt = calendar.timegm((1994, 11, 6, 8, 49, 37, 6, 6, 0))
for dateString in dateStrings:
self.assertEqual(http.stringToDatetime(dateString), dateInt)
self.assertEqual(
http.stringToDatetime(b"Thursday, 29-Sep-16 17:15:29 GMT"),
calendar.timegm((2016, 9, 29, 17, 15, 29, 3, 273, 0)))
示例2: _cache_period_from_headers
# 需要導入模塊: from twisted.web import http [as 別名]
# 或者: from twisted.web.http import stringToDatetime [as 別名]
def _cache_period_from_headers(headers, time_now=time.time):
cache_controls = _parse_cache_control(headers)
if b'no-store' in cache_controls:
return 0
if b'max-age' in cache_controls:
try:
max_age = int(cache_controls[b'max-age'])
return max_age
except ValueError:
pass
expires = headers.getRawHeaders(b'expires')
if expires is not None:
try:
expires_date = stringToDatetime(expires[-1])
return expires_date - time_now()
except ValueError:
# RFC7234 says 'A cache recipient MUST interpret invalid date formats,
# especially the value "0", as representing a time in the past (i.e.,
# "already expired").
return 0
return None
示例3: testRoundtrip
# 需要導入模塊: from twisted.web import http [as 別名]
# 或者: from twisted.web.http import stringToDatetime [as 別名]
def testRoundtrip(self):
for i in range(10000):
time = random.randint(0, 2000000000)
timestr = http.datetimeToString(time)
time2 = http.stringToDatetime(timestr)
self.assertEqual(time, time2)
示例4: retry_after
# 需要導入模塊: from twisted.web import http [as 別名]
# 或者: from twisted.web.http import stringToDatetime [as 別名]
def retry_after(cls, response, default=5, _now=time.time):
"""
Parse the Retry-After value from a response.
"""
val = response.headers.getRawHeaders(b'retry-after', [default])[0]
try:
return int(val)
except ValueError:
return http.stringToDatetime(val) - _now()
示例5: testRoundtrip
# 需要導入模塊: from twisted.web import http [as 別名]
# 或者: from twisted.web.http import stringToDatetime [as 別名]
def testRoundtrip(self):
for i in range(10000):
time = random.randint(0, 2000000000)
timestr = http.datetimeToString(time)
time2 = http.stringToDatetime(timestr)
self.assertEquals(time, time2)