Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9ad2752

Browse files
committed
Use re in stead of regex, so we get rid of the annoying warning during startup.
1 parent 2d0589b commit 9ad2752

5 files changed

Lines changed: 54 additions & 47 deletions

File tree

Mac/Tools/IDE/PyBrowser.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import struct
44
import string
55
import types
6-
import regex
6+
import re
77

88
nullid = '\0\0'
99
closedid = struct.pack('h', 468)
@@ -13,11 +13,15 @@
1313

1414
arrows = (nullid, closedid, openid, closedsolidid, opensolidid)
1515

16-
has_ctlcharsRE = regex.compile('[\000-\037\177-\377]')
17-
16+
has_ctlcharsRE = re.compile('[\000-\037\177-\377]')
17+
def ctlcharsREsearch(str):
18+
if has_ctlcharsRE(str) is None:
19+
return -1
20+
return 1
21+
1822
def double_repr(key, value, truncvalue = 0,
1923
type = type, StringType = types.StringType,
20-
has_ctlchars = has_ctlcharsRE.search, _repr = repr, str = str):
24+
has_ctlchars = ctlcharsREsearch, _repr = repr, str = str):
2125
if type(key) == StringType and has_ctlchars(key) < 0:
2226
key = str(key)
2327
else:

Mac/Tools/IDE/PyDocSearch.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import Standard_Suite
33
import Required_Suite
44
import WWW_Suite
5-
import regex
5+
import re
66
import W
77
import macfs
88
import os
@@ -29,16 +29,16 @@ def openfile(self, path, activate = 1):
2929
#SIGNATURE='MSIE' # MS Explorer
3030
SIGNATURE='MOSS' # Netscape
3131

32-
_titlepat = regex.compile('<title>\([^<]*\)</title>')
32+
_titlepat = re.compile('<title>\([^<]*\)</title>')
3333

3434
def sucktitle(path):
3535
f = open(path)
3636
text = f.read(1024) # assume the title is in the first 1024 bytes
3737
f.close()
3838
lowertext = string.lower(text)
39-
if _titlepat.search(lowertext) > 0:
40-
a, b = _titlepat.regs[1]
41-
return text[a:b]
39+
matcher = _titlepat.search(lowertext)
40+
if matcher:
41+
return matcher.group(1)
4242
return path
4343

4444
def verifydocpath(docpath):

Mac/Tools/IDE/PyEdit.py

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
import sys
1616
import string
1717
import marshal
18-
import regex
18+
import re
1919

2020
try:
2121
import Wthreading
@@ -25,7 +25,8 @@
2525
haveThreading = Wthreading.haveThreading
2626

2727
_scriptuntitledcounter = 1
28-
_wordchars = string.letters + string.digits + "_"
28+
# _wordchars = string.letters + string.digits + "_"
29+
_wordchars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_'
2930

3031

3132
runButtonLabels = ["Run all", "Stop!"]
@@ -553,7 +554,6 @@ def _runselection(self):
553554
if indent == 1:
554555
classname = ''
555556
alllines = string.split(alltext, '\r')
556-
identifieRE_match = _identifieRE.match
557557
for i in range(selfirstline - 1, -1, -1):
558558
line = alllines[i]
559559
if line[:6] == 'class ':
@@ -673,7 +673,6 @@ def flush(self):
673673

674674
def getclasslist(self):
675675
from string import find, strip
676-
import re
677676
methodRE = re.compile(r"\r[ \t]+def ")
678677
findMethod = methodRE.search
679678
editor = self.editgroup.editor
@@ -715,7 +714,6 @@ def getclasslist(self):
715714
offsetToLine = editor.ted.WEOffsetToLine
716715
getLineRange = editor.ted.WEGetLineRange
717716
append = classlist.append
718-
identifieRE_match = _identifieRE.match
719717
for pos, tag in list:
720718
lineno = offsetToLine(pos)
721719
lineStart, lineEnd = getLineRange(lineno)
@@ -794,14 +792,13 @@ def _makewholewordpattern(word):
794792
# first, escape special regex chars
795793
for esc in "\\[].*^+$?":
796794
word = _escape(word, esc)
797-
import regex
798795
notwordcharspat = '[^' + _wordchars + ']'
799-
pattern = '\(' + word + '\)'
796+
pattern = '(' + word + ')'
800797
if word[0] in _wordchars:
801798
pattern = notwordcharspat + pattern
802799
if word[-1] in _wordchars:
803800
pattern = pattern + notwordcharspat
804-
return regex.compile(pattern)
801+
return re.compile(pattern)
805802

806803
class SearchEngine:
807804

@@ -935,9 +932,9 @@ def replaceall(self):
935932
while 1:
936933
if self.parms["wholeword"]:
937934
wholewordRE = _makewholewordpattern(find)
938-
wholewordRE.search(text, pos)
939-
if wholewordRE.regs:
940-
pos = wholewordRE.regs[1][0]
935+
match = wholewordRE.search(text, pos)
936+
if match:
937+
pos = match.start(1)
941938
else:
942939
pos = -1
943940
else:
@@ -997,9 +994,9 @@ def findnext(self):
997994
selstart, selend = min(selstart, selend), max(selstart, selend)
998995
if self.parms["wholeword"]:
999996
wholewordRE = _makewholewordpattern(find)
1000-
wholewordRE.search(text, selend)
1001-
if wholewordRE.regs:
1002-
pos = wholewordRE.regs[1][0]
997+
match = wholewordRE.search(text, selend)
998+
if match:
999+
pos = match.start(1)
10031000
else:
10041001
pos = -1
10051002
else:
@@ -1009,9 +1006,9 @@ def findnext(self):
10091006
return 1
10101007
elif self.parms["wrap"]:
10111008
if self.parms["wholeword"]:
1012-
wholewordRE.search(text, 0)
1013-
if wholewordRE.regs:
1014-
pos = wholewordRE.regs[1][0]
1009+
match = wholewordRE.search(text, 0)
1010+
if match:
1011+
pos = match.start(1)
10151012
else:
10161013
pos = -1
10171014
else:
@@ -1169,12 +1166,19 @@ def execstring(pytext, globals, locals, filename="<string>", debugging=0,
11691166
PyDebugger.stop()
11701167

11711168

1172-
_identifieRE = regex.compile("[A-Za-z_][A-Za-z_0-9]*")
1169+
_identifieRE = re.compile("[A-Za-z_][A-Za-z_0-9]*")
1170+
1171+
def identifieRE_match(str):
1172+
match = _identifieRE.match(str)
1173+
if not match:
1174+
return -1
1175+
return match.end()
11731176

11741177
def _filename_as_modname(fname):
11751178
if fname[-3:] == '.py':
11761179
modname = fname[:-3]
1177-
if _identifieRE.match(modname) == len(modname):
1180+
match = _identifieRE.match(modname)
1181+
if match and match.start() == 0 and match.end() == len(modname):
11781182
return string.join(string.split(modname, '.'), '_')
11791183

11801184
def findeditor(topwindow, fromtop = 0):

Mac/Tools/IDE/PyFontify.py

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

2828
__version__ = "0.3.3"
2929

30-
import string, regex
30+
import string, re
3131

3232
# First a little helper, since I don't like to repeat things. (Tismer speaking)
3333
import string
@@ -87,20 +87,18 @@ def replace(where, what, with):
8787
keyPat = keyPat[:-2] + "\)" + nonKeyPat
8888

8989
matchPat = commentPat + "\|" + keyPat + "\|" + tripleQuotePat + "\|" + quotePat
90-
matchRE = regex.compile(matchPat)
90+
matchRE = re.compile(matchPat)
9191

9292
idKeyPat = "[ \t]*[A-Za-z_][A-Za-z_0-9.]*" # Ident w. leading whitespace.
93-
idRE = regex.compile(idKeyPat)
93+
idRE = re.compile(idKeyPat)
9494

9595

9696
def fontify(pytext, searchfrom = 0, searchto = None):
9797
if searchto is None:
9898
searchto = len(pytext)
9999
# Cache a few attributes for quicker reference.
100100
search = matchRE.search
101-
group = matchRE.group
102101
idSearch = idRE.search
103-
idGroup = idRE.group
104102

105103
tags = []
106104
tags_append = tags.append
@@ -112,10 +110,10 @@ def fontify(pytext, searchfrom = 0, searchto = None):
112110
start = 0
113111
end = searchfrom
114112
while 1:
115-
start = search(pytext, end)
116-
if start < 0 or start >= searchto:
113+
m = search(pytext, end)
114+
if not m or m.start() >= searchto:
117115
break # EXIT LOOP
118-
match = group(0)
116+
match = m.group(0)
119117
end = start + len(match)
120118
c = match[0]
121119
if c not in "#'\"":
@@ -133,9 +131,9 @@ def fontify(pytext, searchfrom = 0, searchto = None):
133131
# If this was a defining keyword, look ahead to the
134132
# following identifier.
135133
if match in ["def", "class"]:
136-
start = idSearch(pytext, end)
137-
if start == end:
138-
match = idGroup(0)
134+
m = idSearch(pytext, end)
135+
if m and m.start() == end:
136+
match = m.group(0)
139137
end = start + len(match)
140138
tags_append((identifierTag, start, end, None))
141139
elif c == "#":

Mac/Tools/IDE/Wtext.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -603,9 +603,9 @@ def draw(self, visRgn = None):
603603
self.drawselframe(1)
604604

605605

606-
import regex
607-
commentPat = regex.compile("[ \t]*\(#\)")
608-
indentPat = regex.compile("\t*")
606+
import re
607+
commentPat = re.compile("[ \t]*\(#\)")
608+
indentPat = re.compile("\t*")
609609

610610
class PyEditor(TextEditor):
611611

@@ -659,9 +659,9 @@ def domenu_uncomment(self):
659659
snippet = self.getselectedtext()
660660
lines = string.split(snippet, '\r')
661661
for i in range(len(lines)):
662-
res = commentPat.match(lines[i]) >= 0
663-
if res > 0:
664-
pos = commentPat.regs[1][0]
662+
m = commentPat.match(lines[i])
663+
if m:
664+
pos = m.start(1)
665665
lines[i] = lines[i][:pos] + lines[i][pos+1:]
666666
snippet = string.join(lines, '\r')
667667
self.insert(snippet)
@@ -676,8 +676,9 @@ def domenu_comment(self):
676676
indent = 3000 # arbitrary large number...
677677
for line in lines:
678678
if string.strip(line):
679-
if indentPat.match(line):
680-
indent = min(indent, indentPat.regs[0][1])
679+
m = indentPat.match(line)
680+
if m:
681+
indent = min(indent, m.regs[0][1])
681682
else:
682683
indent = 0
683684
break

0 commit comments

Comments
 (0)