当前位置: 首页>>代码示例>>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;未经允许,请勿转载。