Created
May 26, 2010 22:02
-
-
Save srid/415137 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/pkginfo/distribution.py b/pkginfo/distribution.py | |
index b1f3d7d..7895c2a 100644 | |
--- a/pkginfo/distribution.py | |
+++ b/pkginfo/distribution.py | |
@@ -1,5 +1,9 @@ | |
-import rfc822 | |
-import StringIO | |
+from email.parser import Parser | |
+try: | |
+ from StringIO import StringIO | |
+except ImportError: | |
+ from io import StringIO | |
+ | |
HEADER_ATTRS_1_0 = ( # PEP 241 | |
('Metadata-Version', 'metadata_version', False), | |
@@ -80,11 +84,11 @@ class Distribution(object): | |
return HEADER_ATTRS.get(self.metadata_version, []) | |
def parse(self, data): | |
- fp = StringIO.StringIO(data) | |
- message = rfc822.Message(fp) | |
+ fp = StringIO(data) | |
+ msg = Parser().parse(fp) | |
- if 'Metadata-Version' in message and self.metadata_version is None: | |
- value = message.getheader('Metadata-Version') | |
+ if 'Metadata-Version' in msg and self.metadata_version is None: | |
+ value = msg.get('Metadata-Version') | |
metadata_version = self.metadata_version = value | |
for header_name, attr_name, multiple in self._getHeaderAttrs(): | |
@@ -92,12 +96,12 @@ class Distribution(object): | |
if attr_name == 'metadata_version': | |
continue | |
- if header_name in message: | |
+ if header_name in msg: | |
if multiple: | |
- values = message.getheaders(header_name) | |
+ values = msg.get_all(header_name) | |
setattr(self, attr_name, values) | |
else: | |
- value = message.getheader(header_name) | |
+ value = msg.get(header_name) | |
if value != 'UNKNOWN': | |
setattr(self, attr_name, value) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment