Python email.utils.parsedate_to_datetime() Examples
The following are 24
code examples of email.utils.parsedate_to_datetime().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
email.utils
, or try the search function
.
Example #1
Source File: headerregistry.py From ironpython3 with Apache License 2.0 | 5 votes |
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'])
Example #2
Source File: test_utils.py From android_universal with MIT License | 5 votes |
def test_parsedate_to_datetime_naive(self): self.assertEqual( utils.parsedate_to_datetime(self.datestring + ' -0000'), self.naive_dt)
Example #3
Source File: test_utils.py From android_universal with MIT License | 5 votes |
def test_parsedate_to_datetime(self): self.assertEqual( utils.parsedate_to_datetime(self.datestring + self.offsetstring), self.aware_dt)
Example #4
Source File: headerregistry.py From android_universal with MIT License | 5 votes |
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'])
Example #5
Source File: headerregistry.py From Carnets with BSD 3-Clause "New" or "Revised" License | 5 votes |
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'])
Example #6
Source File: headerregistry.py From odoo13-x64 with GNU General Public License v3.0 | 5 votes |
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'])
Example #7
Source File: test_utils.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
def test_parsedate_to_datetime_naive(self): self.assertEqual( utils.parsedate_to_datetime(self.datestring + ' -0000'), self.naive_dt)
Example #8
Source File: test_utils.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
def test_parsedate_to_datetime(self): self.assertEqual( utils.parsedate_to_datetime(self.datestring + self.offsetstring), self.aware_dt)
Example #9
Source File: headerregistry.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
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'])
Example #10
Source File: update-zonefile.py From bind-adblock with MIT License | 5 votes |
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()
Example #11
Source File: test_utils.py From ironpython3 with Apache License 2.0 | 5 votes |
def test_parsedate_to_datetime_naive(self): self.assertEqual( utils.parsedate_to_datetime(self.datestring + ' -0000'), self.naive_dt)
Example #12
Source File: test_utils.py From ironpython3 with Apache License 2.0 | 5 votes |
def test_parsedate_to_datetime(self): self.assertEqual( utils.parsedate_to_datetime(self.datestring + self.offsetstring), self.aware_dt)
Example #13
Source File: base.py From quart with MIT License | 5 votes |
def date(self) -> Optional[datetime]: if "date" in self.headers: return parsedate_to_datetime(self.headers["date"]) else: return None
Example #14
Source File: headerregistry.py From Imogen with MIT License | 5 votes |
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'])
Example #15
Source File: test_utils.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
def test_parsedate_to_datetime_naive(self): self.assertEqual( utils.parsedate_to_datetime(self.datestring + ' -0000'), self.naive_dt)
Example #16
Source File: test_utils.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
def test_parsedate_to_datetime(self): self.assertEqual( utils.parsedate_to_datetime(self.datestring + self.offsetstring), self.aware_dt)
Example #17
Source File: headerregistry.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
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'])
Example #18
Source File: twhttp.py From twtxt with MIT License | 5 votes |
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)
Example #19
Source File: response.py From quart with MIT License | 5 votes |
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
Example #20
Source File: response.py From quart with MIT License | 5 votes |
def expires(self) -> Optional[datetime]: try: return parsedate_to_datetime(self.headers.get("Expires", "")) except TypeError: # Not a date format return None
Example #21
Source File: response.py From quart with MIT License | 5 votes |
def date(self) -> Optional[datetime]: try: return parsedate_to_datetime(self.headers.get("Date", "")) except TypeError: # Not a date format return None
Example #22
Source File: base.py From quart with MIT License | 5 votes |
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
Example #23
Source File: base.py From quart with MIT License | 5 votes |
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
Example #24
Source File: fetcher.py From cms with GNU General Public License v3.0 | 4 votes |
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