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


Python utils.parsedate方法代码示例

本文整理汇总了Python中email.utils.parsedate方法的典型用法代码示例。如果您正苦于以下问题:Python utils.parsedate方法的具体用法?Python utils.parsedate怎么用?Python utils.parsedate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在email.utils的用法示例。


在下文中一共展示了utils.parsedate方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: update_headers

# 需要导入模块: from email import utils [as 别名]
# 或者: from email.utils import parsedate [as 别名]
def update_headers(self, response):
        headers = {}

        if 'expires' not in response.headers:
            date = parsedate(response.headers['date'])
            expires = expire_after(timedelta(days=1),
                                   date=datetime(*date[:6]))
            headers['expires'] = datetime_to_header(expires)
            headers['cache-control'] = 'public'
        return headers 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:12,代码来源:heuristics.py

示例2: serve_static

# 需要导入模块: from email import utils [as 别名]
# 或者: from email.utils import parsedate [as 别名]
def serve_static(self, path):
        try:
            generation = self._cache.get_generation(path)
            if not generation:
                self.send_error(404, "File not found")
                return

            if_modified_since = self.headers.get("If-Modified-Since")
            if if_modified_since:
                since = email_utils.parsedate(if_modified_since)
                if since >= time.gmtime(old_div(int(generation),1e6)):
                    self.send_response(304)
                    self.send_header("Content-Length", 0)
                    self.end_headers()
                    return

            # File is not modified.
            requested_generation = self.headers.get("If-None-Match")
            if requested_generation == generation:
                self.send_response(304)
                self.send_header("Content-Length", 0)
                self.end_headers()
                return

            local_path = self._cache.get_local_file(path, generation)
            with open(local_path) as fd:
                self.send_response(200)
                fs = os.fstat(fd.fileno())
                self.send_header("ETag", '"%s"' % generation)
                self.send_header("Content-Length", str(fs[6]))
                self.end_headers()

                while True:
                    data = fd.read(self.READ_BLOCK_SIZE)
                    if not data:
                        break

                    self.wfile.write(data)
        except (IOError, AttributeError):
            self.send_error(500, close=True) 
开发者ID:google,项目名称:rekall,代码行数:42,代码来源:http_server.py

示例3: test_formatdate

# 需要导入模块: from email import utils [as 别名]
# 或者: from email.utils import parsedate [as 别名]
def test_formatdate(self):
        now = time.time()
        self.assertEqual(utils.parsedate(utils.formatdate(now))[:6],
                         time.gmtime(now)[:6]) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:6,代码来源:test_email_renamed.py

示例4: test_formatdate_localtime

# 需要导入模块: from email import utils [as 别名]
# 或者: from email.utils import parsedate [as 别名]
def test_formatdate_localtime(self):
        now = time.time()
        self.assertEqual(
            utils.parsedate(utils.formatdate(now, localtime=True))[:6],
            time.localtime(now)[:6]) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:7,代码来源:test_email_renamed.py

示例5: test_parsedate_none

# 需要导入模块: from email import utils [as 别名]
# 或者: from email.utils import parsedate [as 别名]
def test_parsedate_none(self):
        self.assertEqual(utils.parsedate(''), None) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:4,代码来源:test_email_renamed.py

示例6: test_parsedate_compact

# 需要导入模块: from email import utils [as 别名]
# 或者: from email.utils import parsedate [as 别名]
def test_parsedate_compact(self):
        # The FWS after the comma is optional
        self.assertEqual(utils.parsedate('Wed,3 Apr 2002 14:58:26 +0800'),
                         utils.parsedate('Wed, 3 Apr 2002 14:58:26 +0800')) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:6,代码来源:test_email_renamed.py

示例7: test_parsedate_acceptable_to_time_functions

# 需要导入模块: from email import utils [as 别名]
# 或者: from email.utils import parsedate [as 别名]
def test_parsedate_acceptable_to_time_functions(self):
        eq = self.assertEqual
        timetup = utils.parsedate('5 Feb 2003 13:47:26 -0800')
        t = int(time.mktime(timetup))
        eq(time.localtime(t)[:6], timetup[:6])
        eq(int(time.strftime('%Y', timetup)), 2003)
        timetup = utils.parsedate_tz('5 Feb 2003 13:47:26 -0800')
        t = int(time.mktime(timetup[:9]))
        eq(time.localtime(t)[:6], timetup[:6])
        eq(int(time.strftime('%Y', timetup[:9])), 2003) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:12,代码来源:test_email_renamed.py

示例8: parse_datetime

# 需要导入模块: from email import utils [as 别名]
# 或者: from email.utils import parsedate [as 别名]
def parse_datetime(string):
    return datetime(*(parsedate(string)[:6])) 
开发者ID:singhj,项目名称:locality-sensitive-hashing,代码行数:4,代码来源:utils.py

示例9: parse_rfc2822_date

# 需要导入模块: from email import utils [as 别名]
# 或者: from email.utils import parsedate [as 别名]
def parse_rfc2822_date(s):
    """
    Parses an RFC 2822 date string and returns a time zone naive datetime
    object. All dates returned from Twilio are UTC.
    """
    date_tuple = parsedate(s)
    if date_tuple is None:
        return None
    return datetime.datetime(*date_tuple[:6]) 
开发者ID:skarlekar,项目名称:faces,代码行数:11,代码来源:util.py

示例10: updatePSL

# 需要导入模块: from email import utils [as 别名]
# 或者: from email.utils import parsedate [as 别名]
def updatePSL(psl_file=PSLFILE):
    """ Updates a local copy of PSL file

    :param psl_file: path for the file to store the list. Default: PSLFILE
    """
    if requests is None:
        raise Exception("Please install python-requests http(s) library. $ sudo pip install requests")

    r = requests.get(PSLURL)
    if r.status_code != requests.codes.ok or len(r.content) == 0:
        raise Exception("Could not download PSL from " + PSLURL)

    lastmod = r.headers.get("last-modified", None)
    with open(psl_file + ".swp", "wb") as f:
        f.write(r.content)

    with open(psl_file + ".swp", "rb") as f:
        psl = PublicSuffixList(f)

    os.rename(psl_file + ".swp", psl_file)
    if lastmod:
        t = calendar.timegm(parsedate(lastmod))
        os.utime(psl_file, (t, t))

    print("PSL updated")
    if lastmod:
        print("last-modified: " + lastmod) 
开发者ID:ko-zu,项目名称:psl,代码行数:29,代码来源:update.py

示例11: created_at_in_seconds

# 需要导入模块: from email import utils [as 别名]
# 或者: from email.utils import parsedate [as 别名]
def created_at_in_seconds(self):
        """ Get the time this status message was posted, in seconds since
        the epoch (1 Jan 1970).

        Returns:
            int: The time this status message was posted, in seconds since
            the epoch.
        """
        return timegm(parsedate(self.created_at)) 
开发者ID:doncat99,项目名称:StockRecommendSystem,代码行数:11,代码来源:models.py

示例12: parse_datetime

# 需要导入模块: from email import utils [as 别名]
# 或者: from email.utils import parsedate [as 别名]
def parse_datetime(string):
    if settings.USE_TZ:
        return datetime(*(parsedate(string)[:6]), tzinfo=current_timezone)
    else:
        return datetime(*(parsedate(string)[:6])) 
开发者ID:michaelbrooks,项目名称:django-twitter-stream,代码行数:7,代码来源:models.py


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