[issue1272] Decode __file__ and co_filename to unicode using fs default

Alexandre Vassalotti report at bugs.python.org
Sun Oct 14 18:00:22 CEST 2007


Alexandre Vassalotti added the comment:

> I have a question for Alexandre related to frozen.c -- why is there a
> mode line with an encoding involved in freezing hello.py?

For some reason which I don't know about, freeze.py tries to read all
the modules accessible from sys.path:

    # collect all modules of the program
    dir = os.path.dirname(scriptfile)
    path[0] = dir
    mf = modulefinder.ModuleFinder(path, debug, exclude, replace_paths)

The problem is the imp module, which modulefinder uses, does not
detect the encoding of the files from the mode-line. This causes
TextIOWrapper to crash when it tries to read modules using an encoding
other than ASCII or UTF-8. Here an example:

  >>> import imp
  >>> imp.find_module('heapq')[0].read()
  Traceback (most recent call last):
  ...
  UnicodeDecodeError: 'utf8' codec can't decode bytes in position
  1428-1430: invalid data

I probably should open a seperate issue in the tracker for this,
though.

__________________________________
Tracker <report at bugs.python.org>
<http://bugs.python.org/issue1272>
__________________________________


More information about the Python-bugs-list mailing list