summaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorZac Medico <zmedico@gentoo.org>2009-10-25 23:57:44 +0000
committerZac Medico <zmedico@gentoo.org>2009-10-25 23:57:44 +0000
commitefe96ef184b8a5206441bd3e349f229149c988e4 (patch)
tree897711cbbf3eef95c7e4264aecc433ccae042cc0 /bin
parentUse calendar.timegm instead of time.mktime, for correct timezone handling. (diff)
downloadportage-idfetch-efe96ef184b8a5206441bd3e349f229149c988e4.tar.gz
portage-idfetch-efe96ef184b8a5206441bd3e349f229149c988e4.tar.bz2
portage-idfetch-efe96ef184b8a5206441bd3e349f229149c988e4.zip
Add a parsedate() function which emulates rfc822.parsedate(), since python3
doesn't have it. svn path=/main/trunk/; revision=14729
Diffstat (limited to 'bin')
-rwxr-xr-xbin/repoman40
1 files changed, 28 insertions, 12 deletions
diff --git a/bin/repoman b/bin/repoman
index 9a016896..74bbdab9 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)