本文整理汇总了Python中email.utils.mktime_tz方法的典型用法代码示例。如果您正苦于以下问题:Python utils.mktime_tz方法的具体用法?Python utils.mktime_tz怎么用?Python utils.mktime_tz使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类email.utils
的用法示例。
在下文中一共展示了utils.mktime_tz方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _string_to_dt
# 需要导入模块: from email import utils [as 别名]
# 或者: from email.utils import mktime_tz [as 别名]
def _string_to_dt(self, string):
"""
Convert String to correct DateTime format.
"""
if string is None:
return None
"""
# TODO: Use RFC2822. This doesn't work consistently.
# TODO: Move this to same module as `format_date` once fixed.
tup = parsedate_tz(string)
if len(tup) == 8:
tup = tup + (0,) # If TimeZone is omitted, assume UTC
ts = mktime_tz(tup)
dt = datetime.fromtimestamp(ts, pytz.UTC)
return dt
"""
assert isinstance(string, str)
dt = datetime.strptime(string, "%Y-%m-%dT%H:%M:%SZ")
return dt
示例2: finalize
# 需要导入模块: from email import utils [as 别名]
# 或者: from email.utils import mktime_tz [as 别名]
def finalize(self):
"""Move tempfile to its target location"""
if self.delete:
self.delete = False
os.unlink(self.temppath)
return
if self.temppath != self.realpath:
# Move temp file to its actual location
try:
os.replace(self.temppath, self.realpath)
except OSError:
shutil.copyfile(self.temppath, self.realpath)
os.unlink(self.temppath)
mtime = self.kwdict.get("_mtime")
if mtime:
# Set file modification time
try:
if isinstance(mtime, str):
mtime = mktime_tz(parsedate_tz(mtime))
os.utime(self.realpath, (time.time(), mtime))
except Exception:
pass
示例3: _parse_retry_after
# 需要导入模块: from email import utils [as 别名]
# 或者: from email.utils import mktime_tz [as 别名]
def _parse_retry_after(header):
'''Parse headers for Retry-After value'''
hit = re.match(r'^\s*([0-9]+)\s*$', header)
if hit:
val = int(header)
else:
date = parsedate_tz(header)
if date is None:
log.warning('Unable to parse retry-after value: %s', header)
return None
val = mktime_tz(*date) - time.time()
val_clamp = min(300, max(1, val))
if val != val_clamp:
log.warning('Ignoring retry-after value of %.3f s, using %.3f s instead', val, val_clamp)
val = val_clamp
return val
示例4: from_request
# 需要导入模块: from email import utils [as 别名]
# 或者: from email.utils import mktime_tz [as 别名]
def from_request(cls, req):
if req.status_code == requests.codes.no_content:
data = None
else:
data = req.json()
raw_date = req.headers.get("Date", None)
if raw_date:
# See https://stackoverflow.com/a/26435566
timestamp = mktime_tz(parsedate_tz(raw_date))
else:
timestamp = None
return cls(data=data, server_time=timestamp)
示例5: http_time_to_posix
# 需要导入模块: from email import utils [as 别名]
# 或者: from email.utils import mktime_tz [as 别名]
def http_time_to_posix(http_time):
"""Convert HTTP time format to posix time.
See http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.3.1
for http time format.
Args:
http_time: time in RFC 2616 format. e.g.
"Mon, 20 Nov 1995 19:12:08 GMT".
Returns:
A float of secs from unix epoch.
"""
if http_time is not None:
return email_utils.mktime_tz(email_utils.parsedate_tz(http_time))
示例6: rfc822_timestamp
# 需要导入模块: from email import utils [as 别名]
# 或者: from email.utils import mktime_tz [as 别名]
def rfc822_timestamp(time_string):
return datetime.fromtimestamp(rfc822.mktime_tz(rfc822.parsedate_tz(time_string)))
示例7: rfc1123_to_epoch
# 需要导入模块: from email import utils [as 别名]
# 或者: from email.utils import mktime_tz [as 别名]
def rfc1123_to_epoch(date_str):
try:
date_str = to_unicode(date_str, encoding='ascii')
return mktime_tz(parsedate_tz(date_str))
except Exception:
return None
示例8: stat_file
# 需要导入模块: from email import utils [as 别名]
# 或者: from email.utils import mktime_tz [as 别名]
def stat_file(self, path, info):
def _onsuccess(boto_key):
if self.is_botocore:
checksum = boto_key['ETag'].strip('"')
last_modified = boto_key['LastModified']
modified_stamp = time.mktime(last_modified.timetuple())
else:
checksum = boto_key.etag.strip('"')
last_modified = boto_key.last_modified
modified_tuple = parsedate_tz(last_modified)
modified_stamp = int(mktime_tz(modified_tuple))
return {'checksum': checksum, 'last_modified': modified_stamp}
return self._get_boto_key(path).addCallback(_onsuccess)
示例9: test_mktime_tz
# 需要导入模块: from email import utils [as 别名]
# 或者: from email.utils import mktime_tz [as 别名]
def test_mktime_tz(self):
self.assertEqual(utils.mktime_tz((1970, 1, 1, 0, 0, 0,
-1, -1, -1, 0)), 0)
self.assertEqual(utils.mktime_tz((1970, 1, 1, 0, 0, 0,
-1, -1, -1, 1234)), -1234)
示例10: was_modified_since
# 需要导入模块: from email import utils [as 别名]
# 或者: from email.utils import mktime_tz [as 别名]
def was_modified_since(header=None, mtime=0, size=0):
"""
Was something modified since the user last downloaded it?
header
This is the value of the If-Modified-Since header. If this is None,
I'll just return True.
mtime
This is the modification time of the item we're talking about.
size
This is the size of the item we're talking about.
"""
try:
if header is None:
raise ValueError
matches = re.match(r"^([^;]+)(; length=([0-9]+))?$", header,
re.IGNORECASE)
header_date = parsedate_tz(matches.group(1))
if header_date is None:
raise ValueError
header_mtime = mktime_tz(header_date)
header_len = matches.group(3)
if header_len and int(header_len) != size:
raise ValueError
if mtime > header_mtime:
raise ValueError
except (AttributeError, ValueError, OverflowError):
return True
return False
示例11: compute_weight
# 需要导入模块: from email import utils [as 别名]
# 或者: from email.utils import mktime_tz [as 别名]
def compute_weight(self):
match = re.search(r'Received-Date:\s(.*)', self._data)
if not match:
return 1
# Check whether effective reception date is old or not (old = > 3d)
timestamp = mktime_tz(parsedate_tz(match.group(1)))
timestamp = timestamp + 3 * 24 * 60 * 60
return 0 if timestamp < time.time() else 1
示例12: get_date
# 需要导入模块: from email import utils [as 别名]
# 或者: from email.utils import mktime_tz [as 别名]
def get_date(self):
match = re.search(r'Date:\s(.*)', self._data)
if not match:
return datetime.now()
timestamp = mktime_tz(parsedate_tz(match.group(1)))
return datetime.utcfromtimestamp(timestamp)
示例13: get_date
# 需要导入模块: from email import utils [as 别名]
# 或者: from email.utils import mktime_tz [as 别名]
def get_date(self):
match = re.search(r'Date:\s(.*)', self._data)
if not match or not match.group(1):
return datetime.now()
timestamp = mktime_tz(parsedate_tz(match.group(1)))
return datetime.utcfromtimestamp(timestamp)
示例14: rfc822_time
# 需要导入模块: from email import utils [as 别名]
# 或者: from email.utils import mktime_tz [as 别名]
def rfc822_time(h):
"""Parse RFC 2822-formatted http header and return a time int."""
email_utils.mktime_tz(email_utils.parsedate_tz(h))
示例15: parse_date
# 需要导入模块: from email import utils [as 别名]
# 或者: from email.utils import mktime_tz [as 别名]
def parse_date(self, value):
try:
return datetime.utcfromtimestamp(mktime_tz(parsedate_tz(value)))
except (TypeError, OverflowError):
raise RuntimeError("Received an ill-formed timestamp")