本文整理汇总了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')
示例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),)
示例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
示例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
示例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
示例6: HTTPDate
# 需要导入模块: import rfc822 [as 别名]
# 或者: from rfc822 import formatdate [as 别名]
def HTTPDate(timeval=None):
return formatdate(timeval, usegmt=True)
示例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