Merge lp:~vorlon/python-apt/lp.1069019 into lp:~ubuntu-core-dev/python-apt/ubuntu

Proposed by Steve Langasek
Status: Merged
Merge reported by: Steve Langasek
Merged at revision: not available
Proposed branch: lp:~vorlon/python-apt/lp.1069019
Merge into: lp:~ubuntu-core-dev/python-apt/ubuntu
Diff against target: 102 lines (+23/-16)
2 files modified
aptsources/sourceslist.py (+17/-16)
debian/changelog (+6/-0)
To merge this branch: bzr merge lp:~vorlon/python-apt/lp.1069019
Reviewer Review Type Date Requested Status
Brian Murray Approve
Barry Warsaw Pending
Review via email: mp+166148@code.launchpad.net

Description of the change

Possible fix for bug #1069019, using io.open() and enforcing use of Unicode
internally for the handling of the sources.list entries. Does this look
sane?

To post a comment you must log in.
Revision history for this message
Barry Warsaw (barry) wrote :

I think I still prefer using codecs.open() instead of io.open(), but mostly because the former is more common usage. It probably ultimately doesn't matter, and when Python 2 is dropped, either module prefix can be dropped (but neither hurt in either case).

Any chance you can come up with a test case for this bug?

Revision history for this message
Brian Murray (brian-murray) wrote :

I tried recreating the bug by creating a sources.list entry with unicode in the comment (e.g. # disabled‽). Using the version of python-apt in saucy I was unable to disable this line or actually any other line in sources.list.

I then built an update version of the saucy package using Steve's patch in this branch and I was still not able to disable any line in my sources.list file. So I don't think this patch is sufficient.

Revision history for this message
Brian Murray (brian-murray) wrote :

I tested this again following the steps in the above comment, but this time I rebooted after installing python-apt, python3-apt and python-apt-common. After the reboot I am then able to enable and disable sources in software-properties.

Revision history for this message
Brian Murray (brian-murray) wrote :

I don't think we should keep holding out for a test case, especially given bug 1278280 regarding the release-upgrader (which includes sourceslist.py from python-apt) crashing. With the errors associated with that bug we should have positive confirmation that fix is working rather quickly.

I'll go ahead and take care of merging and uploading this.

review: Approve
Revision history for this message
Brian Murray (brian-murray) wrote :

I've uploaded this to trusty, but the python-apt branch is out of date so I'm not sure what to do with the mp.

Revision history for this message
Steve Langasek (vorlon) wrote :

It looks like in the time since this MP was raised, the python-apt upstream branch moved from Launchpad to git.debian.org, and since then the package was in sync with Debian. So let's close this out as "merged" and not worry about the ~ubuntu-core-dev branch. (Ideally we would not list Vcs-Git for this package as pointing to debian since there's no Ubuntu branch there, but that's secondary.)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'aptsources/sourceslist.py'
--- aptsources/sourceslist.py 2012-11-19 13:22:42 +0000
+++ aptsources/sourceslist.py 2013-05-28 22:27:26 +0000
@@ -31,6 +31,7 @@
31import re31import re
32import shutil32import shutil
33import time33import time
34import io
3435
35import apt_pkg36import apt_pkg
36from .distinfo import DistInfo37from .distinfo import DistInfo
@@ -218,20 +219,20 @@
218 """ return the current line as string """219 """ return the current line as string """
219 if self.invalid:220 if self.invalid:
220 return self.line221 return self.line
221 line = ""222 line = u""
222 if self.disabled:223 if self.disabled:
223 line = "# "224 line = u"# "
224225
225 line += self.type226 line += self.type
226227
227 if self.architectures:228 if self.architectures:
228 line += " [arch=%s]" % ",".join(self.architectures)229 line += u" [arch=%s]" % u",".join(self.architectures)
229 line += " %s %s" % (self.uri, self.dist)230 line += u" %s %s" % (self.uri, self.dist)
230 if len(self.comps) > 0:231 if len(self.comps) > 0:
231 line += " " + " ".join(self.comps)232 line += u" " + u" ".join(self.comps)
232 if self.comment != "":233 if self.comment != u"":
233 line += " #"+self.comment234 line += u" #"+self.comment
234 line += "\n"235 line += u"\n"
235 return line236 return line
236237
237238
@@ -322,13 +323,13 @@
322 # there isn't any matching source, so create a new line and parse it323 # there isn't any matching source, so create a new line and parse it
323 line = type324 line = type
324 if architectures:325 if architectures:
325 line += " [arch=%s]" % ",".join(architectures)326 line += u" [arch=%s]" % u",".join(architectures)
326 line += " %s %s" % (uri, dist)327 line += u" %s %s" % (uri, dist)
327 for c in comps:328 for c in comps:
328 line = line + " " + c329 line = line + u" " + c
329 if comment != "":330 if comment != "":
330 line = "%s #%s\n" % (line, comment)331 line = u"%s #%s\n" % (line, comment)
331 line = line + "\n"332 line = line + u"\n"
332 new_entry = SourceEntry(line)333 new_entry = SourceEntry(line)
333 if file is not None:334 if file is not None:
334 new_entry.file = file335 new_entry.file = file
@@ -370,7 +371,7 @@
370 def load(self, file):371 def load(self, file):
371 """ (re)load the current sources """372 """ (re)load the current sources """
372 try:373 try:
373 with open(file, "r") as f:374 with io.open(file, "r", encoding="utf-8") as f:
374 for line in f:375 for line in f:
375 source = SourceEntry(line, file)376 source = SourceEntry(line, file)
376 self.list.append(source)377 self.list.append(source)
@@ -388,14 +389,14 @@
388 "# Remember that you can only use http, ftp or file URIs\n"389 "# Remember that you can only use http, ftp or file URIs\n"
389 "# CDROMs are managed through the apt-cdrom tool.\n")390 "# CDROMs are managed through the apt-cdrom tool.\n")
390391
391 with open(path, "w") as f:392 with io.open(path, "w", encoding="utf-8") as f:
392 f.write(header)393 f.write(header)
393 return394 return
394395
395 try:396 try:
396 for source in self.list:397 for source in self.list:
397 if source.file not in files:398 if source.file not in files:
398 files[source.file] = open(source.file, "w")399 files[source.file] = io.open(source.file, "w", encoding="utf-8")
399 files[source.file].write(source.str())400 files[source.file].write(source.str())
400 finally:401 finally:
401 for f in files:402 for f in files:
402403
=== modified file 'debian/changelog'
--- debian/changelog 2013-04-30 17:01:20 +0000
+++ debian/changelog 2013-05-28 22:27:26 +0000
@@ -4,6 +4,12 @@
4 - export codename in apt.package.Origin as well4 - export codename in apt.package.Origin as well
5 (closes: #703401)5 (closes: #703401)
66
7 [ Steve Langasek ]
8 * aptsources/sourceslist.py: ensure that our sources are opened with UTF-8
9 encoding, regardless of the current locale, and handle the sources lines
10 as Unicode internally for consistency between python2 and python3.
11 LP: #1069019.
12
7 -- Michael Vogt <michael.vogt@ubuntu.com> Tue, 30 Apr 2013 19:00:44 +020013 -- Michael Vogt <michael.vogt@ubuntu.com> Tue, 30 Apr 2013 19:00:44 +0200
814
9python-apt (0.8.8.2ubuntu1) saucy; urgency=low15python-apt (0.8.8.2ubuntu1) saucy; urgency=low

Subscribers

People subscribed via source and target branches

to all changes: