Gentoo Archives: gentoo-commits

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