summaryrefslogtreecommitdiff
path: root/contrib/python/podman/libs
diff options
context:
space:
mode:
authorJhon Honce <jhonce@redhat.com>2018-05-21 16:31:36 -0700
committerAtomic Bot <atomic-devel@projectatomic.io>2018-05-23 17:54:09 +0000
commit5f0d4b10e9b5ea18e91090e82ddfb22f63b06635 (patch)
tree0a308dd23c0f1c2149f8d597224ba73440bf793d /contrib/python/podman/libs
parentc1efde20e01f255b1186d6958371da4f5401310a (diff)
downloadpodman-5f0d4b10e9b5ea18e91090e82ddfb22f63b06635.tar.gz
podman-5f0d4b10e9b5ea18e91090e82ddfb22f63b06635.tar.bz2
podman-5f0d4b10e9b5ea18e91090e82ddfb22f63b06635.zip
Add support for Zulu timestamp parsing
- Improve error message when podman varlink service is not running Signed-off-by: Jhon Honce <jhonce@redhat.com> Closes: #800 Approved by: rhatdan
Diffstat (limited to 'contrib/python/podman/libs')
-rw-r--r--contrib/python/podman/libs/__init__.py43
1 files changed, 5 insertions, 38 deletions
diff --git a/contrib/python/podman/libs/__init__.py b/contrib/python/podman/libs/__init__.py
index ab8fb94a8..7285921d7 100644
--- a/contrib/python/podman/libs/__init__.py
+++ b/contrib/python/podman/libs/__init__.py
@@ -1,7 +1,8 @@
"""Support files for podman API implementation."""
import datetime
-import re
import threading
+from dateutil.parser import parse as dateutil_parse
+
__all__ = [
'cached_property',
@@ -44,45 +45,11 @@ class cached_property(object):
def datetime_parse(string):
- """Convert timestamp to datetime.
-
- Because date/time parsing in python is still pedantically stupid,
- we rip the input string apart throwing out the stop characters etc;
- then rebuild a string strptime() can parse. Igit!
-
- - Python >3.7 will address colons in the UTC offset.
- - There is no ETA on microseconds > 6 digits.
- - And giving an offset and timezone name...
-
- # match: 2018-05-08T14:12:53.797795191-07:00
- # match: 2018-05-08T18:24:52.753227-07:00
- # match: 2018-05-08 14:12:53.797795191 -0700 MST
- # match: 2018-05-09T10:45:57.576002 (python isoformat())
+ """Convert timestamps to datetime.
- Some people, when confronted with a problem, think “I know,
- I'll use regular expressions.” Now they have two problems.
- -- Jamie Zawinski
+ tzinfo aware, if provided.
"""
- ts = re.compile(r'^(\d+)-(\d+)-(\d+)'
- r'[ T]?(\d+):(\d+):(\d+).(\d+)'
- r' *([-+][\d:]{4,5})? *')
-
- x = ts.match(string)
- if x is None:
- raise ValueError('Unable to parse {}'.format(string))
-
- # converting everything to int() not worth the readablity hit
- igit_proof = '{}T{}.{}{}'.format(
- '-'.join(x.group(1, 2, 3)),
- ':'.join(x.group(4, 5, 6)),
- x.group(7)[0:6],
- x.group(8).replace(':', '') if x.group(8) else '',
- )
-
- format = '%Y-%m-%dT%H:%M:%S.%f'
- if x.group(8):
- format += '%z'
- return datetime.datetime.strptime(igit_proof, format)
+ return dateutil_parse(string.upper(), fuzzy=True)
def datetime_format(dt):