ronaldoussoren / modulegraph

modulegraph determines a dependency graph between Python modules primarily by bytecode analysis for import statements. modulegraph uses similar methods to modulefinder from the standard library, but uses a more flexible internal representation, has more extensive knowledge of special cases, and is extensible.
MIT No Attribution
38 stars 4 forks source link

zipio.open can return objects without context handlers in python 2 #10

Closed ronaldoussoren closed 11 years ago

ronaldoussoren commented 11 years ago

Original report by James Kruth (Bitbucket: artlogic, GitHub: artlogic).


In python 2, StringIO does not implement the context handler protocol. In py2app, calls to zipio.open assume that a context handler is present.

This is fairly easily fixed by doing a version check, and if on python 2, changing the following lines to:

#!python
84:    return contextlib.closing(_BytesIO(data))
90:    return contextlib.closing(_StringIO(data))

You'll of course have to import contextlib as well.

ronaldoussoren commented 11 years ago

Original comment by Ronald Oussoren (Bitbucket: ronaldoussoren, GitHub: ronaldoussoren).


Ensure that the result of zipio.open can be used in a with statement

Fixes issue #10.

ronaldoussoren commented 11 years ago

Original comment by Ronald Oussoren (Bitbucket: ronaldoussoren, GitHub: ronaldoussoren).


Thanks for the report!