[pypy-svn] r48589 - pypy/branch/more-unicode-improvements/pypy/objspace/std
cfbolz at codespeak.net
cfbolz at codespeak.net
Mon Nov 12 01:40:07 CET 2007
Author: cfbolz
Date: Mon Nov 12 01:40:05 2007
New Revision: 48589
Modified:
pypy/branch/more-unicode-improvements/pypy/objspace/std/stringobject.py
Log:
move string.translate to interplevel
Modified: pypy/branch/more-unicode-improvements/pypy/objspace/std/stringobject.py
==============================================================================
--- pypy/branch/more-unicode-improvements/pypy/objspace/std/stringobject.py (original)
+++ pypy/branch/more-unicode-improvements/pypy/objspace/std/stringobject.py Mon Nov 12 01:40:05 2007
@@ -889,25 +889,28 @@
return space.wrap("".join(buf[:i+1])) # buffer was overallocated, so slice
-app = gateway.applevel(r'''
- def str_translate__String_ANY_ANY(s, table, deletechars=''):
- """charfilter - unicode handling is not implemented
-
- Return a copy of the string where all characters occurring
- in the optional argument deletechars are removed, and the
- remaining characters have been mapped through the given translation table,
- which must be a string of length 256"""
-
- if len(table) != 256:
- raise ValueError("translation table must be 256 characters long")
-
- L = [ table[ord(s[i])] for i in range(len(s)) if s[i] not in deletechars ]
- return ''.join(L)
-
-''', filename=__file__)
-
-
-str_translate__String_ANY_ANY = app.interphook('str_translate__String_ANY_ANY')
+def str_translate__String_ANY_ANY(space, w_string, w_table, w_deletechars=''):
+ """charfilter - unicode handling is not implemented
+
+ Return a copy of the string where all characters occurring
+ in the optional argument deletechars are removed, and the
+ remaining characters have been mapped through the given translation table,
+ which must be a string of length 256"""
+
+ # XXX CPython accepts buffers, too, not sure what we should do
+ table = space.str_w(w_table)
+ if len(table) != 256:
+ raise OperationError(
+ space.w_ValueError,
+ space.wrap("translation table must be 256 characters long"))
+
+ string = w_string._value
+ chars = []
+ for char in string:
+ w_char = W_StringObject.PREBUILT[ord(char)]
+ if not space.is_true(space.contains(w_deletechars, w_char)):
+ chars.append(table[ord(char)])
+ return W_StringObject(''.join(chars))
def str_decode__String_ANY_ANY(space, w_string, w_encoding=None, w_errors=None):
from pypy.objspace.std.unicodetype import _get_encoding_and_errors, \
More information about the Pypy-commit
mailing list