Merge lp:~stevenk/python-debian/merge-and-stricter into lp:~launchpad-pqm/python-debian/devel
- merge-and-stricter
- Merge into devel
Proposed by
Steve Kowalik
Status: | Merged |
---|---|
Merged at revision: | 186 |
Proposed branch: | lp:~stevenk/python-debian/merge-and-stricter |
Merge into: | lp:~launchpad-pqm/python-debian/devel |
Diff against target: |
361 lines (+184/-22) 8 files modified
debian/changelog (+14/-10) debian/control (+2/-2) lib/debian/changelog.py (+77/-0) lib/debian/deb822.py (+27/-10) lib/debian/debian_support.py (+4/-0) tests/test_Sources.mixed_encoding (+34/-0) tests/test_changelog.py (+2/-0) tests/test_deb822.py (+24/-0) |
To merge this branch: | bzr merge lp:~stevenk/python-debian/merge-and-stricter |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Robert Collins (community) | Approve | ||
William Grant (community) | code* | Approve | |
Review via email: mp+55277@code.launchpad.net |
Commit message
Description of the change
Merge to the tip of lp:python-debian, and include a patch that makes BaseVersion stricter about versions.
To post a comment you must log in.
Revision history for this message
William Grant (wgrant) : | # |
review:
Approve
(code*)
Revision history for this message
Robert Collins (lifeless) wrote : | # |
(the find() -> in change would be nice too, of course)
- 188. By Steve Kowalik
-
Use in, rather than .find()
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'debian/changelog' |
2 | --- debian/changelog 2010-08-02 22:12:54 +0000 |
3 | +++ debian/changelog 2011-03-29 04:59:41 +0000 |
4 | @@ -1,19 +1,23 @@ |
5 | -python-debian (0.1.17~bzr184~launchpad2) hardy; urgency=low |
6 | +python-debian (0.1.18) unstable; urgency=low |
7 | + |
8 | + * Support installation together with older versions of python-apt. |
9 | + Original patch by Jelmer Vernooij. (Closes: #590805) |
10 | + |
11 | + -- John Wright <jsw@debian.org> Wed, 04 Aug 2010 01:16:52 -0700 |
12 | + |
13 | +python-debian (0.1.17) unstable; urgency=low |
14 | |
15 | [ James Westby ] |
16 | * Use os.path.normpath to hide python version differences |
17 | |
18 | [ John Wright ] |
19 | * test_deb822.py: Make test_gpg_info more robust (Closes: #582878) |
20 | - * Support installation together with older versions of python-apt. |
21 | - Original patch by Jelmer Vernooij. (Closes: #590805) |
22 | - |
23 | - [ Jelmer Vernooij ] |
24 | - * Always use NativeVersion class to work around Debian bug #573592. |
25 | - * Upload to Launchpad PPA. |
26 | - * Downgrade source format to 1.0 to support building on Hardy. |
27 | - |
28 | - -- Jelmer Vernooij <jelmer@debian.org> Thu, 29 Jul 2010 14:23:02 +0200 |
29 | + * deb822: Use chardet to try to detect character encodings as necessary |
30 | + - This is only used when the specified encoding doesn't work. It's mainly |
31 | + useful for files containing multiple deb822 paragraphs with mixed |
32 | + encodings, like etch's Sources file. (Closes: #586021) |
33 | + |
34 | + -- John Wright <jsw@debian.org> Sun, 25 Jul 2010 02:07:11 -0700 |
35 | |
36 | python-debian (0.1.16) unstable; urgency=low |
37 | |
38 | |
39 | === modified file 'debian/control' |
40 | --- debian/control 2010-08-02 22:12:54 +0000 |
41 | +++ debian/control 2011-03-29 04:59:41 +0000 |
42 | @@ -8,7 +8,7 @@ |
43 | Reinhard Tartler <siretart@tauware.de>, |
44 | Stefano Zacchiroli <zack@debian.org>, |
45 | John Wright <jsw@debian.org> |
46 | -Build-Depends: debhelper (>= 5.0.37.2), python, python-setuptools |
47 | +Build-Depends: debhelper (>= 5.0.37.2), python, python-setuptools, python-chardet |
48 | Build-Depends-Indep: python-support (>= 0.3) |
49 | Standards-Version: 3.8.4 |
50 | Vcs-Browser: http://git.debian.org/?p=pkg-python-debian/python-debian.git |
51 | @@ -16,7 +16,7 @@ |
52 | |
53 | Package: python-debian |
54 | Architecture: all |
55 | -Depends: ${python:Depends}, ${misc:Depends} |
56 | +Depends: ${python:Depends}, ${misc:Depends}, python-chardet |
57 | Recommends: python-apt |
58 | Suggests: gpgv |
59 | Provides: python-deb822 |
60 | |
61 | === modified file 'lib/debian/changelog.py' |
62 | --- lib/debian/changelog.py 2010-03-14 09:16:30 +0000 |
63 | +++ lib/debian/changelog.py 2011-03-29 04:59:41 +0000 |
64 | @@ -23,7 +23,10 @@ |
65 | |
66 | """This module implements facilities to deal with Debian changelogs.""" |
67 | |
68 | +import os |
69 | +import pwd |
70 | import re |
71 | +import socket |
72 | import warnings |
73 | |
74 | import debian_support |
75 | @@ -470,3 +473,77 @@ |
76 | |
77 | def write_to_open_file(self, file): |
78 | file.write(self.__str__()) |
79 | + |
80 | + |
81 | +def get_maintainer(): |
82 | + """Get the maintainer information in the same manner as dch. |
83 | + |
84 | + This function gets the information about the current user for |
85 | + the maintainer field using environment variables of gecos |
86 | + informations as approriate. |
87 | + |
88 | + It uses the same methods as dch to get the information, namely |
89 | + DEBEMAIL, DEBFULLNAME, EMAIL, NAME, /etc/mailname and gecos. |
90 | + |
91 | + :returns: a tuple of the full name, email pair as strings. |
92 | + Either of the pair may be None if that value couldn't |
93 | + be determined. |
94 | + """ |
95 | + env = os.environ |
96 | + regex = re.compile(r"^(.*)\s+<(.*)>$") |
97 | + |
98 | + # Split email and name |
99 | + if 'DEBEMAIL' in env: |
100 | + match_obj = regex.match(env['DEBEMAIL']) |
101 | + if match_obj: |
102 | + if not 'DEBFULLNAME' in env: |
103 | + env['DEBFULLNAME'] = match_obj.group(1) |
104 | + env['DEBEMAIL'] = match_obj.group(2) |
105 | + if 'DEBEMAIL' not in env or 'DEBFULLNAME' not in env: |
106 | + if 'EMAIL' in env: |
107 | + match_obj = regex.match(env['EMAIL']) |
108 | + if match_obj: |
109 | + if not 'DEBFULLNAME' in env: |
110 | + env['DEBFULLNAME'] = match_obj.group(1) |
111 | + env['EMAIL'] = match_obj.group(2) |
112 | + |
113 | + # Get maintainer's name |
114 | + if 'DEBFULLNAME' in env: |
115 | + maintainer = env['DEBFULLNAME'] |
116 | + elif 'NAME' in env: |
117 | + maintainer = env['NAME'] |
118 | + else: |
119 | + # Use password database if no data in environment variables |
120 | + try: |
121 | + maintainer = re.sub(r',.*', '', pwd.getpwuid(os.getuid()).pw_gecos) |
122 | + except (KeyError, AttributeError): |
123 | + maintainer = None |
124 | + |
125 | + # Get maintainer's mail address |
126 | + if 'DEBEMAIL' in env: |
127 | + email = env['DEBEMAIL'] |
128 | + elif 'EMAIL' in env: |
129 | + email = env['EMAIL'] |
130 | + else: |
131 | + addr = None |
132 | + if os.path.exists('/etc/mailname'): |
133 | + f = open('/etc/mailname') |
134 | + try: |
135 | + addr = f.readline().strip() |
136 | + finally: |
137 | + f.close() |
138 | + if not addr: |
139 | + addr = socket.getfqdn() |
140 | + if addr: |
141 | + user = pwd.getpwuid(os.getuid()).pw_name |
142 | + if not user: |
143 | + addr = None |
144 | + else: |
145 | + addr = "%s@%s" % (user, addr) |
146 | + |
147 | + if addr: |
148 | + email = addr |
149 | + else: |
150 | + email = None |
151 | + |
152 | + return (maintainer, email) |
153 | |
154 | === modified file 'lib/debian/deb822.py' |
155 | --- lib/debian/deb822.py 2010-08-02 22:12:54 +0000 |
156 | +++ lib/debian/deb822.py 2011-03-29 04:59:41 +0000 |
157 | @@ -4,7 +4,7 @@ |
158 | # (.changes, .dsc, Packages, Sources, etc) |
159 | # |
160 | # Copyright (C) 2005-2006 dann frazier <dannf@dannf.org> |
161 | -# Copyright (C) 2006-2008 John Wright <john@johnwright.org> |
162 | +# Copyright (C) 2006-2010 John Wright <john@johnwright.org> |
163 | # Copyright (C) 2006 Adeodato Simó <dato@net.com.org.es> |
164 | # Copyright (C) 2008 Stefano Zacchiroli <zack@upsilon.cc> |
165 | # |
166 | @@ -32,10 +32,13 @@ |
167 | except (ImportError, AttributeError): |
168 | _have_apt_pkg = False |
169 | |
170 | +import chardet |
171 | import new |
172 | import re |
173 | import string |
174 | import sys |
175 | +import warnings |
176 | + |
177 | import StringIO |
178 | import UserDict |
179 | |
180 | @@ -178,7 +181,25 @@ |
181 | |
182 | if isinstance(value, str): |
183 | # Always return unicode objects instead of strings |
184 | - value = value.decode(self.encoding) |
185 | + try: |
186 | + value = value.decode(self.encoding) |
187 | + except UnicodeDecodeError, e: |
188 | + # Evidently, the value wasn't encoded with the encoding the |
189 | + # user specified. Try detecting it. |
190 | + warnings.warn('decoding from %s failed; attempting to detect ' |
191 | + 'the true encoding' % self.encoding, |
192 | + UnicodeWarning) |
193 | + result = chardet.detect(value) |
194 | + try: |
195 | + value = value.decode(result['encoding']) |
196 | + except UnicodeDecodeError: |
197 | + raise e |
198 | + else: |
199 | + # Assume the rest of the paragraph is in this encoding as |
200 | + # well (there's no sense in repeating this exercise for |
201 | + # every field). |
202 | + self.encoding = result['encoding'] |
203 | + |
204 | return value |
205 | |
206 | def __delitem__(self, key): |
207 | @@ -309,33 +330,29 @@ |
208 | curkey = None |
209 | content = "" |
210 | for line in self.gpg_stripped_paragraph(sequence): |
211 | - if isinstance(line, str): |
212 | - line = line.decode(self.encoding) |
213 | m = single.match(line) |
214 | if m: |
215 | if curkey: |
216 | - self[curkey] += content |
217 | + self[curkey] = content |
218 | |
219 | if not wanted_field(m.group('key')): |
220 | curkey = None |
221 | continue |
222 | |
223 | curkey = m.group('key') |
224 | - self[curkey] = m.group('data') |
225 | - content = "" |
226 | + content = m.group('data') |
227 | continue |
228 | |
229 | m = multi.match(line) |
230 | if m: |
231 | if curkey: |
232 | - self[curkey] += content |
233 | + self[curkey] = content |
234 | |
235 | if not wanted_field(m.group('key')): |
236 | curkey = None |
237 | continue |
238 | |
239 | curkey = m.group('key') |
240 | - self[curkey] = "" |
241 | content = "" |
242 | continue |
243 | |
244 | @@ -345,7 +362,7 @@ |
245 | continue |
246 | |
247 | if curkey: |
248 | - self[curkey] += content |
249 | + self[curkey] = content |
250 | |
251 | def __str__(self): |
252 | return self.dump() |
253 | |
254 | === modified file 'lib/debian/debian_support.py' |
255 | --- lib/debian/debian_support.py 2010-03-14 11:37:42 +0000 |
256 | +++ lib/debian/debian_support.py 2011-03-29 04:59:41 +0000 |
257 | @@ -94,6 +94,10 @@ |
258 | m = self.re_valid_version.match(version) |
259 | if not m: |
260 | raise ValueError("Invalid version string %r" % version) |
261 | + # If there no epoch ("1:..."), then the upstream version can not |
262 | + # contain a :. |
263 | + if m.group("epoch") is None and ':' in m.group("upstream_version"): |
264 | + raise ValueError("Invalid version string %r" % version) |
265 | |
266 | self.__full_version = version |
267 | self.__epoch = m.group("epoch") |
268 | |
269 | === added file 'tests/test_Sources.mixed_encoding' |
270 | --- tests/test_Sources.mixed_encoding 1970-01-01 00:00:00 +0000 |
271 | +++ tests/test_Sources.mixed_encoding 2011-03-29 04:59:41 +0000 |
272 | @@ -0,0 +1,34 @@ |
273 | +Package: amarok |
274 | +Binary: amarok, amarok-engines, amarok-xine |
275 | +Version: 1.4.4-4etch1 |
276 | +Priority: optional |
277 | +Section: kde |
278 | +Maintainer: Adeodato Simó <dato@net.com.org.es> |
279 | +Build-Depends: cdbs, debhelper (>= 5), quilt, bzip2, automake1.9, libtool, kdelibs4-dev, kdemultimedia-dev, kdebase-dev, libxine-dev, libtag1-dev (>> 1.4), libsqlite3-dev, libtunepimp3-dev, libmysqlclient15-dev, libpq-dev, xmms-dev, libvisual-0.4-dev, libsdl1.2-dev, libifp-dev, libusb-dev, libgpod-dev, libnjb-dev, ruby, ruby1.8-dev, dpkg-dev (>= 1.13.19) |
280 | +Architecture: any |
281 | +Standards-Version: 3.7.2 |
282 | +Format: 1.0 |
283 | +Directory: pool/main/a/amarok |
284 | +Files: |
285 | + f8e80af55fbd8386e6b13b0b12d798f4 986 amarok_1.4.4-4etch1.dsc |
286 | + 0adbbd8373da2198b80e509618a2dab9 17628566 amarok_1.4.4.orig.tar.gz |
287 | + c29b0538c033ededacc6d31339d17700 42402 amarok_1.4.4-4etch1.diff.gz |
288 | +Uploaders: Ana Beatriz Guerrero Lopez <ana@debian.org> |
289 | + |
290 | +Package: texinfo |
291 | +Binary: texinfo, info |
292 | +Version: 4.8.dfsg.1-4 |
293 | +Priority: important |
294 | +Section: doc |
295 | +Maintainer: Norbert Preining <preining@debian.org> |
296 | +Build-Depends: debhelper (>= 5), dpatch, libncurses5-dev | libncurses-dev, gettext |
297 | +Architecture: any |
298 | +Standards-Version: 3.7.2 |
299 | +Format: 1.0 |
300 | +Directory: pool/main/t/texinfo |
301 | +Files: |
302 | + 2c233d2bf6627eac32deb9bb87726ea1 680 texinfo_4.8.dfsg.1-4.dsc |
303 | + 614273ac8568a25926aae374cd9a6683 1926534 texinfo_4.8.dfsg.1.orig.tar.gz |
304 | + e01520524bc114d90a2a1e5eefe71b50 101211 texinfo_4.8.dfsg.1-4.diff.gz |
305 | +Uploaders: Frank Küster <frank@debian.org> |
306 | + |
307 | |
308 | === modified file 'tests/test_changelog.py' |
309 | --- tests/test_changelog.py 2010-03-14 09:16:30 +0000 |
310 | +++ tests/test_changelog.py 2011-03-29 04:59:41 +0000 |
311 | @@ -202,6 +202,8 @@ |
312 | self._test_version('2:1.0.4+svn26-1ubuntu1', '2', '1.0.4+svn26', |
313 | '1ubuntu1') |
314 | self._test_version('2:1.0.4~rc2-1', '2', '1.0.4~rc2', '1') |
315 | + self.assertRaises( |
316 | + ValueError, changelog.Version, 'a1:1.8.8-070403-1~priv1') |
317 | |
318 | def test_version_updating(self): |
319 | v = changelog.Version('1:1.4.1-1') |
320 | |
321 | === modified file 'tests/test_deb822.py' |
322 | --- tests/test_deb822.py 2010-07-25 07:12:28 +0000 |
323 | +++ tests/test_deb822.py 2011-03-29 04:59:41 +0000 |
324 | @@ -21,6 +21,7 @@ |
325 | import re |
326 | import sys |
327 | import unittest |
328 | +import warnings |
329 | from StringIO import StringIO |
330 | |
331 | sys.path.insert(0, '../lib/debian/') |
332 | @@ -702,6 +703,29 @@ |
333 | self.assertEqual(utf8_contents, latin1_to_utf8.getvalue()) |
334 | self.assertEqual(latin1_contents, utf8_to_latin1.getvalue()) |
335 | |
336 | + def test_mixed_encodings(self): |
337 | + """Test that we can handle a simple case of mixed encodings |
338 | + |
339 | + In general, this isn't guaranteed to work. It uses the chardet |
340 | + package, which tries to determine heuristically the encoding of the |
341 | + text given to it. But as far as I've seen, it's reliable for mixed |
342 | + latin1 and utf-8 in maintainer names in old Sources files... |
343 | + """ |
344 | + |
345 | + # Avoid spitting out the encoding warning during testing. |
346 | + warnings.filterwarnings(action='ignore', category=UnicodeWarning) |
347 | + |
348 | + filename = 'test_Sources.mixed_encoding' |
349 | + for paragraphs in [deb822.Sources.iter_paragraphs(file(filename)), |
350 | + deb822.Sources.iter_paragraphs(file(filename), |
351 | + use_apt_pkg=False)]: |
352 | + p1 = paragraphs.next() |
353 | + self.assertEqual(p1['maintainer'], |
354 | + u'Adeodato Simó <dato@net.com.org.es>') |
355 | + p2 = paragraphs.next() |
356 | + self.assertEqual(p2['uploaders'], |
357 | + u'Frank Küster <frank@debian.org>') |
358 | + |
359 | class TestPkgRelations(unittest.TestCase): |
360 | |
361 | def test_packages(self): |
Looks fine to me