Commit 0d962727 authored by Lennart Regebro's avatar Lennart Regebro

Issue #310: Non-ascii characters in a namespace __init__.py causes errors.

--HG--
branch : distribute
extra : rebase_source : 668e1c79a2bcc314bcf1f7213b317766bb8511ab
parent ea687a55
...@@ -15,6 +15,7 @@ CHANGES ...@@ -15,6 +15,7 @@ CHANGES
* Issue #307: Prints the full path when .svn/entries is broken. * Issue #307: Prints the full path when .svn/entries is broken.
* Issue #313: Support for sdist subcommands (Python 2.7) * Issue #313: Support for sdist subcommands (Python 2.7)
* Issue #314: test_local_index() would fail an OS X. * Issue #314: test_local_index() would fail an OS X.
* Issue #310: Non-ascii characters in a namespace __init__.py causes errors.
------ ------
0.6.28 0.6.28
......
...@@ -215,8 +215,8 @@ class build_py(_build_py, Mixin2to3): ...@@ -215,8 +215,8 @@ class build_py(_build_py, Mixin2to3):
else: else:
return init_py return init_py
f = open(init_py,'rU') f = open(init_py,'rbU')
if 'declare_namespace' not in f.read(): if 'declare_namespace'.encode() not in f.read():
from distutils import log from distutils import log
log.warn( log.warn(
"WARNING: %s is a namespace package, but its __init__.py does\n" "WARNING: %s is a namespace package, but its __init__.py does\n"
......
# -*- coding: UTF-8 -*-
"""develop tests """develop tests
""" """
import sys import sys
...@@ -21,13 +23,19 @@ setup(name='foo', ...@@ -21,13 +23,19 @@ setup(name='foo',
) )
""" """
NS_INIT = """ NS_INIT = """# -*- coding: Latin-1 -*-
# Söme Arbiträry Ünicode to test Issüé 310
try: try:
__import__('pkg_resources').declare_namespace(__name__) __import__('pkg_resources').declare_namespace(__name__)
except ImportError: except ImportError:
from pkgutil import extend_path from pkgutil import extend_path
__path__ = extend_path(__path__, __name__) __path__ = extend_path(__path__, __name__)
""" """
# Make sure this is Latin-1 binary, before writing:
if sys.version_info < (3,):
NS_INIT = NS_INIT.decode('UTF-8')
NS_INIT = NS_INIT.encode('Latin-1')
TEST_PY = """import unittest TEST_PY = """import unittest
class TestTest(unittest.TestCase): class TestTest(unittest.TestCase):
...@@ -50,23 +58,23 @@ class TestTestTest(unittest.TestCase): ...@@ -50,23 +58,23 @@ class TestTestTest(unittest.TestCase):
os.mkdir(os.path.join(self.dir, 'name', 'space', 'tests')) os.mkdir(os.path.join(self.dir, 'name', 'space', 'tests'))
# setup.py # setup.py
setup = os.path.join(self.dir, 'setup.py') setup = os.path.join(self.dir, 'setup.py')
f = open(setup, 'w') f = open(setup, 'wt')
f.write(SETUP_PY) f.write(SETUP_PY)
f.close() f.close()
self.old_cwd = os.getcwd() self.old_cwd = os.getcwd()
# name/__init__.py # name/__init__.py
init = os.path.join(self.dir, 'name', '__init__.py') init = os.path.join(self.dir, 'name', '__init__.py')
f = open(init, 'w') f = open(init, 'wb')
f.write(NS_INIT) f.write(NS_INIT)
f.close() f.close()
# name/space/__init__.py # name/space/__init__.py
init = os.path.join(self.dir, 'name', 'space', '__init__.py') init = os.path.join(self.dir, 'name', 'space', '__init__.py')
f = open(init, 'w') f = open(init, 'wt')
f.write('#empty\n') f.write('#empty\n')
f.close() f.close()
# name/space/tests/__init__.py # name/space/tests/__init__.py
init = os.path.join(self.dir, 'name', 'space', 'tests', '__init__.py') init = os.path.join(self.dir, 'name', 'space', 'tests', '__init__.py')
f = open(init, 'w') f = open(init, 'wt')
f.write(TEST_PY) f.write(TEST_PY)
f.close() f.close()
...@@ -105,7 +113,7 @@ class TestTestTest(unittest.TestCase): ...@@ -105,7 +113,7 @@ class TestTestTest(unittest.TestCase):
cmd.install_dir = site.USER_SITE cmd.install_dir = site.USER_SITE
cmd.user = 1 cmd.user = 1
old_stdout = sys.stdout old_stdout = sys.stdout
sys.stdout = StringIO() #sys.stdout = StringIO()
try: try:
try: # try/except/finally doesn't work in Python 2.4, so we need nested try-statements. try: # try/except/finally doesn't work in Python 2.4, so we need nested try-statements.
cmd.run() cmd.run()
...@@ -113,3 +121,4 @@ class TestTestTest(unittest.TestCase): ...@@ -113,3 +121,4 @@ class TestTestTest(unittest.TestCase):
pass pass
finally: finally:
sys.stdout = old_stdout sys.stdout = old_stdout
\ No newline at end of file
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