当前位置: 首页>>代码示例>>Python>>正文


Python http.stringToDatetime方法代码示例

本文整理汇总了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))) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:19,代码来源:test_http.py

示例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 
开发者ID:matrix-org,项目名称:sydent,代码行数:27,代码来源:matrixfederationagent.py

示例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) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:8,代码来源:test_http.py

示例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() 
开发者ID:twisted,项目名称:txacme,代码行数:11,代码来源:client.py

示例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) 
开发者ID:kuri65536,项目名称:python-for-android,代码行数:8,代码来源:test_http.py


注:本文中的twisted.web.http.stringToDatetime方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。