[pypy-svn] r12510 - in pypy/branch/non-fake-unicode/pypy: documentation interpreter module/builtin objspace/std

ac at codespeak.net ac at codespeak.net
Thu May 19 13:45:40 CEST 2005


Author: ac
Date: Thu May 19 13:45:40 2005
New Revision: 12510

Modified:
   pypy/branch/non-fake-unicode/pypy/documentation/objspace.txt
   pypy/branch/non-fake-unicode/pypy/interpreter/baseobjspace.py
   pypy/branch/non-fake-unicode/pypy/module/builtin/__init__.py
   pypy/branch/non-fake-unicode/pypy/module/builtin/app_misc.py
   pypy/branch/non-fake-unicode/pypy/module/builtin/operation.py
   pypy/branch/non-fake-unicode/pypy/objspace/std/objspace.py
Log:
Added a method 'newunicode' to the objectspace.
Changed builtin unichr to use the method ad thereby getting 30 times faster.



Modified: pypy/branch/non-fake-unicode/pypy/documentation/objspace.txt
==============================================================================
--- pypy/branch/non-fake-unicode/pypy/documentation/objspace.txt	(original)
+++ pypy/branch/non-fake-unicode/pypy/documentation/objspace.txt	Thu May 19 13:45:40 2005
@@ -195,6 +195,9 @@
 **newstring(asciilist):**
   Creates a string from a list of wrapped integers.
 
+**newunicode(codelist):**
+  Creates a unicode string from a list of wrapped integers.
+
 Conversions from Application Level to Interpreter Level
 ----------------------------------------------------------
 

Modified: pypy/branch/non-fake-unicode/pypy/interpreter/baseobjspace.py
==============================================================================
--- pypy/branch/non-fake-unicode/pypy/interpreter/baseobjspace.py	(original)
+++ pypy/branch/non-fake-unicode/pypy/interpreter/baseobjspace.py	Thu May 19 13:45:40 2005
@@ -465,6 +465,7 @@
 #                  newtuple([w_1, w_2,...]) -> w_tuple
 #                   newlist([w_1, w_2,...]) -> w_list
 #                 newstring([w_1, w_2,...]) -> w_string from ascii numbers (bytes)
+#                newunicode([w_1, w_2,...]) -> w_unicode from numbers
 #            newdict([(w_key,w_value),...]) -> w_dict
 #           newslice(w_start,w_stop,w_step) -> w_slice (any argument may be a real None)
 #              call_args(w_obj,Arguments()) -> w_result
@@ -481,6 +482,7 @@
     'newtuple',
     'newlist',
     'newstring',
+    'newunicode',
     'newdict',
     'newslice',
     'call_args'

Modified: pypy/branch/non-fake-unicode/pypy/module/builtin/__init__.py
==============================================================================
--- pypy/branch/non-fake-unicode/pypy/module/builtin/__init__.py	(original)
+++ pypy/branch/non-fake-unicode/pypy/module/builtin/__init__.py	Thu May 19 13:45:40 2005
@@ -50,7 +50,6 @@
         'complex'       : 'app_complex.complex',
 
         'intern'        : 'app_misc.intern',
-        'unichr'        : 'app_misc.unichr',
         'buffer'        : 'app_buffer.buffer',
         'reload'        : 'app_misc.reload',
     }
@@ -79,6 +78,7 @@
         # interp-level function definitions
         'abs'           : 'operation.abs',
         'chr'           : 'operation.chr',
+        'unichr'        : 'operation.unichr',
         'len'           : 'operation.len',
         'ord'           : 'operation.ord',
         'pow'           : 'operation.pow',

Modified: pypy/branch/non-fake-unicode/pypy/module/builtin/app_misc.py
==============================================================================
--- pypy/branch/non-fake-unicode/pypy/module/builtin/app_misc.py	(original)
+++ pypy/branch/non-fake-unicode/pypy/module/builtin/app_misc.py	Thu May 19 13:45:40 2005
@@ -11,13 +11,6 @@
     return _stringtable.setdefault(s,s)
 
 
-def unichr(code):
-    import sys
-    if (code < 0 or code > sys.maxunicode):
-        raise ValueError('unichr() arg not in range(%#x)'%(sys.maxunicode + 1))
-    return unicode('\\U%08x' %(code), 'unicode-escape')
-
-
 def reload(module):
     import imp, sys, errno
 

Modified: pypy/branch/non-fake-unicode/pypy/module/builtin/operation.py
==============================================================================
--- pypy/branch/non-fake-unicode/pypy/module/builtin/operation.py	(original)
+++ pypy/branch/non-fake-unicode/pypy/module/builtin/operation.py	Thu May 19 13:45:40 2005
@@ -15,6 +15,9 @@
     w_character = space.newstring([w_ascii])
     return w_character
 
+def unichr(space, w_code):
+    return space.newunicode([w_code])
+
 def len(space, w_obj):
     "len(object) -> integer\n\nReturn the number of items of a sequence or mapping."
     return space.len(w_obj)

Modified: pypy/branch/non-fake-unicode/pypy/objspace/std/objspace.py
==============================================================================
--- pypy/branch/non-fake-unicode/pypy/objspace/std/objspace.py	(original)
+++ pypy/branch/non-fake-unicode/pypy/objspace/std/objspace.py	Thu May 19 13:45:40 2005
@@ -268,6 +268,14 @@
                                  self.wrap("character code not in range(256)"))
         return W_StringObject(self, ''.join(chars))
 
+    def newunicode(self, chars_w):
+        try:
+            chars = [unichr(self.int_w(w_c)) for w_c in chars_w]
+        except ValueError, e:  # unichr(out-of-range)
+            raise OperationError(self.w_ValueError,
+                                 self.wrap("character code not in range(0x110000)"))
+        return W_UnicodeObject(self, chars)
+
     def newseqiter(self, w_obj):
         return W_SeqIterObject(self, w_obj)
 



More information about the Pypy-commit mailing list