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


Python utils.format_datetime方法代码示例

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


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

示例1: __call__

# 需要导入模块: from email import utils [as 别名]
# 或者: from email.utils import format_datetime [as 别名]
def __call__(self, request):
        # We have to format the date according to RFC 2616
        # https://tools.ietf.org/html/rfc2616#section-14.18

        now = datetime.now(timezone.utc)
        date = format_datetime(now, True)

        try:
            # Attempt to decode request.body (assume bytes received)
            msg = '\n'.join([self.serial.lower(), date, request.body.decode('utf8')])
        except AttributeError:
            # Decode failed, assume request.body is already type str
            msg = '\n'.join([self.serial.lower(), date, request.body])

        signing = hmac.new(key=self.secret.encode('utf8'),
                           msg=msg.encode('utf8'),
                           digestmod=hashlib.sha256)

        request.headers['Date'] = date
        request.headers['Authorization'] = "NEATOAPP " + signing.hexdigest()

        return request 
开发者ID:stianaske,项目名称:pybotvac,代码行数:24,代码来源:robot.py

示例2: render_js

# 需要导入模块: from email import utils [as 别名]
# 或者: from email.utils import format_datetime [as 别名]
def render_js(request, template_name, cache=True, *args, **kwargs):
    response = render(request, template_name, *args, **kwargs)
    response["Content-Type"] = \
        "application/javascript; charset=UTF-8"
    if cache:
        now = datetime.now(timezone.utc)
        response["Last-Modified"] = format_datetime(now,
                                                    usegmt=True)

        # cache in the browser for 1 month
        expires = now + timedelta(days=31)
        response["Expires"] = format_datetime(expires,
                                              usegmt=True)
    else:
        response["Pragma"] = "No-Cache"
    return response 
开发者ID:PacktPublishing,项目名称:Django-2-Web-Development-Cookbook-Third-Edition,代码行数:18,代码来源:views.py

示例3: parse

# 需要导入模块: from email import utils [as 别名]
# 或者: from email.utils import format_datetime [as 别名]
def parse(cls, value, kwds):
        if not value:
            kwds['defects'].append(errors.HeaderMissingRequiredValue())
            kwds['datetime'] = None
            kwds['decoded'] = ''
            kwds['parse_tree'] = parser.TokenList()
            return
        if isinstance(value, str):
            value = utils.parsedate_to_datetime(value)
        kwds['datetime'] = value
        kwds['decoded'] = utils.format_datetime(kwds['datetime'])
        kwds['parse_tree'] = cls.value_parser(kwds['decoded']) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:14,代码来源:headerregistry.py

示例4: test_naive_datetime

# 需要导入模块: from email import utils [as 别名]
# 或者: from email.utils import format_datetime [as 别名]
def test_naive_datetime(self):
        self.assertEqual(utils.format_datetime(self.naive_dt),
                         self.datestring + ' -0000') 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:5,代码来源:test_utils.py

示例5: test_aware_datetime

# 需要导入模块: from email import utils [as 别名]
# 或者: from email.utils import format_datetime [as 别名]
def test_aware_datetime(self):
        self.assertEqual(utils.format_datetime(self.aware_dt),
                         self.datestring + self.offsetstring) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:5,代码来源:test_utils.py

示例6: test_usegmt

# 需要导入模块: from email import utils [as 别名]
# 或者: from email.utils import format_datetime [as 别名]
def test_usegmt(self):
        utc_dt = datetime.datetime(*self.dateargs,
                                   tzinfo=datetime.timezone.utc)
        self.assertEqual(utils.format_datetime(utc_dt, usegmt=True),
                         self.datestring + ' GMT') 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:7,代码来源:test_utils.py

示例7: test_usegmt_with_naive_datetime_raises

# 需要导入模块: from email import utils [as 别名]
# 或者: from email.utils import format_datetime [as 别名]
def test_usegmt_with_naive_datetime_raises(self):
        with self.assertRaises(ValueError):
            utils.format_datetime(self.naive_dt, usegmt=True) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:5,代码来源:test_utils.py

示例8: download_list

# 需要导入模块: from email import utils [as 别名]
# 或者: from email.utils import format_datetime [as 别名]
def download_list(url):
    headers = None

    cache = Path(config['cache'], hashlib.sha1(url.encode()).hexdigest())

    if cache.is_file():
        last_modified = datetime.utcfromtimestamp(cache.stat().st_mtime)
        headers = {
                'If-modified-since': eut.format_datetime(last_modified),
                'User-Agent': 'Bind adblock zonfile updater v1.0 (https://github.com/Trellmor/bind-adblock)'
                }

    try:
        r = requests.get(url, headers=headers, timeout=config['req_timeout_s'])

        if r.status_code == 200:
            with cache.open('w', encoding='utf8') as f:
                f.write(r.text)
            if 'last-modified' in r.headers:
                last_modified = eut.parsedate_to_datetime(r.headers['last-modified']).timestamp()
                os.utime(str(cache), times=(last_modified, last_modified))

            return r.text
    except requests.exceptions.RequestException as e:
        print(e)

    if cache.is_file():
        with cache.open('r', encoding='utf8') as f:
            return f.read() 
开发者ID:Trellmor,项目名称:bind-adblock,代码行数:31,代码来源:update-zonefile.py


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