當前位置: 首頁>>代碼示例>>Python>>正文


Python utils.parsedate_to_datetime方法代碼示例

本文整理匯總了Python中email.utils.parsedate_to_datetime方法的典型用法代碼示例。如果您正苦於以下問題:Python utils.parsedate_to_datetime方法的具體用法?Python utils.parsedate_to_datetime怎麽用?Python utils.parsedate_to_datetime使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在email.utils的用法示例。


在下文中一共展示了utils.parsedate_to_datetime方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: date

# 需要導入模塊: from email import utils [as 別名]
# 或者: from email.utils import parsedate_to_datetime [as 別名]
def date(self) -> Optional[datetime]:
        if "date" in self.headers:
            return parsedate_to_datetime(self.headers["date"])
        else:
            return None 
開發者ID:pgjones,項目名稱:quart,代碼行數:7,代碼來源:base.py

示例2: if_modified_since

# 需要導入模塊: from email import utils [as 別名]
# 或者: from email.utils import parsedate_to_datetime [as 別名]
def if_modified_since(self) -> Optional[datetime]:
        if "If-Modified-Since" in self.headers:
            return parsedate_to_datetime(self.headers["If-Modified-Since"])
        else:
            return None 
開發者ID:pgjones,項目名稱:quart,代碼行數:7,代碼來源:base.py

示例3: if_unmodified_since

# 需要導入模塊: from email import utils [as 別名]
# 或者: from email.utils import parsedate_to_datetime [as 別名]
def if_unmodified_since(self) -> Optional[datetime]:
        if "If-Unmodified-Since" in self.headers:
            return parsedate_to_datetime(self.headers["If-Unmodified-Since"])
        else:
            return None 
開發者ID:pgjones,項目名稱:quart,代碼行數:7,代碼來源:base.py

示例4: date

# 需要導入模塊: from email import utils [as 別名]
# 或者: from email.utils import parsedate_to_datetime [as 別名]
def date(self) -> Optional[datetime]:
        try:
            return parsedate_to_datetime(self.headers.get("Date", ""))
        except TypeError:  # Not a date format
            return None 
開發者ID:pgjones,項目名稱:quart,代碼行數:7,代碼來源:response.py

示例5: expires

# 需要導入模塊: from email import utils [as 別名]
# 或者: from email.utils import parsedate_to_datetime [as 別名]
def expires(self) -> Optional[datetime]:
        try:
            return parsedate_to_datetime(self.headers.get("Expires", ""))
        except TypeError:  # Not a date format
            return None 
開發者ID:pgjones,項目名稱:quart,代碼行數:7,代碼來源:response.py

示例6: retry_after

# 需要導入模塊: from email import utils [as 別名]
# 或者: from email.utils import parsedate_to_datetime [as 別名]
def retry_after(self) -> Optional[datetime]:
        value = self.headers.get("Retry-After", "")
        if value.isdigit():
            return datetime.utcnow() + timedelta(seconds=int(value))
        else:
            try:
                return parsedate_to_datetime(value)
            except TypeError:
                return None 
開發者ID:pgjones,項目名稱:quart,代碼行數:11,代碼來源:response.py

示例7: natural_last_modified

# 需要導入模塊: from email import utils [as 別名]
# 或者: from email.utils import parsedate_to_datetime [as 別名]
def natural_last_modified(self):
        last_modified = parsedate_to_datetime(self.last_modified)
        now = datetime.now(timezone.utc)
        tense = "from now" if last_modified > now else "ago"
        return "{0} {1}".format(humanize.naturaldelta(now - last_modified), tense) 
開發者ID:buckket,項目名稱:twtxt,代碼行數:7,代碼來源:twhttp.py

示例8: parse

# 需要導入模塊: from email import utils [as 別名]
# 或者: from email.utils import parsedate_to_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

示例9: test_parsedate_to_datetime

# 需要導入模塊: from email import utils [as 別名]
# 或者: from email.utils import parsedate_to_datetime [as 別名]
def test_parsedate_to_datetime(self):
        self.assertEqual(
            utils.parsedate_to_datetime(self.datestring + self.offsetstring),
            self.aware_dt) 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:6,代碼來源:test_utils.py

示例10: test_parsedate_to_datetime_naive

# 需要導入模塊: from email import utils [as 別名]
# 或者: from email.utils import parsedate_to_datetime [as 別名]
def test_parsedate_to_datetime_naive(self):
        self.assertEqual(
            utils.parsedate_to_datetime(self.datestring + ' -0000'),
            self.naive_dt) 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:6,代碼來源:test_utils.py

示例11: download_list

# 需要導入模塊: from email import utils [as 別名]
# 或者: from email.utils import parsedate_to_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

示例12: processMessages

# 需要導入模塊: from email import utils [as 別名]
# 或者: from email.utils import parsedate_to_datetime [as 別名]
def processMessages(self, msgs):
        log = []
        for msg in msgs:
            CCemail = None
            to_email = None
            header_data = msg["payload"]["headers"]
            for data in header_data:
                if "To" == data["name"]:
                    to_email = data["value"]
                    if '<' in to_email:
                        start = to_email.find('<')
                        end = to_email.find('>')
                        to_email = to_email[start + 1: end]
                if "From" == data["name"]:
                    email_id = data["value"]
                    if '<' in email_id:
                        start = email_id.find('<')
                        end = email_id.find('>')
                        email_id = email_id[start + 1: end]
                if "Received" == data["name"]:
                    timestamp = parsedate_to_datetime(data["value"].split(';', 1)[-1]).astimezone(
                        pytz.timezone("Asia/Calcutta"))
                if "Cc" == data["name"]:
                    CCemail = data["value"]
                    if '<' in CCemail:
                        start = CCemail.find('<')
                        end = CCemail.find('>')
                        CCemail = CCemail[start + 1: end]
            MsgB64 = ""
            try:
                if "parts" in msg["payload"]:
                    MsgB64 = msg["payload"]['parts'][0]['body']['data'].replace("-", "+").replace("_", "/")
                else:
                    MsgB64 = msg["payload"]['body']['data'].replace("-", "+").replace("_", "/")
            except Exception as e:
                errorObj = Errors.objects.create(module='status', errorContent=e, timestamp=datetime.now())
                errorObj.save()

            Msg = base64.b64decode(bytes(MsgB64, 'UTF-8')).decode('UTF-8')
            Msg = "<br />".join(Msg.split("\r\n"))
            Msg = Msg.split("wrote:<br /><br />>")[0]
            Msg = Msg.rsplit("On ", 1)[0]
            Msg = Msg.split("-- <br />You received this message")[0]

            log.append({
                "CCemail": CCemail,
                "to": to_email,
                'email': email_id,
                'date': self.date,
                'timestamp': timestamp.isoformat(),
                'message': Msg
            })

        return log 
開發者ID:amfoss,項目名稱:cms,代碼行數:56,代碼來源:fetcher.py


注:本文中的email.utils.parsedate_to_datetime方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。