當前位置: 首頁>>代碼示例>>Python>>正文


Python rfc822.formatdate方法代碼示例

本文整理匯總了Python中rfc822.formatdate方法的典型用法代碼示例。如果您正苦於以下問題:Python rfc822.formatdate方法的具體用法?Python rfc822.formatdate怎麽用?Python rfc822.formatdate使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在rfc822的用法示例。


在下文中一共展示了rfc822.formatdate方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: open_local_file

# 需要導入模塊: import rfc822 [as 別名]
# 或者: from rfc822 import formatdate [as 別名]
def open_local_file(self, req):
        host = req.get_host()
        file = req.get_selector()
        localfile = url2pathname(file)
        stats = os.stat(localfile)
        size = stats[stat.ST_SIZE]
        modified = rfc822.formatdate(stats[stat.ST_MTIME])
        mtype = mimetypes.guess_type(file)[0]
        stats = os.stat(localfile)
        headers = mimetools.Message(StringIO(
            'Content-Type: %s\nContent-Length: %d\nLast-modified: %s\n' %
            (mtype or 'text/plain', size, modified)))
        if host:
            host, port = splitport(host)
        if not host or \
           (not port and socket.gethostbyname(host) in self.get_names()):
            return addinfourl(open(localfile, 'rb'),
                              headers, 'file:'+file)
        raise URLError('file not on local host') 
開發者ID:war-and-code,項目名稱:jawfish,代碼行數:21,代碼來源:urllib2.py

示例2: compose

# 需要導入模塊: import rfc822 [as 別名]
# 或者: from rfc822 import formatdate [as 別名]
def compose(self, time=None, delta=None):
        time = time or now()
        if delta:
            assert type(delta) == int
            time += delta
        return (formatdate(time),) 
開發者ID:linuxscout,項目名稱:mishkal,代碼行數:8,代碼來源:httpheaders.py

示例3: __set_headers

# 需要導入模塊: import rfc822 [as 別名]
# 或者: from rfc822 import formatdate [as 別名]
def __set_headers(self):
    headers = dict()
    headers[configs.CONTENT_TYPE] = "application/json; charset=UTF-8"
    headers[configs.DATE] = rfc822.formatdate(time.time())
    headers[configs.REQUEST_ID] = utils.request_id()
    headers[configs.CONTENT_MD5] = ""
    return headers 
開發者ID:XiaoMi,項目名稱:galaxy-sdk-python,代碼行數:9,代碼來源:visionclient.py

示例4: __set_headers

# 需要導入模塊: import rfc822 [as 別名]
# 或者: from rfc822 import formatdate [as 別名]
def __set_headers(self, body):
    headers = dict()
    headers[HK_HOST] = self.host
    headers['content-length'] = str(len(body))
    headers[HK_TIMESTAMP] = str(int(time.time() + self.__clock_offset))
    headers[HK_CONTENT_MD5] = hashlib.md5(body).hexdigest()
    headers['content-type'] = THRIFT_HEADER_MAP[self.__protocol]
    headers[MI_DATE] = rfc822.formatdate(time.time())
    return headers 
開發者ID:XiaoMi,項目名稱:galaxy-sdk-python,代碼行數:11,代碼來源:sdsthttpclient.py

示例5: __set_headers

# 需要導入模塊: import rfc822 [as 別名]
# 或者: from rfc822 import formatdate [as 別名]
def __set_headers(self, body):
    headers = dict()
    headers[HOST] = self.host
    headers[CONTENT_LENGTH] = str(len(body))
    headers[TIMESTAMP] = str(int(time.time() + self.__clock_offset))
    headers[CONTENT_MD5] = hashlib.md5(body).hexdigest()
    headers[CONTENT_TYPE] = THRIFT_HEADER_MAP[self.__protocol]
    headers[MI_DATE] = rfc822.formatdate(time.time())
    return headers 
開發者ID:XiaoMi,項目名稱:galaxy-sdk-python,代碼行數:11,代碼來源:thttpclient.py

示例6: HTTPDate

# 需要導入模塊: import rfc822 [as 別名]
# 或者: from rfc822 import formatdate [as 別名]
def HTTPDate(timeval=None):
        return formatdate(timeval, usegmt=True) 
開發者ID:naparuba,項目名稱:opsbro,代碼行數:4,代碼來源:_cpcompat.py

示例7: open_local_file

# 需要導入模塊: import rfc822 [as 別名]
# 或者: from rfc822 import formatdate [as 別名]
def open_local_file(self, req):
        import mimetypes
        import mimetools
        host = req.get_host()
        file = req.get_selector()
        localfile = urllib.url2pathname(file)
        stats = os.stat(localfile)
        size = stats[stat.ST_SIZE]
        modified = rfc822.formatdate(stats[stat.ST_MTIME])
        mtype = mimetypes.guess_type(file)[0]
        if host:
            host, port = urllib.splitport(host)
            if port or socket.gethostbyname(host) not in self.get_names():
                raise urllib2.URLError('file not on local host')
        fo = open(localfile,'rb')
        brange = req.headers.get('Range',None)
        brange = range_header_to_tuple(brange)
        assert brange != ()
        if brange:
            (fb,lb) = brange
            if lb == '': lb = size
            if fb < 0 or fb > size or lb > size:
                raise RangeError(9, 'Requested Range Not Satisfiable')
            size = (lb - fb)
            fo = RangeableFileObject(fo, (fb,lb))
        headers = mimetools.Message(StringIO(
            'Content-Type: %s\nContent-Length: %d\nLast-modified: %s\n' %
            (mtype or 'text/plain', size, modified)))
        return urllib.addinfourl(fo, headers, 'file:'+file)


# FTP Range Support 
# Unfortunately, a large amount of base FTP code had to be copied
# from urllib and urllib2 in order to insert the FTP REST command.
# Code modifications for range support have been commented as 
# follows:
# -- range support modifications start/end here 
開發者ID:yandex,項目名稱:root-2015-tasks,代碼行數:39,代碼來源:byterange.py


注:本文中的rfc822.formatdate方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。