[pypy-svn] r16079 - in pypy/dist/pypy/module/_sre: . test

nik at codespeak.net nik at codespeak.net
Mon Aug 15 16:40:38 CEST 2005


Author: nik
Date: Mon Aug 15 16:40:37 2005
New Revision: 16079

Modified:
   pypy/dist/pypy/module/_sre/__init__.py
   pypy/dist/pypy/module/_sre/app_sre.py
   pypy/dist/pypy/module/_sre/interp_sre.py
   pypy/dist/pypy/module/_sre/test/test_interp_sre.py
Log:
moved getlower to interp-level


Modified: pypy/dist/pypy/module/_sre/__init__.py
==============================================================================
--- pypy/dist/pypy/module/_sre/__init__.py	(original)
+++ pypy/dist/pypy/module/_sre/__init__.py	Mon Aug 15 16:40:37 2005
@@ -14,10 +14,10 @@
         'copyright':      'app_info.copyright',
         'getcodesize':    'app_info.getcodesize',
         'compile':        'app_sre.compile',
-        'getlower':       'app_sre.getlower',
     }
 
     interpleveldefs = {
+        'getlower':       'interp_sre.getlower',
         '_check_charset': 'interp_sre.check_charset',
         '_at_dispatch':   'interp_sre.at_dispatch',
         '_category_dispatch': 'interp_sre.category_dispatch',

Modified: pypy/dist/pypy/module/_sre/app_sre.py
==============================================================================
--- pypy/dist/pypy/module/_sre/app_sre.py	(original)
+++ pypy/dist/pypy/module/_sre/app_sre.py	Mon Aug 15 16:40:37 2005
@@ -19,13 +19,6 @@
     """Compiles (or rather just converts) a pattern descriptor to a SRE_Pattern
     object. Actual compilation to opcodes happens in sre_compile."""
     return SRE_Pattern(pattern, flags, code, groups, groupindex, indexgroup)
-    
-def getlower(char_ord, flags):
-    if (char_ord < 128) or (flags & SRE_FLAG_UNICODE) \
-                              or (flags & SRE_FLAG_LOCALE and char_ord < 256):
-        return ord(unichr(char_ord).lower())
-    else:
-        return char_ord
 
 
 class SRE_Pattern(object):
@@ -455,7 +448,7 @@
         self.marks_stack.pop()
 
     def lower(self, char_ord):
-        return getlower(char_ord, self.flags)
+        return _sre.getlower(char_ord, self.flags)
 
 
 class _MatchContext(object):

Modified: pypy/dist/pypy/module/_sre/interp_sre.py
==============================================================================
--- pypy/dist/pypy/module/_sre/interp_sre.py	(original)
+++ pypy/dist/pypy/module/_sre/interp_sre.py	Mon Aug 15 16:40:37 2005
@@ -3,6 +3,23 @@
 from pypy.module._sre.app_info import CODESIZE
 from pypy.module.array.app_array import array
 
+#### Exposed functions
+
+# XXX can we import those safely from sre_constants?
+SRE_FLAG_LOCALE = 4 # honour system locale
+SRE_FLAG_UNICODE = 32 # use unicode locale
+
+def getlower(space, w_char_ord, w_flags):
+    char_ord = space.int_w(w_char_ord)
+    flags = space.int_w(w_flags)
+    if (char_ord < 128) or (flags & SRE_FLAG_UNICODE) \
+                              or (flags & SRE_FLAG_LOCALE and char_ord < 256):
+        w_uni_char = space.newunicode([char_ord])
+        w_lowered = space.call_method(w_uni_char, "lower")
+        return space.ord(w_lowered)
+    else:
+        return space.wrap(char_ord)
+
 #### Category helpers
 
 ascii_char_info = [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 6, 2,

Modified: pypy/dist/pypy/module/_sre/test/test_interp_sre.py
==============================================================================
--- pypy/dist/pypy/module/_sre/test/test_interp_sre.py	(original)
+++ pypy/dist/pypy/module/_sre/test/test_interp_sre.py	Mon Aug 15 16:40:37 2005
@@ -77,3 +77,6 @@
     for string, pos, end in [(".", 0, 1), (".", 1, 1), ("ab", 1, 2)]:
         assert not isre.at_boundary(space,
                         isre.MatchContext(space, [], space.wrap(string), pos, end))
+
+def test_getlower(space):
+    assert space.int_w(isre.getlower(space, space.wrap(ord("A")), space.wrap(0))) == ord("a")



More information about the Pypy-commit mailing list