Index: Lib/distutils/tests/test_dist.py =================================================================== --- Lib/distutils/tests/test_dist.py (revision 66030) +++ Lib/distutils/tests/test_dist.py (working copy) @@ -1,3 +1,4 @@ +# -*- coding: utf-8 -*- """Tests for distutils.dist.""" import distutils.cmd @@ -95,6 +96,44 @@ finally: os.unlink(TESTFN) + def test_write_pkg_file(self): + # DistributionMetadata now stores some fields + # in Unicode : + # - author + # - maintainer + # - description + # - long_description + my_file = os.path.join(os.path.dirname(__file__), 'f') + klass = distutils.dist.Distribution + + dist = klass(attrs={'author': u'Mister Café', + 'name': 'my.package', + 'maintainer': u'Café Junior', + 'description': u'Café torréfié', + 'long_description': u'Héhéhé'}) + + + # let's make sure the file can be written + # with Unicode fields. they are encoded with + # dist.metadata.encoding (defaults to utf8) + try: + dist.metadata.write_pkg_file(open(my_file, 'w')) + finally: + if os.path.exists(my_file): + os.remove(my_file) + + # regular ascii is of course always usable + dist = klass(attrs={'author': 'Mister Cafe', + 'name': 'my.package', + 'maintainer': 'Cafe Junior', + 'description': 'Cafe torrefie', + 'long_description': 'Hehehe'}) + + try: + dist.metadata.write_pkg_file(open(my_file, 'w')) + finally: + if os.path.exists(my_file): + os.remove(my_file) class MetadataTestCase(unittest.TestCase): Index: Lib/distutils/dist.py =================================================================== --- Lib/distutils/dist.py (revision 66030) +++ Lib/distutils/dist.py (working copy) @@ -1047,16 +1047,19 @@ ) def __init__ (self): + # Unicode strings + self.author = None + self.maintainer = None + self.description = None + self.long_description = None + + # ASCII strings self.name = None self.version = None - self.author = None self.author_email = None - self.maintainer = None self.maintainer_email = None self.url = None self.license = None - self.description = None - self.long_description = None self.keywords = None self.platforms = None self.classifiers = None @@ -1087,15 +1090,18 @@ file.write('Metadata-Version: %s\n' % version) file.write('Name: %s\n' % self.get_name() ) file.write('Version: %s\n' % self.get_version() ) - file.write('Summary: %s\n' % self.get_description() ) + desc = self._encode_field(self.get_description()) + file.write('Summary: %s\n' % desc) file.write('Home-page: %s\n' % self.get_url() ) - file.write('Author: %s\n' % self.get_contact() ) + contact = self._encode_field(self.get_contact()) + file.write('Author: %s\n' % contact ) file.write('Author-email: %s\n' % self.get_contact_email() ) file.write('License: %s\n' % self.get_license() ) if self.download_url: file.write('Download-URL: %s\n' % self.download_url) - long_desc = rfc822_escape( self.get_long_description() ) + long_desc = self._encode_field(self.get_long_description()) + long_desc = rfc822_escape(long_desc) file.write('Description: %s\n' % long_desc) keywords = string.join( self.get_keywords(), ',') @@ -1114,6 +1120,11 @@ for value in values: file.write('%s: %s\n' % (name, value)) + def _encode_field(self, value): + """Will encode the value""" + # forces to utf8 + return value.encode('utf8') + # -- Metadata query methods ---------------------------------------- def get_name (self): @@ -1126,13 +1137,13 @@ return "%s-%s" % (self.get_name(), self.get_version()) def get_author(self): - return self.author or "UNKNOWN" + return self.author or u"UNKNOWN" def get_author_email(self): return self.author_email or "UNKNOWN" def get_maintainer(self): - return self.maintainer or "UNKNOWN" + return self.maintainer or u"UNKNOWN" def get_maintainer_email(self): return self.maintainer_email or "UNKNOWN" @@ -1140,7 +1151,7 @@ def get_contact(self): return (self.maintainer or self.author or - "UNKNOWN") + u"UNKNOWN") def get_contact_email(self): return (self.maintainer_email or @@ -1155,10 +1166,10 @@ get_licence = get_license def get_description(self): - return self.description or "UNKNOWN" + return self.description or u"UNKNOWN" def get_long_description(self): - return self.long_description or "UNKNOWN" + return self.long_description or u"UNKNOWN" def get_keywords(self): return self.keywords or [] Index: Lib/test/test_distutils.py =================================================================== --- Lib/test/test_distutils.py (revision 66030) +++ Lib/test/test_distutils.py (working copy) @@ -4,7 +4,6 @@ the test_suite() function there returns a test suite that's ready to be run. """ - import distutils.tests import test.test_support