Commit 21e9c58b authored by Philip Thiem's avatar Philip Thiem

ensure write_manifest passes contents to write_file as unicode strings.

--HG--
extra : rebase_source : 719fb2eb2c3599c57d7a11f5fc55cf9a88d74df7
parent 0f0c8924
......@@ -10,7 +10,7 @@ from setuptools import Command
import distutils.errors
from distutils import log
from setuptools.command.sdist import sdist
from setuptools.compat import basestring
from setuptools.compat import basestring, unicode
from setuptools import svn_utils
from distutils.util import convert_path
from distutils.filelist import FileList as _FileList
......@@ -256,22 +256,37 @@ class manifest_maker(sdist):
by 'add_defaults()' and 'read_template()') to the manifest file
named by 'self.manifest'.
"""
# The manifest must be UTF-8 encodable. See #303.
if sys.version_info >= (3,):
files = []
for file in self.filelist.files:
#if files are byte codes they should be filesystem encoded
fs_enc = sys.getfilesystemencoding()
files = []
contents = []
for file in self.filelist.files:
#In order to ensure the encode behaves, must explicitly
#decode non-unicode strings, yet retain original for
#filelist cleanup
if not isinstance(file, unicode):
try:
file.encode("utf-8")
except UnicodeEncodeError:
log.warn("'%s' not UTF-8 encodable -- skipping" % file)
else:
files.append(file)
self.filelist.files = files
u_file = file.decode(fs_enc)
except UnicodeDecodeError:
log.warn("'%s' in unexpected encoding -- skipping" % file)
continue
else:
u_file = file
# The manifest must be UTF-8 encodable. See #303.
try:
u_file.encode("utf-8")
except UnicodeEncodeError:
log.warn("'%s' not UTF-8 encodable -- skipping" % file)
else:
files.append(file) # possibily byte encoded
contents.append(u_file) # unicode only
self.filelist.files = files
files = self.filelist.files
if os.sep!='/':
files = [f.replace(os.sep,'/') for f in files]
self.execute(write_file, (self.manifest, files),
contents = [f.replace(os.sep,'/') for f in contents]
self.execute(write_file, (self.manifest, contents),
"writing manifest file '%s'" % self.manifest)
def warn(self, msg): # suppress missing-file warnings from sdist
......
......@@ -156,10 +156,11 @@ class TestSdistTest(unittest.TestCase):
self.fail(e)
# The manifest should contain the UTF-8 filename
if sys.version_info >= (3,):
self.assertTrue(posix(filename) in u_contents)
else:
self.assertTrue(posix(filename) in contents)
if sys.version_info < (3,):
fs_enc = sys.getfilesystemencoding()
filename = filename.decode(fs_enc)
self.assertTrue(posix(filename) in u_contents)
# Python 3 only
if sys.version_info >= (3,):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment