[pypy-svn] r73830 - in pypy/trunk/pypy/interpreter: . test

fijal at codespeak.net fijal at codespeak.net
Sat Apr 17 20:13:10 CEST 2010


Author: fijal
Date: Sat Apr 17 20:13:08 2010
New Revision: 73830

Modified:
   pypy/trunk/pypy/interpreter/baseobjspace.py
   pypy/trunk/pypy/interpreter/gateway.py
   pypy/trunk/pypy/interpreter/test/test_gateway.py
Log:
Add a path_w method that would encode unicode using filesystemencoding and
add that to gateway


Modified: pypy/trunk/pypy/interpreter/baseobjspace.py
==============================================================================
--- pypy/trunk/pypy/interpreter/baseobjspace.py	(original)
+++ pypy/trunk/pypy/interpreter/baseobjspace.py	Sat Apr 17 20:13:08 2010
@@ -1095,6 +1095,18 @@
                                  self.wrap('argument must be a unicode'))
         return self.unicode_w(w_obj)
 
+    def path_w(space, w_obj):
+        """ Like str_w, but if the object is unicode, encode it using
+        filesystemencoding
+        """
+        filesystemencoding = space.sys.filesystemencoding
+        if (filesystemencoding and
+            space.is_true(space.isinstance(w_obj, space.w_unicode))):
+            w_obj = space.call_function(space.getattr(w_obj,
+                                                      space.wrap('encode')),
+                                        space.wrap(filesystemencoding))
+        return space.str_w(w_obj)
+
     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().

Modified: pypy/trunk/pypy/interpreter/gateway.py
==============================================================================
--- pypy/trunk/pypy/interpreter/gateway.py	(original)
+++ pypy/trunk/pypy/interpreter/gateway.py	Sat Apr 17 20:13:08 2010
@@ -137,6 +137,9 @@
     def visit_c_nonnegint(self, el, app_sig):
         self.checked_space_method(el, app_sig)
 
+    def visit_path(self, el, app_sig):
+        self.checked_space_method(el, app_sig)
+
     def visit__Wrappable(self, el, app_sig):
         name = el.__name__
         argname = self.orig_arg()
@@ -238,6 +241,9 @@
     def visit_bufferstr(self, typ):
         self.run_args.append("space.bufferstr_w(%s)" % (self.scopenext(),))
 
+    def visit_path(self, typ):
+        self.run_args.append("space.path_w(%s)" % (self.scopenext(),))
+
     def visit_nonnegint(self, typ):
         self.run_args.append("space.nonnegint_w(%s)" % (self.scopenext(),))
 
@@ -365,6 +371,9 @@
     def visit_bufferstr(self, typ):
         self.unwrap.append("space.bufferstr_w(%s)" % (self.nextarg(),))
 
+    def visit_path(self, typ):
+        self.unwrap.append("space.path_w(%s)" % (self.nextarg(),))
+
     def visit_nonnegint(self, typ):
         self.unwrap.append("space.nonnegint_w(%s)" % (self.nextarg(),))
 

Modified: pypy/trunk/pypy/interpreter/test/test_gateway.py
==============================================================================
--- pypy/trunk/pypy/interpreter/test/test_gateway.py	(original)
+++ pypy/trunk/pypy/interpreter/test/test_gateway.py	Sat Apr 17 20:13:08 2010
@@ -1,3 +1,6 @@
+
+# -*- coding: utf-8 -*-
+
 from pypy.conftest import gettestobjspace
 from pypy.interpreter import gateway
 from pypy.interpreter import argument
@@ -451,6 +454,15 @@
         assert len(l) == 1
         assert space.eq_w(l[0], w("foo"))
 
+    def test_interp2app_unwrap_spec_path(self):
+        space = self.space
+        def g(space, p):
+            return p
+
+        app_g = gateway.interp2app(g, unwrap_spec=[gateway.ObjSpace, 'path'])
+        w_app_g = space.wrap(app_g)
+        w_res = space.call_function(w_app_g, space.wrap(u"ą"))
+
     def test_interp2app_classmethod(self):
         space = self.space
         w = space.wrap



More information about the Pypy-commit mailing list