]> granicus.if.org Git - python/commitdiff
Issue #12112: packaging reads/writes metadata using UTF-8
authorVictor Stinner <victor.stinner@haypocalc.com>
Thu, 19 May 2011 16:49:56 +0000 (18:49 +0200)
committerVictor Stinner <victor.stinner@haypocalc.com>
Thu, 19 May 2011 16:49:56 +0000 (18:49 +0200)
Lib/packaging/metadata.py
Lib/packaging/tests/test_dist.py
Lib/packaging/tests/test_metadata.py

index 8abbe384a726d8fc71351544b95582fa40f58d80..596eec796a84372cb69e27add91b748d1e12c966 100644 (file)
@@ -307,7 +307,7 @@ class Metadata:
 
     def read(self, filepath):
         """Read the metadata values from a file path."""
-        with open(filepath, 'r', encoding='ascii') as fp:
+        with open(filepath, 'r', encoding='utf-8') as fp:
             self.read_file(fp)
 
     def read_file(self, fileob):
@@ -330,7 +330,7 @@ class Metadata:
 
     def write(self, filepath):
         """Write the metadata fields to filepath."""
-        with open(filepath, 'w') as fp:
+        with open(filepath, 'w', encoding='utf-8') as fp:
             self.write_file(fp)
 
     def write_file(self, fileobject):
index 36b64f90c95e148b78ece80ebfa4a0659bf047e5..74c727bf5eba80a8a6a8e28e71fb1d8e9cb36fa4 100644 (file)
@@ -78,7 +78,7 @@ class DistributionTestCase(support.TempdirManager,
         # let's make sure the file can be written
         # with Unicode fields. they are encoded with
         # PKG_INFO_ENCODING
-        with open(my_file, 'w') as fp:
+        with open(my_file, 'w', encoding='utf-8') as fp:
             dist.metadata.write_file(fp)
 
         # regular ascii is of course always usable
index b8dc5d8b06f134b181e577a777c2143cb1654e84..904019c34e231300fe3f079c824c3014ffa9e6da 100644 (file)
@@ -17,7 +17,7 @@ class MetadataTestCase(LoggingCatcher,
 
     def test_instantiation(self):
         PKG_INFO = os.path.join(os.path.dirname(__file__), 'PKG-INFO')
-        with open(PKG_INFO, 'r') as f:
+        with open(PKG_INFO, 'r', encoding='utf-8') as f:
             contents = f.read()
         fp = StringIO(contents)
 
@@ -57,7 +57,7 @@ class MetadataTestCase(LoggingCatcher,
     def test_metadata_markers(self):
         # see if we can be platform-aware
         PKG_INFO = os.path.join(os.path.dirname(__file__), 'PKG-INFO')
-        with open(PKG_INFO, 'r') as f:
+        with open(PKG_INFO, 'r', encoding='utf-8') as f:
             content = f.read() % sys.platform
         metadata = Metadata(platform_dependent=True)
 
@@ -77,7 +77,7 @@ class MetadataTestCase(LoggingCatcher,
 
     def test_description(self):
         PKG_INFO = os.path.join(os.path.dirname(__file__), 'PKG-INFO')
-        with open(PKG_INFO, 'r') as f:
+        with open(PKG_INFO, 'r', encoding='utf-8') as f:
             content = f.read() % sys.platform
         metadata = Metadata()
         metadata.read_file(StringIO(content))
@@ -97,7 +97,7 @@ class MetadataTestCase(LoggingCatcher,
 
     def test_mapping_api(self):
         PKG_INFO = os.path.join(os.path.dirname(__file__), 'PKG-INFO')
-        with open(PKG_INFO, 'r') as f:
+        with open(PKG_INFO, 'r', encoding='utf-8') as f:
             content = f.read() % sys.platform
         metadata = Metadata(fileobj=StringIO(content))
         self.assertIn('Version', metadata.keys())
@@ -130,14 +130,14 @@ class MetadataTestCase(LoggingCatcher,
 
         PKG_INFO = os.path.join(os.path.dirname(__file__),
                                 'SETUPTOOLS-PKG-INFO')
-        with open(PKG_INFO, 'r') as f:
+        with open(PKG_INFO, 'r', encoding='utf-8') as f:
             content = f.read()
         metadata.read_file(StringIO(content))
         self.assertEqual(metadata['Metadata-Version'], '1.0')
 
         PKG_INFO = os.path.join(os.path.dirname(__file__),
                                 'SETUPTOOLS-PKG-INFO2')
-        with open(PKG_INFO, 'r') as f:
+        with open(PKG_INFO, 'r', encoding='utf-8') as f:
             content = f.read()
         metadata.read_file(StringIO(content))
         self.assertEqual(metadata['Metadata-Version'], '1.1')