Python PKG-INFO parsing

SDist raises TypeError when initializing

Reported by rubik on 2011-03-12
258
This bug affects 1 person
Affects Status Importance Assigned to Milestone
pkginfo
Undecided
Tres Seaver

Bug Description

When I try to initialize a sdist distribution a TypeError is raised:
>>> p = SDist('Sphinx-1.0.7.tar.gz')

---------------------------------------------------------------------------
TypeError Traceback (most recent call last)

/home/miki/<ipython console> in <module>()

/usr/local/lib/python2.7/dist-packages/pkginfo/sdist.pyc in __init__(self, filename, metadata_version)
     10 self.filename = filename
     11 self.metadata_version = metadata_version
---> 12 self.extractMetadata()
     13
     14 def read(self):

/usr/local/lib/python2.7/dist-packages/pkginfo/distribution.pyc in extractMetadata(self)
    108 def extractMetadata(self):
    109 data = self.read()
--> 110 self.parse(data)
    111
    112 def read(self):

/usr/local/lib/python2.7/dist-packages/pkginfo/distribution.pyc in parse(self, data)
    117
    118 def parse(self, data):
--> 119 fp = StringIO(data)
    120 msg = parse(fp)
    121

TypeError: initial_value must be unicode or None, not str

Related branches

rubik (michelelacchia) on 2011-03-12
visibility: private → public
Tres Seaver (tseaver) wrote :

Thanks for the bug report. It looks like Python 2.7's io backport broke us
here..

Changed in pkginfo:
assignee: nobody → Tres Seaver (tseaver)
status: New → In Progress
Tres Seaver (tseaver) on 2011-03-12
Changed in pkginfo:
status: In Progress → Fix Released
rubik (michelelacchia) wrote :

I saw that adding unicode() in distribution.py:119 it works:

    fp = StringIO(unicode(data))

Sridhar Ratnakumar (srid) wrote :

Looks like this introduced a regression in 0.8:

    def __init__(self):
> self.extractMetadata()

pypm/grail/veneer.py:297:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <pypm.grail.veneer.Distribution2 object at 0x101e5be10>

    def extractMetadata(self):
        data = self.read()
> self.parse(data)

lib/python2.7/site-packages/pkginfo/distribution.py:110:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <pypm.grail.veneer.Distribution2 object at 0x101e5be10>
data = u'Metadata-Version: 1.0\nName: zope.interface\nVersion: 3.6.1\nSummary: Interf....1\nClassifier: Topic :: Software Development :: Libraries :: Python Modules\n'

    def parse(self, data):
> fp = StringIO(data)
E TypeError: 'unicode' does not have the buffer interface

lib/python2.7/site-packages/pkginfo/distribution.py:119: TypeError

Tres Seaver (tseaver) wrote :

I'm sorry, but your report doesn't give me enough information to figure out whether / how the fix released for this bug caused a regression. Please provide the full traceback, as well as the command line you used to provoke the error.

Tres Seaver (tseaver) wrote :

OK, I've managed to reconstruct the error: you are constructing a unicode literal and
passing it to 'parse()'. I have added code which checks for that and converts it using 'str()',
which will work only if you have no non-encodable characters in the unicode (given the
default system encoding).

 http://bazaar.launchpad.net/~tseaver/pkginfo/trunk/revision/69

To post a comment you must log in.
This report contains Public Security information  Edit
Everyone can see this security related information.

Other bug subscribers