Gentoo Archives: gentoo-commits

From: "Zac Medico (zmedico)" <zmedico@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] portage r14729 - main/trunk/bin
Date: Sun, 25 Oct 2009 23:58:01
Message-Id: E1N2Cy1-00083s-2B@stork.gentoo.org
1 Author: zmedico
2 Date: 2009-10-25 23:57:44 +0000 (Sun, 25 Oct 2009)
3 New Revision: 14729
4
5 Modified:
6 main/trunk/bin/repoman
7 Log:
8 Add a parsedate() function which emulates rfc822.parsedate(), since python3
9 doesn't have it.
10
11
12 Modified: main/trunk/bin/repoman
13 ===================================================================
14 --- main/trunk/bin/repoman 2009-10-25 22:41:27 UTC (rev 14728)
15 +++ main/trunk/bin/repoman 2009-10-25 23:57:44 UTC (rev 14729)
16 @@ -32,11 +32,6 @@
17 except ImportError:
18 from urllib import urlopen as urllib_request_urlopen
19
20 -try:
21 - from rfc822 import parsedate
22 -except ImportError:
23 - parsedate = None
24 -
25 from io import StringIO
26 from itertools import chain
27 from stat import S_ISDIR, ST_CTIME
28 @@ -784,6 +779,33 @@
29 xmllint_capable = False
30 metadata_dtd = os.path.join(repoman_settings["DISTDIR"], 'metadata.dtd')
31
32 +def parsedate(s):
33 + """Parse a RFC 822 date and time string.
34 + This is required for python3 compatibility, since the
35 + rfc822.parsedate() function is not available."""
36 +
37 + s_split = []
38 + for x in s.upper().split():
39 + for y in x.split(','):
40 + if y:
41 + s_split.append(y)
42 +
43 + if len(s_split) != 6:
44 + return None
45 +
46 + # %a, %d %b %Y %H:%M:%S %Z
47 + a, d, b, Y, H_M_S, Z = s_split
48 +
49 + # Convert month to integer, since strptime %w is locale-dependent.
50 + month_map = {'JAN':1, 'FEB':2, 'MAR':3, 'APR':4, 'MAY':5, 'JUN':6,
51 + 'JUL':7, 'AUG':8, 'SEP':9, 'OCT':10, 'NOV':11, 'DEC':12}
52 + m = month_map.get(b)
53 + if m is None:
54 + return None
55 + m = str(m).rjust(2, '0')
56 +
57 + return time.strptime(':'.join((Y, m, d, H_M_S)), '%Y:%m:%d:%H:%M:%S')
58 +
59 def fetch_metadata_dtd():
60 """
61 Fetch metadata.dtd if it doesn't exist or the ctime is older than
62 @@ -816,13 +838,7 @@
63 url_f = urllib_request_urlopen(metadata_dtd_uri)
64 msg_info = url_f.info()
65 last_modified = msg_info.get('last-modified')
66 - # Date parsing isn't supported in python3 since it has no
67 - # equivalent of the rfc822.parsedate() function.
68 - # TODO: Convert the last-modified field to locale-independent
69 - # format and then use time.strptime() to parse it.
70 - if parsedate is None:
71 - last_modified = None
72 - elif last_modified is not None:
73 + if last_modified is not None:
74 last_modified = parsedate(last_modified)
75 if last_modified is not None:
76 last_modified = calendar.timegm(last_modified)