[pypy-svn] rev 739 - pypy/trunk/src/pypy/objspace/std

tomek at codespeak.net tomek at codespeak.net
Fri May 30 20:28:40 CEST 2003


Author: tomek
Date: Fri May 30 20:28:38 2003
New Revision: 739

Modified:
   pypy/trunk/src/pypy/objspace/std/stringobject.py
   pypy/trunk/src/pypy/objspace/std/stringtype.py
Log:
small changes...


Modified: pypy/trunk/src/pypy/objspace/std/stringobject.py
==============================================================================
--- pypy/trunk/src/pypy/objspace/std/stringobject.py	(original)
+++ pypy/trunk/src/pypy/objspace/std/stringobject.py	Fri May 30 20:28:38 2003
@@ -30,56 +30,56 @@
     def hash(w_self):
         return W_IntObject(self, self._value.hash())
 
-    def _char_isspace(ch):
-        return ord(ch) in (9, 10, 11, 12, 13, 32)  
+def _isspace(ch):
+    return ord(ch) in (9, 10, 11, 12, 13, 32)  
 
-    def is_generic(w_self, fun): 
-        space = w_self.space   
-        v = w_self._value
-        if v.len == 0:
-            return space.w_False
-        if v.len == 1:
-            c = v.charat(0)
-            return space.newbool(fun(c))
-        else:
-            res = 1
-            for idx in range(v.len):
-                if not fun(v.charat(idx)):
-                    return space.w_False
-            return space.w_True
+def _isdigit(ch):
+    o = ord(ch)
+    return o >= 48 and o <= 57
+
+def _isalpha(ch):
+    o = ord(ch)
+    return (o>=97 and o<=122) or (o>=65 and o<=90)
+
+def _isalnum(ch):
+    o = ord(ch)
+    return (o>=97 and o<=122) \
+        or (o>=65 and o<=90) \
+        or (o>=48 and o<=57)
+
+
+def _is_generic(w_self, fun): 
+    space = w_self.space   
+    v = w_self._value
+    if v.len == 0:
+        return space.w_False
+    if v.len == 1:
+        c = v.charat(0)
+        return space.newbool(fun(c))
+    else:
+        res = 1
+        for idx in range(v.len):
+            if not fun(v.charat(idx)):
+                return space.w_False
+        return space.w_True
+
+def str_isspace(space, w_self):
+    return _is_generic(w_self, _isspace)
 
-    def isspace(w_self):
-       return is_generic(w_self, _char_isspace)
-   ## XXX fixme
-
-##    def isdigit(w_self):
-##        pass
-
-##    def isupper(w_self):
-##        pass
-
-##    def isupper(w_self):
-##        pass
-    
-##    def islower(w_self):
-##        pass
-
-##    def istitle(w_self):
-##        pass
-
-##    def isalnum(w_self):
-##        pass
-
-##    def isalpha(w_self):
-##        pass
-
-##    isspace = implmethod().register(isspace)
-##    isdigit = implmethod().register(isdigit)
-##    isupper = implmethod().register(isupper)
-##    islower = implmethod().register(islower)
-##    istitle = implmethod().register(istitle)
-##    isalnum = implmethod().register(isalnum)
-##    isalpha = implmethod().register(isalpha)
+def str_isdigit(space, w_self):
+    return _is_generic(w_self, _isdigit)
+
+def str_isalpha(space, w_self):
+    return _is_generic(w_self, _isalpha)
+
+def str_isalnum(space, w_self):
+    return _is_generic(w_self, _isalnum)
+
+def str_isupper(space, w_self):
+    return _is_generic(w_self, _isupper)
+
+def str_islower(space, w_self):
+    return _is_generic(w_self, _islower)
 
 
 def str_splitByWhitespace(space, w_self, w_none):
@@ -124,6 +124,9 @@
 #the same number of parameters. So you have to call split with
 #None as parameter instead of calling it without any parameter
 
+W_StringType.str_isspace.register(str_isspace, W_StringObject)
+W_StringType.str_isdigit.register(str_isdigit, W_StringObject)
+
 
 def str_join(space, w_self, w_list):
     list = space.unpackiterable(w_list)

Modified: pypy/trunk/src/pypy/objspace/std/stringtype.py
==============================================================================
--- pypy/trunk/src/pypy/objspace/std/stringtype.py	(original)
+++ pypy/trunk/src/pypy/objspace/std/stringtype.py	Fri May 30 20:28:38 2003
@@ -1,4 +1,4 @@
-from pypy.objspace.std.objspace import *
+from pypy.objspace.std.objspace import MultiMethod, StdObjSpace, W_ANY
 from typeobject import W_TypeObject
 
 
@@ -6,9 +6,16 @@
 
     typename = 'str'
 
-    str_join  = MultiMethod('join', 2)
-    str_split = MultiMethod('split', 2)
+    str_join    = MultiMethod('join', 2)
+    str_split   = MultiMethod('split', 2)
 
+    str_isdigit = MultiMethod('isdigit', 1)
+    str_isalpha = MultiMethod('isalpha', 1)
+    str_isspace = MultiMethod('isspace', 1)
+    str_isupper = MultiMethod('isupper', 1)
+    str_islower = MultiMethod('islower', 1)
+    str_istitle = MultiMethod('istitle', 1)
+    str_isalnum = MultiMethod('isalnum', 1)
 
 # XXX we'll worry about the __new__/__init__ distinction later
 def stringtype_new(space, w_stringtype, w_args, w_kwds):


More information about the Pypy-commit mailing list