Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(401)

Unified Diff: Lib/packaging/metadata.py

Issue 12112: The new packaging module should not use the locale encoding
Patch Set: Created 2 years ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Lib/packaging/create.py ('k') | Lib/packaging/tests/support.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
--- a/Lib/packaging/metadata.py
+++ b/Lib/packaging/metadata.py
@@ -3,6 +3,7 @@
Supports all metadata formats (1.0, 1.1, 1.2).
"""
+import codecs
import re
import logging
@@ -330,11 +331,16 @@ 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):
"""Write the PKG-INFO format data to a file object."""
+ if not isinstance(fileobject, StringIO):
+ encoding = codecs.lookup(fileobject.encoding).name
+ if encoding != 'utf-8':
+ raise ValueError("Output file should be a UTF-8 text file, not %s encoding" % encoding)
+
self._set_best_version()
for field in _version2fieldlist(self['Metadata-Version']):
values = self.get(field)
« no previous file with comments | « Lib/packaging/create.py ('k') | Lib/packaging/tests/support.py » ('j') | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld cbc36f91f3f7