Author: Philip Jenvey <[email protected]>
Branch: py3k
Changeset: r64696:dd88d8fe7adf
Date: 2013-05-31 13:51 -0700
http://bitbucket.org/pypy/pypy/changeset/dd88d8fe7adf/

Log:    fix identifier handling in module's repr

diff --git a/pypy/interpreter/module.py b/pypy/interpreter/module.py
--- a/pypy/interpreter/module.py
+++ b/pypy/interpreter/module.py
@@ -112,14 +112,14 @@
     def descr_module__repr__(self, space):
         from pypy.interpreter.mixedmodule import MixedModule
         if self.w_name is not None:
-            name = space.str_w(space.repr(self.w_name))
+            name = space.unicode_w(space.repr(self.w_name))
         else:
-            name = "'?'"
+            name = u"'?'"
         if isinstance(self, MixedModule):
-            return space.wrap("<module %s (built-in)>" % name)
+            return space.wrap(u"<module %s (built-in)>" % name)
         try:
             w___file__ = space.getattr(self, space.wrap('__file__'))
-            __file__ = space.str_w(space.repr(w___file__))
+            __file__ = space.unicode_w(space.repr(w___file__))
         except OperationError:
-            __file__ = '?'
-        return space.wrap("<module %s from %s>" % (name, __file__))
+            __file__ = u'?'
+        return space.wrap(u"<module %s from %s>" % (name, __file__))
diff --git a/pypy/interpreter/test/test_module.py 
b/pypy/interpreter/test/test_module.py
--- a/pypy/interpreter/test/test_module.py
+++ b/pypy/interpreter/test/test_module.py
@@ -1,4 +1,4 @@
-
+# encoding: utf-8
 from pypy.interpreter.module import Module
 
 class TestModule: 
@@ -75,3 +75,9 @@
         assert sys.__package__ is None
         assert os.__package__ is None
         assert not hasattr(type(sys)('foo'), '__package__')
+
+    def test_name_nonascii(self):
+        import sys
+        m = type(sys)('&#26085;&#26412;')
+        assert m.__name__ == '&#26085;&#26412;'
+        assert repr(m).startswith("<module '&#26085;&#26412;'")
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to