]> granicus.if.org Git - python/commitdiff
Use re in stead of regex, so we get rid of the annoying warning during startup.
authorJack Jansen <jack.jansen@cwi.nl>
Wed, 21 Feb 2001 13:54:31 +0000 (13:54 +0000)
committerJack Jansen <jack.jansen@cwi.nl>
Wed, 21 Feb 2001 13:54:31 +0000 (13:54 +0000)
Mac/Tools/IDE/PyBrowser.py
Mac/Tools/IDE/PyDocSearch.py
Mac/Tools/IDE/PyEdit.py
Mac/Tools/IDE/PyFontify.py
Mac/Tools/IDE/Wtext.py

index c1abbacfd129d32ae4a47d5ea186ce37fc3be7c5..853392f5256fe28bfff946d89512261c91ea0d1a 100644 (file)
@@ -3,7 +3,7 @@ import Wkeys
 import struct
 import string
 import types
-import regex
+import re
 
 nullid = '\0\0'
 closedid = struct.pack('h', 468)
@@ -13,11 +13,15 @@ opensolidid = struct.pack('h', 471)
 
 arrows = (nullid, closedid, openid, closedsolidid, opensolidid)
 
-has_ctlcharsRE = regex.compile('[\000-\037\177-\377]')
-
+has_ctlcharsRE = re.compile('[\000-\037\177-\377]')
+def ctlcharsREsearch(str):
+       if has_ctlcharsRE(str) is None:
+               return -1
+       return 1
+       
 def double_repr(key, value, truncvalue = 0, 
                        type = type, StringType = types.StringType,
-                       has_ctlchars = has_ctlcharsRE.search, _repr = repr, str = str):
+                       has_ctlchars = ctlcharsREsearch, _repr = repr, str = str):
        if type(key) == StringType and has_ctlchars(key) < 0:
                key = str(key)
        else:
index f975026d087daed957b2298f2d8d62ececff25fb..b036556da11ce26785c29d6d74a3eeb54b1881ee 100644 (file)
@@ -2,7 +2,7 @@ import aetools
 import Standard_Suite
 import Required_Suite
 import WWW_Suite
-import regex
+import re
 import W
 import macfs
 import os
@@ -29,16 +29,16 @@ app = W.getapplication()
 #SIGNATURE='MSIE' # MS Explorer
 SIGNATURE='MOSS' # Netscape
 
-_titlepat = regex.compile('<title>\([^<]*\)</title>')
+_titlepat = re.compile('<title>\([^<]*\)</title>')
 
 def sucktitle(path):
        f = open(path)
        text = f.read(1024) # assume the title is in the first 1024 bytes
        f.close()
        lowertext = string.lower(text)
-       if _titlepat.search(lowertext) > 0:
-               a, b = _titlepat.regs[1]
-               return text[a:b]
+       matcher = _titlepat.search(lowertext)
+       if matcher:
+               return matcher.group(1)
        return path
 
 def verifydocpath(docpath):
index 7274a1eedf0e442c06cce4dac79d5e976896f5c5..fc8503aa9a1086700bfd00e94b5c455af0f73804 100644 (file)
@@ -15,7 +15,7 @@ import imp
 import sys
 import string
 import marshal
-import regex
+import re
 
 try:
        import Wthreading
@@ -25,7 +25,8 @@ else:
        haveThreading = Wthreading.haveThreading
 
 _scriptuntitledcounter = 1
-_wordchars = string.letters + string.digits + "_"
+# _wordchars = string.letters + string.digits + "_"
+_wordchars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_'
 
 
 runButtonLabels = ["Run all", "Stop!"]
@@ -553,7 +554,6 @@ class Editor(W.Window):
                if indent == 1:
                        classname = ''
                        alllines = string.split(alltext, '\r')
-                       identifieRE_match = _identifieRE.match
                        for i in range(selfirstline - 1, -1, -1):
                                line = alllines[i]
                                if line[:6] == 'class ':
@@ -673,7 +673,6 @@ class Editor(W.Window):
        
        def getclasslist(self):
                from string import find, strip
-               import re
                methodRE = re.compile(r"\r[ \t]+def ")
                findMethod = methodRE.search
                editor = self.editgroup.editor
@@ -715,7 +714,6 @@ class Editor(W.Window):
                offsetToLine = editor.ted.WEOffsetToLine
                getLineRange = editor.ted.WEGetLineRange
                append = classlist.append
-               identifieRE_match = _identifieRE.match
                for pos, tag in list:
                        lineno = offsetToLine(pos)
                        lineStart, lineEnd = getLineRange(lineno)
@@ -794,14 +792,13 @@ def _makewholewordpattern(word):
        # first, escape special regex chars
        for esc in "\\[].*^+$?":
                word = _escape(word, esc)
-       import regex
        notwordcharspat = '[^' + _wordchars + ']'
-       pattern = '\(' + word + '\)'
+       pattern = '(' + word + ')'
        if word[0] in _wordchars:
                pattern = notwordcharspat + pattern
        if word[-1] in _wordchars:
                pattern = pattern + notwordcharspat
-       return regex.compile(pattern)
+       return re.compile(pattern)
 
 class SearchEngine:
        
@@ -935,9 +932,9 @@ class SearchEngine:
                while 1:
                        if self.parms["wholeword"]:
                                wholewordRE = _makewholewordpattern(find)
-                               wholewordRE.search(text, pos)
-                               if wholewordRE.regs:
-                                       pos = wholewordRE.regs[1][0]
+                               match = wholewordRE.search(text, pos)
+                               if match:
+                                       pos = match.start(1)
                                else:
                                        pos = -1
                        else:
