Merge ~cjwatson/launchpad:unsixify-tagfile-parsing into launchpad:master

Proposed by Colin Watson
Status: Merged
Approved by: Colin Watson
Approved revision: 99b2626d7040b480c3223c206e054ad30e6ce594
Merge reported by: Otto Co-Pilot
Merged at revision: not available
Proposed branch: ~cjwatson/launchpad:unsixify-tagfile-parsing
Merge into: launchpad:master
Diff against target: 338 lines (+38/-49)
9 files modified
lib/lp/archiveuploader/changesfile.py (+9/-13)
lib/lp/archiveuploader/dscfile.py (+9/-11)
lib/lp/archiveuploader/tagfiles.py (+5/-2)
lib/lp/archiveuploader/tests/nascentupload-closing-bugs.rst (+1/-1)
lib/lp/archiveuploader/tests/nascentuploadfile.rst (+2/-2)
lib/lp/archiveuploader/tests/test_dscfile.py (+2/-2)
lib/lp/soyuz/doc/soyuz-upload.rst (+2/-2)
lib/lp/soyuz/scripts/gina/archive.py (+6/-13)
lib/lp/soyuz/scripts/tests/test_gina.py (+2/-3)
Reviewer Review Type Date Requested Status
Jürgen Gmach Approve
Review via email: mp+436152@code.launchpad.net

Commit message

Remove six from code dealing with parsed tagfiles

Description of the change

`parse_tagfile_content` always returns header values as bytes (now type-annotated), so we can just use `.decode`/`.encode` rather than `six.ensure_*`.

