當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。