summaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorZac Medico <zmedico@gentoo.org>2009-10-27 22:55:04 +0000
committerZac Medico <zmedico@gentoo.org>2009-10-27 22:55:04 +0000
commit49a1e24fcc6bc0c23181665519fc92ae4fb0de58 (patch)
tree9e7e8be13a6c1c8abf82f0e15ae691d2f1c3ada9 /bin
parentUse calendar.timegm instead of time.mktime, for correct timezone handling. (diff)
downloadportage-multirepo-49a1e24fcc6bc0c23181665519fc92ae4fb0de58.tar.gz
portage-multirepo-49a1e24fcc6bc0c23181665519fc92ae4fb0de58.tar.bz2
portage-multirepo-49a1e24fcc6bc0c23181665519fc92ae4fb0de58.zip
Add a parsedate() function which emulates rfc822.parsedate(), since python3
doesn't have it. (trunk r14729) svn path=/main/branches/2.1.7/; revision=14737
Diffstat (limited to 'bin')
-rwxr-xr-xbin/repoman40
1 files changed, 28 insertions, 12 deletions
diff --git a/bin/repoman b/bin/repoman
index f6fb55b3..80e7a97d 100755
--- a/bin/repoman
+++ b/bin/repoman
@@ -32,11 +32,6 @@ try:
except ImportError:
from urllib import urlopen as urllib_request_urlopen
-try:
- from rfc822 import parsedate
-except ImportError:
- parsedate = None
-
from io import StringIO
from itertools import chain
from stat import S_ISDIR, ST_CTIME
@@ -784,6 +779,33 @@ for x in qacats:
xmllint_capable = False
metadata_dtd = os.path.join(repoman_settings["DISTDIR"], 'metadata.dtd')
+def parsedate(s):
+ """Parse a RFC 822 date and time string.
+ This is required for python3 compatibility, since the
+ rfc822.parsedate() function is not available."""
+
+ s_split = []
+ for x in s.upper().split():
+ for y in x.split(','):
+ if y:
+ s_split.append(y)
+
+ if len(s_split) != 6:
+ return None
+
+ # %a, %d %b %Y %H:%M:%S %Z
+ a, d, b, Y, H_M_S, Z = s_split
+
+ # Convert month to integer, since strptime %w is locale-dependent.
+ month_map = {'JAN':1, 'FEB':2, 'MAR':3, 'APR':4, 'MAY':5, 'JUN':6,
+ 'JUL':7, 'AUG':8, 'SEP':9, 'OCT':10, 'NOV':11, 'DEC':12}
+ m = month_map.get(b)
+ if m is None:
+ return None
+ m = str(m).rjust(2, '0')
+
+ return time.strptime(':'.join((Y, m, d, H_M_S)), '%Y:%m:%d:%H:%M:%S')
+
def fetch_metadata_dtd():
"""
Fetch metadata.dtd if it doesn't exist or the ctime is older than
@@ -816,13 +838,7 @@ def fetch_metadata_dtd():
url_f = urllib_request_urlopen(metadata_dtd_uri)
msg_info = url_f.info()
last_modified = msg_info.get('last-modified')
- # Date parsing isn't supported in python3 since it has no
- # equivalent of the rfc822.parsedate() function.
- # TODO: Convert the last-modified field to locale-independent
- # format and then use time.strptime() to parse it.
- if parsedate is None:
- last_modified = None
- elif last_modified is not None:
+ if last_modified is not None:
last_modified = parsedate(last_modified)
if last_modified is not None:
last_modified = calendar.timegm(last_modified)