當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。