@@ -997,9 +994,9 @@ class SearchEngine:
                selstart, selend = min(selstart, selend), max(selstart, selend)
                if self.parms["wholeword"]:
                        wholewordRE = _makewholewordpattern(find)
-                       wholewordRE.search(text, selend)
-                       if wholewordRE.regs:
-                               pos = wholewordRE.regs[1][0]
+                       match = wholewordRE.search(text, selend)
+                       if match:
+                               pos = match.start(1)
                        else:
                                pos = -1
                else:
@@ -1009,9 +1006,9 @@ class SearchEngine:
                        return 1
                elif self.parms["wrap"]:
                        if self.parms["wholeword"]:
-                               wholewordRE.search(text, 0)
-                               if wholewordRE.regs:
-                                       pos = wholewordRE.regs[1][0]
+                               match = wholewordRE.search(text, 0)
+                               if match:
+                                       pos = match.start(1)
                                else:
                                        pos = -1
                        else:
@@ -1169,12 +1166,19 @@ def execstring(pytext, globals, locals, filename="<string>", debugging=0,
                PyDebugger.stop()
 
 
-_identifieRE = regex.compile("[A-Za-z_][A-Za-z_0-9]*")
+_identifieRE = re.compile("[A-Za-z_][A-Za-z_0-9]*")
+
+def identifieRE_match(str):
+       match = _identifieRE.match(str)
+       if not match:
+               return -1
+       return match.end()
 
 def _filename_as_modname(fname):
        if fname[-3:] == '.py':
                modname = fname[:-3]
-               if _identifieRE.match(modname) == len(modname):
+               match = _identifieRE.match(modname)
+               if match and match.start() == 0 and match.end() == len(modname):
                        return string.join(string.split(modname, '.'), '_')
 
 def findeditor(topwindow, fromtop = 0):
index 02de08e0b3ccbc56617e542853b67e4ca127520b..b5d6102777138b228739da39ccc0a2338aab40c4 100644 (file)
@@ -27,7 +27,7 @@ sublist is not used, hence always None.
 
 __version__ = "0.3.3"
 
-import string, regex
+import string, re
 
 # First a little helper, since I don't like to repeat things. (Tismer speaking)
 import string
@@ -87,10 +87,10 @@ for keyword in keywordsList:
 keyPat = keyPat[:-2] + "\)" + nonKeyPat
 
 matchPat = commentPat + "\|" + keyPat + "\|" + tripleQuotePat + "\|" + quotePat
-matchRE = regex.compile(matchPat)
+matchRE = re.compile(matchPat)
 
 idKeyPat = "[ \t]*[A-Za-z_][A-Za-z_0-9.]*"     # Ident w. leading whitespace.
-idRE = regex.compile(idKeyPat)
+idRE = re.compile(idKeyPat)
 
 
 def fontify(pytext, searchfrom = 0, searchto = None):
@@ -98,9 +98,7 @@ def fontify(pytext, searchfrom = 0, searchto = None):
                searchto = len(pytext)
        # Cache a few attributes for quicker reference.
        search = matchRE.search
-       group = matchRE.group
        idSearch = idRE.search
-       idGroup = idRE.group
        
        tags = []
        tags_append = tags.append
@@ -112,10 +110,10 @@ def fontify(pytext, searchfrom = 0, searchto = None):
        start = 0
        end = searchfrom
        while 1:
-               start = search(pytext, end)
-               if start < 0 or start >= searchto:
+               m = search(pytext, end)
+               if not m or m.start() >= searchto:
                        break   # EXIT LOOP
-               match = group(0)
+               match = m.group(0)
                end = start + len(match)
                c = match[0]
                if c not in "#'\"":
@@ -133,9 +131,9 @@ def fontify(pytext, searchfrom = 0, searchto = None):
                        # If this was a defining keyword, look ahead to the
                        # following identifier.
                        if match in ["def", "class"]:
-                               start = idSearch(pytext, end)
-                               if start == end:
-                                       match = idGroup(0)
+                               m = idSearch(pytext, end)
+                               if m and m.start() == end:
+                                       match = m.group(0)
                                        end = start + len(match)
                                        tags_append((identifierTag, start, end, None))
                elif c == "#":
index 8c1662d598d6707046b2465db323656669e960b7..11b02768e6f27c40670f947ecf88b1ae1507fedd 100644 (file)
@@ -603,9 +603,9 @@ class TextEditor(EditText):
                                self.drawselframe(1)
 
 
-import regex
-commentPat = regex.compile("[ \t]*\(#\)")
-indentPat = regex.compile("\t*")
+import re
+commentPat = re.compile("[ \t]*\(#\)")
+indentPat = re.compile("\t*")
 
 class PyEditor(TextEditor):
        
@@ -659,9 +659,9 @@ class PyEditor(TextEditor):
                snippet = self.getselectedtext()
                lines = string.split(snippet, '\r')
                for i in range(len(lines)):
-                       res = commentPat.match(lines[i]) >= 0
-                       if res > 0:
-                               pos = commentPat.regs[1][0]
+                       m = commentPat.match(lines[i])
+                       if m:
+                               pos = m.start(1)
                                lines[i] = lines[i][:pos] + lines[i][pos+1:]
                snippet = string.join(lines, '\r')
                self.insert(snippet)
@@ -676,8 +676,9 @@ class PyEditor(TextEditor):
                indent = 3000 # arbitrary large number...
                for line in lines:
                        if string.strip(line):
-                               if indentPat.match(line):
-                                       indent = min(indent, indentPat.regs[0][1])
+                               m = indentPat.match(line)
+                               if m:
+                                       indent = min(indent, m.regs[0][1])
                                else:
                                        indent = 0
                                        break