[pypy-commit] pypy py3k: add a new space method to unwrap unicode identifiers into UTF-8 encoded strings
antocuni
noreply at buildbot.pypy.org
Fri Aug 31 10:06:00 CEST 2012
Author: Antonio Cuni <anto.cuni at gmail.com>
Branch: py3k
Changeset: r57043:259f31766894
Date: 2012-08-31 09:47 +0200
http://bitbucket.org/pypy/pypy/changeset/259f31766894/
Log: add a new space method to unwrap unicode identifiers into UTF-8
encoded strings
diff --git a/pypy/interpreter/baseobjspace.py b/pypy/interpreter/baseobjspace.py
--- a/pypy/interpreter/baseobjspace.py
+++ b/pypy/interpreter/baseobjspace.py
@@ -1371,6 +1371,14 @@
self.wrap('argument must be a unicode'))
return self.unicode_w(w_obj)
+ def identifier_w(self, w_obj):
+ """
+ Unwrap an object which is used as an identifier (i.e. names of
+ variables, methdods, functions, classes etc.). In py3k, identifiers
+ are unicode strings and are unwrapped as UTF-8 encoded byte strings.
+ """
+ return self.unicode_w(w_obj).encode('utf-8')
+
def bool_w(self, w_obj):
# Unwraps a bool, also accepting an int for compatibility.
# This is here mostly just for gateway.int_unwrapping_space_method().
diff --git a/pypy/interpreter/test/test_objspace.py b/pypy/interpreter/test/test_objspace.py
--- a/pypy/interpreter/test/test_objspace.py
+++ b/pypy/interpreter/test/test_objspace.py
@@ -1,3 +1,4 @@
+# -*- encoding: utf-8 -*-
from py.test import raises
from pypy.interpreter.error import OperationError
from pypy.interpreter.function import Function
@@ -179,6 +180,12 @@
assert space.unicode0_w(w(u"123")) == u"123"
exc = space.raises_w(space.w_TypeError, space.unicode0_w, w(u"123\x004"))
+ def test_identifier_w(self):
+ space = self.space
+ x = u'àèì'
+ w_name = space.wrap(x)
+ assert space.identifier_w(w_name) == x.encode('utf-8')
+
def test_getindex_w(self):
w_instance1 = self.space.appexec([], """():
class X(object):
More information about the pypy-commit
mailing list