[Python-checkins] cpython: Issue #12112: packaging reads/writes metadata using UTF-8

victor.stinner python-checkins at python.org
Thu May 19 18:50:25 CEST 2011


http://hg.python.org/cpython/rev/01d61096140a
changeset:   70205:01d61096140a
user:        Victor Stinner <victor.stinner at haypocalc.com>
date:        Thu May 19 18:49:56 2011 +0200
summary:
  Issue #12112: packaging reads/writes metadata using UTF-8

files:
  Lib/packaging/metadata.py            |   4 ++--
  Lib/packaging/tests/test_dist.py     |   2 +-
  Lib/packaging/tests/test_metadata.py |  12 ++++++------
  3 files changed, 9 insertions(+), 9 deletions(-)


diff --git a/Lib/packaging/metadata.py b/Lib/packaging/metadata.py
--- a/Lib/packaging/metadata.py
+++ b/Lib/packaging/metadata.py
@@ -307,7 +307,7 @@
 
     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 @@
 
     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):
diff --git a/Lib/packaging/tests/test_dist.py b/Lib/packaging/tests/test_dist.py
--- a/Lib/packaging/tests/test_dist.py
+++ b/Lib/packaging/tests/test_dist.py
@@ -78,7 +78,7 @@
         # 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
diff --git a/Lib/packaging/tests/test_metadata.py b/Lib/packaging/tests/test_metadata.py
--- a/Lib/packaging/tests/test_metadata.py
+++ b/Lib/packaging/tests/test_metadata.py
@@ -17,7 +17,7 @@
 
     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 @@
     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 @@
 
     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 @@
 
     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 @@
 
         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')

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list