To post a comment you must log in.
Revision history for this message
Jürgen Gmach (jugmac00) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/lib/lp/archiveuploader/changesfile.py b/lib/lp/archiveuploader/changesfile.py
2index 61c722c..6f0f81d 100644
3--- a/lib/lp/archiveuploader/changesfile.py
4+++ b/lib/lp/archiveuploader/changesfile.py
5@@ -15,8 +15,6 @@ __all__ = [
6
7 import os
8
9-import six
10-
11 from lp.archiveuploader.buildinfofile import BuildInfoFile
12 from lp.archiveuploader.dscfile import DSCFile, SignableTagFile
13 from lp.archiveuploader.nascentuploadfile import (
14@@ -267,7 +265,7 @@ class ChangesFile(SignableTagFile):
15 # Urgency is recommended but not mandatory. Default to 'low'
16 self._dict["Urgency"] = b"low"
17
18- raw_urgency = six.ensure_text(self._dict["Urgency"]).lower()
19+ raw_urgency = self._dict["Urgency"].decode().lower()
20 if raw_urgency not in self.urgency_map:
21 yield UploadWarning(
22 "Unable to grok urgency %s, overriding with 'low'"
23@@ -326,7 +324,7 @@ class ChangesFile(SignableTagFile):
24
25 For example, 'hoary' or 'hoary-security'.
26 """
27- return six.ensure_text(self._dict["Distribution"])
28+ return self._dict["Distribution"].decode()
29
30 @property
31 def architectures(self):
32@@ -335,24 +333,22 @@ class ChangesFile(SignableTagFile):
33 For instance ['source', 'all'] or ['source', 'i386', 'amd64']
34 or ['source'].
35 """
36- return set(six.ensure_text(self._dict["Architecture"]).split())
37+ return set(self._dict["Architecture"].decode().split())
38
39 @property
40 def binaries(self):
41 """Return set of binary package names listed."""
42- return set(
43- six.ensure_text(self._dict.get("Binary", "")).strip().split()
44- )
45+ return set(self._dict.get("Binary", "").decode().strip().split())
46
47 @property
48 def converted_urgency(self):
49 """Return the appropriate SourcePackageUrgency item."""
50- return self.urgency_map[six.ensure_text(self._dict["Urgency"]).lower()]
51+ return self.urgency_map[self._dict["Urgency"].decode().lower()]
52
53 @property
54 def version(self):
55 """Return changesfile claimed version."""
56- return six.ensure_text(self._dict["Version"])
57+ return self._dict["Version"].decode()
58
59 @classmethod
60 def formatChangesComment(cls, comment):
61@@ -376,17 +372,17 @@ class ChangesFile(SignableTagFile):
62 @property
63 def date(self):
64 """Return changesfile date."""
65- return six.ensure_text(self._dict["Date"])
66+ return self._dict["Date"].decode()
67
68 @property
69 def source(self):
70 """Return changesfile claimed source name."""
71- return six.ensure_text(self._dict["Source"])
72+ return self._dict["Source"].decode()
73
74 @property
75 def architecture_line(self):
76 """Return changesfile archicteture line."""
77- return six.ensure_text(self._dict["Architecture"])
78+ return self._dict["Architecture"].decode()
79
80 @property
81 def simulated_changelog(self):
82diff --git a/lib/lp/archiveuploader/dscfile.py b/lib/lp/archiveuploader/dscfile.py
83index e7516ff..59b5087 100644
84--- a/lib/lp/archiveuploader/dscfile.py
85+++ b/lib/lp/archiveuploader/dscfile.py
86@@ -23,7 +23,6 @@ import shutil
87 import tempfile
88 import warnings
89
90-import six
91 from debian.deb822 import Deb822Dict, PkgRelation
92 from zope.component import getUtility
93
94@@ -220,8 +219,8 @@ class SignableTagFile:
95 raise UploadError("Invalid Maintainer.")
96
97 if person is None and self.policy.create_people:
98- package = six.ensure_text(self._dict["Source"])
99- version = six.ensure_text(self._dict["Version"])
100+ package = self._dict["Source"].decode()
101+ version = self._dict["Version"].decode()
102 if self.policy.distroseries and self.policy.pocket:
103 policy_suite = "%s/%s" % (
104 self.policy.distroseries.name,
105@@ -344,8 +343,7 @@ class DSCFile(SourceUploadFile, SignableTagFile):
106
107 if self.format is None:
108 raise EarlyReturnUploadError(
109- "Unsupported source format: %s"
110- % six.ensure_str(self._dict["Format"])
111+ "Unsupported source format: %s" % self._dict["Format"].decode()
112 )
113
114 #
115@@ -354,19 +352,19 @@ class DSCFile(SourceUploadFile, SignableTagFile):
116 @property
117 def source(self):
118 """Return the DSC source name."""
119- return six.ensure_text(self._dict["Source"])
120+ return self._dict["Source"].decode()
121
122 @property
123 def dsc_version(self):
124 """Return the DSC source version."""
125- return six.ensure_text(self._dict["Version"])
126+ return self._dict["Version"].decode()
127
128 @property
129 def format(self):
130 """Return the DSC format."""
131 try:
132 return SourcePackageFormat.getTermByToken(
133- six.ensure_text(self._dict["Format"])
134+ self._dict["Format"].decode()
135 ).value
136 except LookupError:
137 return None
138@@ -374,12 +372,12 @@ class DSCFile(SourceUploadFile, SignableTagFile):
139 @property
140 def architecture(self):
141 """Return the DSC source architecture."""
142- return six.ensure_text(self._dict["Architecture"])
143+ return self._dict["Architecture"].decode()
144
145 @property
146 def binary(self):
147 """Return the DSC claimed binary line."""
148- return six.ensure_text(self._dict["Binary"])
149+ return self._dict["Binary"].decode()
150
151 #
152 # DSC file checks.
153@@ -449,7 +447,7 @@ class DSCFile(SourceUploadFile, SignableTagFile):
154 for field_name in ["Build-Depends", "Build-Depends-Indep"]:
155 field = self._dict.get(field_name, None)
156 if field is not None:
157- field = six.ensure_text(field)
158+ field = field.decode()
159 if field.startswith("ARRAY"):
160 yield UploadError(
161 "%s: invalid %s field produced by a broken version "
162diff --git a/lib/lp/archiveuploader/tagfiles.py b/lib/lp/archiveuploader/tagfiles.py
163index 7470f27..7815394 100644
164--- a/lib/lp/archiveuploader/tagfiles.py
165+++ b/lib/lp/archiveuploader/tagfiles.py
166@@ -7,6 +7,7 @@ __all__ = ["TagFileParseError", "parse_tagfile", "parse_tagfile_content"]
167
168
169 import tempfile
170+from typing import Dict, Optional
171
172 import apt_pkg
173
174@@ -19,7 +20,9 @@ class TagFileParseError(Exception):
175 pass
176
177
178-def parse_tagfile_content(content, filename=None):
179+def parse_tagfile_content(
180+ content: bytes, filename: Optional[str] = None
181+) -> Dict[str, bytes]:
182 """Parses a tag file and returns a dictionary where each field is a key.
183
184 The mandatory first argument is the contents of the tag file as a
185@@ -56,7 +59,7 @@ def parse_tagfile_content(content, filename=None):
186 return trimmed_dict
187
188
189-def parse_tagfile(filename):
190+def parse_tagfile(filename: str) -> Dict[str, bytes]:
191 """Parses a tag file and returns a dictionary where each field is a key.
192
193 The mandatory first argument is the filename of the tag file, and
194diff --git a/lib/lp/archiveuploader/tests/nascentupload-closing-bugs.rst b/lib/lp/archiveuploader/tests/nascentupload-closing-bugs.rst
195index 68eff30..4a47593 100644
196--- a/lib/lp/archiveuploader/tests/nascentupload-closing-bugs.rst
197+++ b/lib/lp/archiveuploader/tests/nascentupload-closing-bugs.rst
198@@ -82,7 +82,7 @@ This new version fixes bug #6 according its changesfiles:
199 >>> print(bar2_src.changes.changed_by["person"].name)
200 kinnison
201
202- >>> print(six.ensure_str(bar2_src.changes._dict["Launchpad-bugs-fixed"]))
203+ >>> print(bar2_src.changes._dict["Launchpad-bugs-fixed"].decode())
204 6
205
206 >>> print(bar2_src.changes.changes_comment)
207diff --git a/lib/lp/archiveuploader/tests/nascentuploadfile.rst b/lib/lp/archiveuploader/tests/nascentuploadfile.rst
208index 357205c..78bfed5 100644
209--- a/lib/lp/archiveuploader/tests/nascentuploadfile.rst
210+++ b/lib/lp/archiveuploader/tests/nascentuploadfile.rst
211@@ -274,8 +274,8 @@ Some fields extracted from the tag_file are required, they are always
212 present in ChangesFile and DSCFile:
213
214 >>> sig_file._dict = {}
215- >>> sig_file._dict["Source"] = "some-source"
216- >>> sig_file._dict["Version"] = "6.6.6"
217+ >>> sig_file._dict["Source"] = b"some-source"
218+ >>> sig_file._dict["Version"] = b"6.6.6"
219
220 After initialising sig_file we can parse addresses and look them up in
221 Launchpad:
222diff --git a/lib/lp/archiveuploader/tests/test_dscfile.py b/lib/lp/archiveuploader/tests/test_dscfile.py
223index b3365a2..23a15ca 100644
224--- a/lib/lp/archiveuploader/tests/test_dscfile.py
225+++ b/lib/lp/archiveuploader/tests/test_dscfile.py
226@@ -168,8 +168,8 @@ class TestSignableTagFile(TestCaseWithFactory):
227 tagfile.logger = DevNullLogger()
228 tagfile.policy = FakePolicy(None, None, create_people=True)
229 tagfile._dict = {
230- "Source": "arbitrary-source-package-name",
231- "Version": "1.0",
232+ "Source": b"arbitrary-source-package-name",
233+ "Version": b"1.0",
234 }
235 return tagfile
236
237diff --git a/lib/lp/soyuz/doc/soyuz-upload.rst b/lib/lp/soyuz/doc/soyuz-upload.rst
238index f32f5f7..b456a95 100644
239--- a/lib/lp/soyuz/doc/soyuz-upload.rst
240+++ b/lib/lp/soyuz/doc/soyuz-upload.rst
241@@ -60,14 +60,14 @@ been uploaded over FTP.
242 ... tf = {}
243 ...
244 ... if "Source" in tf:
245- ... package_names.append(six.ensure_text(tf["Source"]))
246+ ... package_names.append(tf["Source"].decode())
247 ...
248 ... send_filepaths = [changes_filepath]
249 ... if "Files" in tf:
250 ... send_filepaths.extend(
251 ... [
252 ... os.path.join(test_files_dir, line.split()[-1])
253- ... for line in six.ensure_text(tf["Files"]).splitlines()
254+ ... for line in tf["Files"].decode().splitlines()
255 ... if line
256 ... ]
257 ... )
258diff --git a/lib/lp/soyuz/scripts/gina/archive.py b/lib/lp/soyuz/scripts/gina/archive.py
259index f283190..ad06de5 100644
260--- a/lib/lp/soyuz/scripts/gina/archive.py
261+++ b/lib/lp/soyuz/scripts/gina/archive.py
262@@ -20,7 +20,6 @@ import tempfile
263 from collections import defaultdict
264
265 import apt_pkg
266-import six
267
268 from lp.services.scripts import log
269 from lp.soyuz.scripts.gina import call
270@@ -236,10 +235,8 @@ class PackagesMap:
271 for section in sources:
272 try:
273 src_tmp = dict(section)
274- src_tmp["Component"] = six.ensure_binary(
275- info_set.component
276- )
277- src_name = six.ensure_text(src_tmp["Package"])
278+ src_tmp["Component"] = info_set.component.encode()
279+ src_name = src_tmp["Package"].decode()
280 except KeyError:
281 log.exception(
282 "Invalid Sources stanza in %s",
283@@ -267,10 +264,8 @@ class PackagesMap:
284 try:
285 bin_tmp = dict(section)
286 # The component isn't listed in the tagfile.
287- bin_tmp["Component"] = six.ensure_binary(
288- info_set.component
289- )
290- bin_name = six.ensure_text(bin_tmp["Package"])
291+ bin_tmp["Component"] = info_set.component.encode()
292+ bin_name = bin_tmp["Package"].decode()
293 except KeyError:
294 log.exception(
295 "Invalid Releases stanza in %s",
296@@ -284,10 +279,8 @@ class PackagesMap:
297 for section in dibinaries:
298 try:
299 dibin_tmp = dict(section)
300- dibin_tmp["Component"] = six.ensure_binary(
301- info_set.component
302- )
303- dibin_name = six.ensure_text(dibin_tmp["Package"])
304+ dibin_tmp["Component"] = info_set.component.encode()
305+ dibin_name = dibin_tmp["Package"].decode()
306 except KeyError:
307 log.exception(
308 "Invalid D-I Releases stanza in %s" % info_set.difile
309diff --git a/lib/lp/soyuz/scripts/tests/test_gina.py b/lib/lp/soyuz/scripts/tests/test_gina.py
310index 3c37297..edff14e 100644
311--- a/lib/lp/soyuz/scripts/tests/test_gina.py
312+++ b/lib/lp/soyuz/scripts/tests/test_gina.py
313@@ -11,7 +11,6 @@ from textwrap import dedent
314 from unittest import TestLoader
315
316 import apt_pkg
317-import six
318 import transaction
319 from fixtures import EnvironmentVariableFixture
320 from testtools.matchers import MatchesSetwise, MatchesStructure
321@@ -338,7 +337,7 @@ class TestSourcePackageData(TestCaseWithFactory):
322 )
323
324 dsc_contents = parse_tagfile(dsc_path)
325- dsc_contents["Directory"] = six.ensure_binary(pool_dir)
326+ dsc_contents["Directory"] = pool_dir.encode()
327 dsc_contents["Package"] = b"foo"
328 dsc_contents["Component"] = b"main"
329 dsc_contents["Section"] = b"misc"
330@@ -409,7 +408,7 @@ class TestSourcePackageData(TestCaseWithFactory):
331 )
332
333 dsc_contents = parse_tagfile(dsc_path)
334- dsc_contents["Directory"] = six.ensure_binary(pool_dir)
335+ dsc_contents["Directory"] = pool_dir.encode()
336 dsc_contents["Package"] = b"foo"
337 dsc_contents["Component"] = b"main"
338 dsc_contents["Section"] = b"misc"

Subscribers

People subscribed via source and target branches

to status/vote changes: