diff options
author | Jack Jansen <jack.jansen@cwi.nl> | 2001-02-21 13:54:31 (GMT) |
---|---|---|
committer | Jack Jansen <jack.jansen@cwi.nl> | 2001-02-21 13:54:31 (GMT) |
commit | 9ad2752381b10cae83eb9e8044aa77dfd87d7039 (patch) | |
tree | e06b55db8ff39a445a6dcc83622fc229348d0582 /Mac/Tools | |
parent | 2d0589be6739e15bc27ab8996ee0727a5a3dda51 (diff) | |
download | cpython-9ad2752381b10cae83eb9e8044aa77dfd87d7039.zip cpython-9ad2752381b10cae83eb9e8044aa77dfd87d7039.tar.gz cpython-9ad2752381b10cae83eb9e8044aa77dfd87d7039.tar.bz2 |
Use re in stead of regex, so we get rid of the annoying warning during startup.
Diffstat (limited to 'Mac/Tools')
-rw-r--r-- | Mac/Tools/IDE/PyBrowser.py | 12 | ||||
-rw-r--r-- | Mac/Tools/IDE/PyDocSearch.py | 10 | ||||
-rw-r--r-- | Mac/Tools/IDE/PyEdit.py | 42 | ||||
-rw-r--r-- | Mac/Tools/IDE/PyFontify.py | 20 | ||||
-rw-r--r-- | Mac/Tools/IDE/Wtext.py | 17 |
5 files changed, 54 insertions, 47 deletions
diff --git a/Mac/Tools/IDE/PyBrowser.py b/Mac/Tools/IDE/PyBrowser.py index c1abbac..853392f 100644 --- a/Mac/Tools/IDE/PyBrowser.py +++ b/Mac/Tools/IDE/PyBrowser.py @@ -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: diff --git a/Mac/Tools/IDE/PyDocSearch.py b/Mac/Tools/IDE/PyDocSearch.py index f975026..b036556 100644 --- a/Mac/Tools/IDE/PyDocSearch.py +++ b/Mac/Tools/IDE/PyDocSearch.py @@ -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): diff --git a/Mac/Tools/IDE/PyEdit.py b/Mac/Tools/IDE/PyEdit.py index 7274a1e..fc8503a 100644 --- a/Mac/Tools/IDE/PyEdit.py +++ b/Mac/Tools/IDE/PyEdit.py @@ -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): diff --git a/Mac/Tools/IDE/PyFontify.py b/Mac/Tools/IDE/PyFontify.py index 02de08e..b5d6102 100644 --- a/Mac/Tools/IDE/PyFontify.py +++ b/Mac/Tools/IDE/PyFontify.py @@ -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 == "#": diff --git a/Mac/Tools/IDE/Wtext.py b/Mac/Tools/IDE/Wtext.py index 8c1662d..11b0276 100644 --- a/Mac/Tools/IDE/Wtext.py +++ b/Mac/Tools/IDE/Wtext.py @@ -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 |