当前位置: 首页>>代码示例>>Python>>正文


Python utils.mktime_tz方法代码示例

本文整理汇总了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 
开发者ID:quay,项目名称:quay,代码行数:22,代码来源:mirror.py

示例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 
开发者ID:mikf,项目名称:gallery-dl,代码行数:26,代码来源:util.py

示例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 
开发者ID:s3ql,项目名称:s3ql,代码行数:21,代码来源:s3c.py

示例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) 
开发者ID:appuio,项目名称:nagios-plugins-openshift,代码行数:17,代码来源:hawkular_client.py

示例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)) 
开发者ID:googlearchive,项目名称:billing-export-python,代码行数:17,代码来源:common.py

示例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))) 
开发者ID:XiaoMi,项目名称:galaxy-fds-sdk-python,代码行数:4,代码来源:utils.py

示例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 
开发者ID:wistbean,项目名称:learn_python3_spider,代码行数:8,代码来源:httpcache.py

示例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) 
开发者ID:wistbean,项目名称:learn_python3_spider,代码行数:16,代码来源:files.py

示例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) 
开发者ID:IronLanguages,项目名称:ironpython3,代码行数:7,代码来源:test_email.py

示例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 
开发者ID:wagtail,项目名称:wagtail,代码行数:33,代码来源:sendfile_streaming_backend.py

示例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 
开发者ID:ovh,项目名称:ip-reputation-monitoring,代码行数:12,代码来源:arf.py

示例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) 
开发者ID:ovh,项目名称:ip-reputation-monitoring,代码行数:9,代码来源:arf.py

示例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) 
开发者ID:ovh,项目名称:ip-reputation-monitoring,代码行数:9,代码来源:spamcop.py

示例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)) 
开发者ID:anybox,项目名称:anybox.recipe.odoo,代码行数:5,代码来源:base.py

示例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") 
开发者ID:amol-,项目名称:depot,代码行数:7,代码来源:middleware.py


注:本文中的email.utils.mktime_tz方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。