← Back to team overview

apport-hackers team mailing list archive

Apport API users: Watch your data types / Python 3 porting

 

Hello Ubuntu developers,

I just uploaded Apport 2.1 to Quantal. A big change in that version is
that the whole code now works with both Python 2 and 3, except for the
launchpadlib crash database backend (as we do not yet have a
python3-launchpadlib package).

I took some care that apport report objects get along with both
strings ("unicode" type in Python 2) and byte arrays ("str" type in
Python 2) in values, so most package hooks should still work. However,
now is the time to check whether they also work with Python 3, to make
the impending transition to Python 3 easier.

However, you need to watch out if you use projects or scripts which
directly use python-apport to process reports: The open(), write(),
and write_mime() methods now require the passed file descriptors to be
open in binary mode. You will get an exception otherwise.

A common pattern so far has been code like

  report = apport.Report()
  report.load(open('myfile.crash'))

This needs to be changed to

  report = apport.Report()
  with open('myfile.crash', 'rb') as f:
      report.load(f)

The "with" context is not strictly required, but it takes care of
timely closing the files again. This avoids ResourceWarning spew
when you run this in test suites or enable warnings.

Thanks,

Martin
 
-- 
Martin Pitt                        | http://www.piware.de
Ubuntu Developer (www.ubuntu.com)  | Debian Developer  (www.debian.org)

Attachment: signature.asc
Description: Digital signature