exception raised by installedFiles on unicode filenames

Bug #407953 reported by Chris Jones
12
This bug affects 2 people
Affects Status Importance Assigned to Milestone
python-apt (Ubuntu)
Fix Released
Undecided
Unassigned

Bug Description

Binary package hint: python-apt

I'm iterating over installed packages and looking at their installedFiles list. Some packages seem to have unicode filenames (e.g. the 'kbd' package has /usr/share/doc/kbd/utf/♪♬) which cause exceptions to be raised:

Traceback (most recent call last):
  File "./apptest.py", line 10, in <module>
    files = pkg.installedFiles
  File "/usr/lib/python2.6/dist-packages/apt/package.py", line 709, in installedFiles
    return file_list.read().decode().split("\n")
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 3636: ordinal not in range(128)

ProblemType: Bug
Architecture: amd64
Date: Sun Aug 2 11:49:18 2009
DistroRelease: Ubuntu 9.10
Package: python-apt 0.7.10.4ubuntu1
ProcEnviron:
 PATH=(custom, user)
 LANG=en_GB.UTF-8
 SHELL=/bin/bash
ProcVersionSignature: Ubuntu 2.6.31-4.23-generic
SourcePackage: python-apt
Uname: Linux 2.6.31-4-generic x86_64

Revision history for this message
Chris Jones (cmsj) wrote :
Revision history for this message
Chris Jones (cmsj) wrote :

trivial script to reproduce the backtrace

Revision history for this message
Chris Jones (cmsj) wrote :

reload(sys)
sys.setdefaultencoding('utf-8')

"fixes" this. I guess this is just python being a bit weak on unicode?

Revision history for this message
Julian Andres Klode (juliank) wrote :

I committed the following fix to the Debian branch which should fix this problem.

=== modified file 'apt/package.py'
--- apt/package.py 2010-03-08 14:04:39 +0000
+++ apt/package.py 2010-03-30 10:58:26 +0000
@@ -955,9 +955,9 @@ class Package(object):
         """
         path = "/var/lib/dpkg/info/%s.list" % self.name
         try:
- file_list = open(path)
+ file_list = open(path, "rb")
             try:
- return file_list.read().decode().split("\n")
+ return file_list.read().decode("utf-8").split(u"\n")
             finally:
                 file_list.close()
         except EnvironmentError:

Changed in python-apt (Ubuntu):
status: New → In Progress
Revision history for this message
Launchpad Janitor (janitor) wrote :

This bug was fixed in the package python-apt - 0.7.94.2ubuntu5

---------------
python-apt (0.7.94.2ubuntu5) lucid; urgency=low

  [ Julian Andres Klode ]
  * apt/package.py:
    - Decode using utf-8 in installed_files (LP: #407953).
    - Fix fetch_source() to work when source name = binary name (LP: #552400).
  * python/cache.cc:
    - Check that 2nd argument to Cache.update() really is a SourceList object.
  * python/generic.cc:
    - Map ArchiveURI property to archive_uri
  * utils/migrate-0.8.py:
    - Open files in universal newline support and pass filename to ast.parse.
    - Add has_key to the list of deprecated functions.
    - Don't abort if parsing failed.
    - do not require files to end in .py if they are passed on the command
      line or if they contain python somewhere in the shebang line.
 -- Michael Vogt <email address hidden> Wed, 31 Mar 2010 22:11:38 +0200

Changed in python-apt (Ubuntu):
status: In Progress → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.