]> granicus.if.org Git - python/commitdiff
Convert all remaining *simple* cases of regex usage to re usage.
authorGuido van Rossum <guido@python.org>
Wed, 22 Oct 1997 21:00:49 +0000 (21:00 +0000)
committerGuido van Rossum <guido@python.org>
Wed, 22 Oct 1997 21:00:49 +0000 (21:00 +0000)
23 files changed:
Lib/fmt.py
Lib/fnmatch.py
Lib/fpformat.py
Lib/glob.py
Lib/keyword.py
Lib/lib-old/fmt.py
Lib/mailbox.py
Lib/mhlib.py
Lib/nntplib.py
Lib/pipes.py
Lib/plat-irix5/cddb.py
Lib/plat-irix5/cdplayer.py
Lib/plat-irix5/flp.py
Lib/plat-irix6/cddb.py
Lib/plat-irix6/cdplayer.py
Lib/plat-irix6/flp.py
Lib/posixpath.py
Lib/pstats.py
Lib/rfc822.py
Lib/string.py
Lib/stringold.py
Lib/token.py
Lib/tzparse.py

index f7c271885920492181569aca97a3d4b89112a592..3f146cb5894aa678c31de8eac703e1bb816cebfa 100644 (file)
@@ -461,9 +461,9 @@ class StdwinBackEnd(SavingBackEnd):
                self.paralist[para2].invert(d, pos1, pos2)
        #
        def search(self, prog):
-               import regex, string
+               import re, string
                if type(prog) == type(''):
-                       prog = regex.compile(string.lower(prog))
+                       prog = re.compile(string.lower(prog))
                if self.selection:
                        iold = self.selection[0][0]
                else:
@@ -474,8 +474,9 @@ class StdwinBackEnd(SavingBackEnd):
                                continue
                        p = self.paralist[i]
                        text = string.lower(p.extract())
-                       if prog.search(text) >= 0:
-                               a, b = prog.regs[0]
+                       match = prog.search(text)
+                       if match:
+                               a, b = match.group(0)
                                long1 = i, a
                                long2 = i, b
                                hit = long1, long2
index 9b31856546f5d763f91ed9434648ffb40a97cfef..ed815945e2d9659ba9d1b4524ee8aa5b688f941a 100644 (file)
@@ -10,6 +10,8 @@ The function translate(PATTERN) returns a regular expression
 corresponding to PATTERN.  (It does not compile it.)
 """
 
+import re
+
 _cache = {}
 
 def fnmatch(name, pat):
@@ -42,11 +44,8 @@ def fnmatchcase(name, pat):
        
        if not _cache.has_key(pat):
                res = translate(pat)
-               import regex
-               save_syntax = regex.set_syntax(0)
-               _cache[pat] = regex.compile(res)
-               save_syntax = regex.set_syntax(save_syntax)
-       return _cache[pat].match(name) == len(name)
+               _cache[pat] = re.compile(res)
+       return _cache[pat].match(name) is not None
 
 def translate(pat):
        """Translate a shell PATTERN to a regular expression.
@@ -85,8 +84,6 @@ def translate(pat):
                                                stuff = stuff[1:] + stuff[0]
                                        stuff = '[' + stuff + ']'
                                res = res + stuff
-               elif c in '\\.+^$':
-                       res = res + ('\\' + c)
                else:
-                       res = res + c
-       return res
+                       res = res + re.escape(c)
+       return res + "$"
index 457457595c8df48b304d7680eed3d06f9a8481c7..404738d79bf798feef3561a0b237e7d9fc40867f 100644 (file)
 # digits_behind: number of digits behind the decimal point
 
 
-import regex
+import re
 
 # Compiled regular expression to "decode" a number
-decoder = regex.compile( \
-       '^\([-+]?\)0*\([0-9]*\)\(\(\.[0-9]*\)?\)\(\([eE][-+]?[0-9]+\)?\)$')
+decoder = re.compile( \
+       '^([-+]?)0*([0-9]*)((\.[0-9]*)?)(([eE][-+]?[0-9]+)?)$')
 # \0 the whole thing
 # \1 leading sign or empty
 # \2 digits left of decimal point
@@ -30,10 +30,9 @@ NotANumber = 'fpformat.NotANumber'
 # fraction is 0 or more digits
 # expo is an integer
 def extract(s):
-       if decoder.match(s) < 0: raise NotANumber
-       (a1, b1), (a2, b2), (a3, b3), (a4, b4), (a5, b5) = decoder.regs[1:6]
-       sign, intpart, fraction, exppart = \
-               s[a1:b1], s[a2:b2], s[a3:b3], s[a5:b5]
+       m = decoder.match(s)
+       if not m: raise NotANumber
+       sign, intpart, fraction, exppart = m.group(1, 2, 3, 5)
        if sign == '+': sign = ''
        if fraction: fraction = fraction[1:]
        if exppart: expo = eval(exppart[1:])
index 990ffa3ada0303c30731e12f8bf84b41568a39a7..599d41b5e12ccbf324cbf0284dac3e9b3a63188e 100644 (file)
@@ -2,7 +2,7 @@
 
 import os
 import fnmatch
-import regex
+import re
 
 
 def glob(pathname):
@@ -50,7 +50,7 @@ def glob1(dirname, pattern):
        return result
 
 
-magic_check = regex.compile('[*?[]')
+magic_check = re.compile('[*?[]')
 
 def has_magic(s):
-       return magic_check.search(s) >= 0
+       return magic_check.search(s) is not None
index 2ad80d7baca58ba7aee90dd88828879d80204156..ba9249d2e448148455805a4d36aa2283713dc861 100755 (executable)
@@ -7,10 +7,7 @@
 #  To update the symbols in this file, 'cd' to the top directory of
 #  the python source tree after building the interpreter and run:
 #
-#    PYTHONPATH=./Lib ./python Lib/keyword.py
-#
-#  (this path allows the import of string.py and regexmodule.so
-#  for a site with no installation in place)
+#    python Lib/keyword.py
 
 kwlist = [
 #--start keywords--
@@ -52,7 +49,7 @@ for keyword in kwlist:
 iskeyword = kwdict.has_key
 
 def main():
-    import sys, regex, string
+    import sys, re, string
 
     args = sys.argv[1:]
     iptfile = args and args[0] or "Python/graminit.c"
@@ -61,13 +58,15 @@ def main():
 
     # scan the source file for keywords
     fp = open(iptfile)
-    strprog = regex.compile('"\([^"]+\)"')
+    strprog = re.compile('"([^"]+)"')
     lines = []
     while 1:
         line = fp.readline()
         if not line: break
-        if string.find(line, '{1, "') > -1 and strprog.search(line) > -1:
-            lines.append("        '" + strprog.group(1) + "',\n")
+       if string.find(line, '{1, "') > -1:
+           match = strprog.search(line)
+           if match:
+               lines.append("        '" + match.group(1) + "',\n")
     fp.close()
     lines.sort()
 
@@ -90,4 +89,5 @@ def main():
     fp.write(string.join(format, ''))
     fp.close()
 
-if __name__ == "__main__": main()
+if __name__ == "__main__":
+    main()
index f7c271885920492181569aca97a3d4b89112a592..3f146cb5894aa678c31de8eac703e1bb816cebfa 100644 (file)
@@ -461,9 +461,9 @@ class StdwinBackEnd(SavingBackEnd):
                self.paralist[para2].invert(d, pos1, pos2)
        #
        def search(self, prog):
-               import regex, string
+               import re, string
                if type(prog) == type(''):
-                       prog = regex.compile(string.lower(prog))
+                       prog = re.compile(string.lower(prog))
                if self.selection:
                        iold = self.selection[0][0]
                else:
@@ -474,8 +474,9 @@ class StdwinBackEnd(SavingBackEnd):
                                continue
                        p = self.paralist[i]
                        text = string.lower(p.extract())
-                       if prog.search(text) >= 0:
-                               a, b = prog.regs[0]
+                       match = prog.search(text)
+                       if match:
+                               a, b = match.group(0)
                                long1 = i, a
                                long2 = i, b
                                hit = long1, long2
index 4c4eebe3321442c098f82967918349b1ec27948f..37a4636cc30a79bdf69e37e951db8f490dcc2418 100755 (executable)
@@ -5,7 +5,6 @@
 
 import rfc822
 import os
-import regex
 
 class _Mailbox:
        def __init__(self, fp):
@@ -117,12 +116,13 @@ class MmdfMailbox(_Mailbox):
 
 class MHMailbox:
     def __init__(self, dirname):
-       pat = regex.compile('^[0-9][0-9]*$')
+       import re
+       pat = re.compile('^[0-9][0-9]*$')
        self.dirname = dirname
        files = os.listdir(self.dirname)
        self.boxes = []
        for f in files:
-           if pat.match(f) == len(f):
+           if pat.match(f):
                self.boxes.append(f)
 
     def next(self):
@@ -187,6 +187,7 @@ def _test():
                if not msg:
                        break
                msgs.append(msg)
+               msg.fp = None
        if len(args) > 1:
                num = string.atoi(args[1])
                print 'Message %d body:'%num
index a78b2c723dfc02b05ecb0be98ac9cc05c8cbadf0..69a33ec6797f24d15d8968e497ba92526cf42e67 100644 (file)
@@ -73,7 +73,7 @@ FOLDER_PROTECT = 0700
 import os
 import sys
 from stat import ST_NLINK
-import regex
+import re
 import string
 import mimetools
 import multifile
@@ -236,9 +236,9 @@ class MH:
 
 # Class representing a particular folder
 
-numericprog = regex.compile('^[1-9][0-9]*$')
+numericprog = re.compile('^[1-9][0-9]*$')
 def isnumeric(str):
-    return numericprog.match(str) >= 0
+    return numericprog.match(str) is not None
 
 class Folder:
 
@@ -906,15 +906,12 @@ def pickline(file, key, casefold = 1):
        f = open(file, 'r')
     except IOError:
        return None
-    pat = key + ':'
-    if casefold:
-       prog = regex.compile(pat, regex.casefold)
-    else:
-       prog = regex.compile(pat)
+    pat = re.escape(key) + ':'
+    prog = re.compile(pat, casefold and re.IGNORECASE)
     while 1:
        line = f.readline()
        if not line: break
-       if prog.match(line) >= 0:
+       if prog.match(line):
            text = line[len(key)+1:]
            while 1:
                line = f.readline()
@@ -931,18 +928,15 @@ def updateline(file, key, value, casefold = 1):
        f.close()
     except IOError:
        lines = []
-    pat = key + ':\(.*\)\n'
-    if casefold:
-       prog = regex.compile(pat, regex.casefold)
-    else:
-       prog = regex.compile(pat)
+    pat = re.escape(key) + ':(.*)\n'
+    prog = re.compile(pat, casefold and re.IGNORECASE)
     if value is None:
        newline = None
     else:
        newline = '%s: %s\n' % (key, value)
     for i in range(len(lines)):
        line = lines[i]
-       if prog.match(line) == len(line):
+       if prog.match(line):
            if newline is None:
                del lines[i]
            else:
index a266cbd08414314c807267f979e99a80b6b57e78..85c2a63912a194948d77e01dcfbd06e8d3ed06eb 100644 (file)
@@ -29,7 +29,7 @@
 
 
 # Imports
-import regex
+import re
 import socket
 import string
 
@@ -313,13 +313,13 @@ class NNTP:
        # - list: list of (nr, value) strings
 
        def xhdr(self, hdr, str):
+               pat = re.compile('^([0-9]+) ?(.*)\n?')
                resp, lines = self.longcmd('XHDR ' + hdr + ' ' + str)
                for i in range(len(lines)):
                        line = lines[i]
-                       n = regex.match('^[0-9]+', line)
-                       nr = line[:n]
-                       if n < len(line) and line[n] == ' ': n = n+1
-                       lines[i] = (nr, line[n:])
+                       m = pat.match(line)
+                       if m:
+                               lines[i] = m.group(1, 2)
                return resp, lines
 
        # Process an XOVER command (optional server extension) Arguments:
@@ -354,14 +354,13 @@ class NNTP:
        # - list: list of (name,title) strings
 
        def xgtitle(self, group):
-               line_pat = regex.compile("^\([^ \t]+\)[ \t]+\(.*\)$")
+               line_pat = re.compile("^([^ \t]+)[ \t]+(.*)$")
                resp, raw_lines = self.longcmd('XGTITLE ' + group)
                lines = []
                for raw_line in raw_lines:
-                       if line_pat.search(string.strip(raw_line)) == 0:
-                               lines.append(line_pat.group(1),
-                                            line_pat.group(2))
-
+                       match = line_pat.search(string.strip(raw_line))
+                       if match:
+                               lines.append(match.group(1, 2))
                return resp, lines
 
        # Process an XPATH command (optional server extension) Arguments:
index 0ae0b8c9edd2deb6f7615b9b594a4af6df9d7505..2bb6ee317ab19f5ecb7ed57132e9701b183887c7 100644 (file)
@@ -61,7 +61,7 @@
 
 
 import sys
-import regex
+import re
 
 import os
 import tempfile
@@ -124,10 +124,10 @@ class Template:
                if self.steps <> [] and self.steps[-1][1] == SINK:
                        raise ValueError, \
                              'Template.append: already ends with SINK'
-               if kind[0] == 'f' and regex.search('\$IN', cmd) < 0:
+               if kind[0] == 'f' and not re.search('\$IN\b', cmd):
                        raise ValueError, \
                              'Template.append: missing $IN in cmd'
-               if kind[1] == 'f' and regex.search('\$OUT', cmd) < 0:
+               if kind[1] == 'f' and not re.search('\$OUT\b', cmd):
                        raise ValueError, \
                              'Template.append: missing $OUT in cmd'
                self.steps.append((cmd, kind))
@@ -146,10 +146,10 @@ class Template:
                if self.steps <> [] and self.steps[0][1] == SOURCE:
                        raise ValueError, \
                              'Template.prepend: already begins with SOURCE'
-               if kind[0] == 'f' and regex.search('\$IN\>', cmd) < 0:
+               if kind[0] == 'f' and not re.search('\$IN\b', cmd):
                        raise ValueError, \
                              'Template.prepend: missing $IN in cmd'
-               if kind[1] == 'f' and regex.search('\$OUT\>', cmd) < 0:
+               if kind[1] == 'f' and not re.search('\$OUT\b', cmd):
                        raise ValueError, \
                              'Template.prepend: missing $OUT in cmd'
                self.steps.insert(0, (cmd, kind))
index 57cf3c6661a467c9bb4bf5df71b1bb4737b83c96..acd7870932b71c11d4f6cfde42a66ecc956354f1 100755 (executable)
@@ -81,18 +81,17 @@ class Cddb:
                self.notes = []
                if not hasattr(self, 'file'):
                        return
-               import regex
-               reg = regex.compile('^\\([^.]*\\)\\.\\([^:]*\\):[\t ]+\\(.*\\)')
+               import re
+               reg = re.compile(r'^([^.]*)\.([^:]*):[\t ]+(.*)')
                while 1:
                        line = f.readline()
                        if not line:
                                break
-                       if reg.match(line) == -1:
+                       match = reg.match(line)
+                       if not match:
                                print 'syntax error in ' + file
                                continue
-                       name1 = line[reg.regs[1][0]:reg.regs[1][1]]
-                       name2 = line[reg.regs[2][0]:reg.regs[2][1]]
-                       value = line[reg.regs[3][0]:reg.regs[3][1]]
+                       name1, name2, value = match.group(1, 2, 3)
                        if name1 == 'album':
                                if name2 == 'artist':
                                        self.artist = value
index 5c2c95aa7fd868be27bacc36230d733750d04af1..0e27468451e8d6805b78fd44a208a02135cde532 100755 (executable)
@@ -39,8 +39,8 @@ class Cdplayer:
                        f = open(posix.environ['HOME'] + '/' + cdplayerrc, 'r')
                except IOError:
                        return
-               import regex
-               reg = regex.compile('^\\([^:]*\\):\t\\(.*\\)')
+               import re
+               reg = re.compile(r'^([^:]*):\t(.*)')
                s = self.id + '.'
                l = len(s)
                while 1:
@@ -49,11 +49,11 @@ class Cdplayer:
                                break
                        if line[:l] == s:
                                line = line[l:]
-                               if reg.match(line) == -1:
+                               match = reg.match(line)
+                               if not match:
                                        print 'syntax error in ~/' + cdplayerrc
                                        continue
-                               name = line[reg.regs[1][0]:reg.regs[1][1]]
-                               value = line[reg.regs[2][0]:reg.regs[2][1]]
+                               name, valye = match.group(1, 2)
                                if name == 'title':
                                        self.title = value
                                elif name == 'artist':
index 14e22787445e6093dbad25874d50423098402f02..a277f7f25ef26eec924d0825d045792545ac7898 100755 (executable)
@@ -267,19 +267,18 @@ _parse_func = { \
 # This function parses a line, and returns either
 # a string or a tuple (name,value)
 
-import regex
-prog = regex.compile('^\([^:]*\): *\(.*\)')
+import re
+prog = re.compile('^([^:]*): *(.*)')
 
 def _parse_line(line):
-    if prog.match(line) < 0:
+    match = prog.match(line)
+    if not match:
        return line
-    a = prog.regs
-    name = line[:a[1][1]]
+    name, value = match.group(1, 2)
     if name[0] == 'N':
-           name = string.joinfields(string.split(name),'')
+           name = string.join(string.split(name),'')
            name = string.lower(name)
-    name = string.upper(name[0]) + name[1:]
-    value = line[a[2][0]:]
+    name = string.capitalize(name)
     try:
        pf = _parse_func[name]
     except KeyError:
index 57cf3c6661a467c9bb4bf5df71b1bb4737b83c96..acd7870932b71c11d4f6cfde42a66ecc956354f1 100644 (file)
@@ -81,18 +81,17 @@ class Cddb:
                self.notes = []
                if not hasattr(self, 'file'):
                        return
-               import regex
-               reg = regex.compile('^\\([^.]*\\)\\.\\([^:]*\\):[\t ]+\\(.*\\)')
+               import re
+               reg = re.compile(r'^([^.]*)\.([^:]*):[\t ]+(.*)')
                while 1:
                        line = f.readline()
                        if not line:
                                break
-                       if reg.match(line) == -1:
+                       match = reg.match(line)
+                       if not match:
                                print 'syntax error in ' + file
                                continue
-                       name1 = line[reg.regs[1][0]:reg.regs[1][1]]
-                       name2 = line[reg.regs[2][0]:reg.regs[2][1]]
-                       value = line[reg.regs[3][0]:reg.regs[3][1]]
+                       name1, name2, value = match.group(1, 2, 3)
                        if name1 == 'album':
                                if name2 == 'artist':
                                        self.artist = value
index 5c2c95aa7fd868be27bacc36230d733750d04af1..0e27468451e8d6805b78fd44a208a02135cde532 100644 (file)
@@ -39,8 +39,8 @@ class Cdplayer:
                        f = open(posix.environ['HOME'] + '/' + cdplayerrc, 'r')
                except IOError:
                        return
-               import regex
-               reg = regex.compile('^\\([^:]*\\):\t\\(.*\\)')
+               import re
+               reg = re.compile(r'^([^:]*):\t(.*)')
                s = self.id + '.'
                l = len(s)
                while 1:
@@ -49,11 +49,11 @@ class Cdplayer:
                                break
                        if line[:l] == s:
                                line = line[l:]
-                               if reg.match(line) == -1:
+                               match = reg.match(line)
+                               if not match:
                                        print 'syntax error in ~/' + cdplayerrc
                                        continue
-                               name = line[reg.regs[1][0]:reg.regs[1][1]]
-                               value = line[reg.regs[2][0]:reg.regs[2][1]]
+                               name, valye = match.group(1, 2)
                                if name == 'title':
                                        self.title = value
                                elif name == 'artist':
index 14e22787445e6093dbad25874d50423098402f02..a277f7f25ef26eec924d0825d045792545ac7898 100644 (file)
@@ -267,19 +267,18 @@ _parse_func = { \
 # This function parses a line, and returns either
 # a string or a tuple (name,value)
 
-import regex
-prog = regex.compile('^\([^:]*\): *\(.*\)')
+import re
+prog = re.compile('^([^:]*): *(.*)')
 
 def _parse_line(line):
-    if prog.match(line) < 0:
+    match = prog.match(line)
+    if not match:
        return line
-    a = prog.regs
-    name = line[:a[1][1]]
+    name, value = match.group(1, 2)
     if name[0] == 'N':
-           name = string.joinfields(string.split(name),'')
+           name = string.join(string.split(name),'')
            name = string.lower(name)
-    name = string.upper(name[0]) + name[1:]
-    value = line[a[2][0]:]
+    name = string.capitalize(name)
     try:
        pf = _parse_func[name]
     except KeyError:
index 965184bc3c9a464b283e2182d742e2e5c623facb..996080175b0b651582be415d4fc04de4a7322b91 100644 (file)
@@ -266,15 +266,15 @@ def expandvars(path):
        if '$' not in path:
                return path
        if not _varprog:
-               import regex
-               _varprog = regex.compile('$\([a-zA-Z0-9_]+\|{[^}]*}\)')
+               import re
+               _varprog = re.compile(r'\$(\w+|\{[^}]*\})')
        i = 0
        while 1:
-               i = _varprog.search(path, i)
-               if i < 0:
+               m = _varprog.search(path, i)
+               if not m:
                        break
-               name = _varprog.group(1)
-               j = i + len(_varprog.group(0))
+               i, j = m.span(0)
+               name = m.group(1)
                if name[:1] == '{' and name[-1:] == '}':
                        name = name[1:-1]
                if os.environ.has_key(name):
index 7e4a3851e75c9480caa7ac4463265d90affa2e5d..5bc70b367cfbf15f2ff4d000a41e1aba2de60aea 100644 (file)
@@ -35,7 +35,7 @@ import os
 import time
 import string
 import marshal
-import regex
+import re
 
 #**************************************************************************
 # Class Stats documentation
@@ -300,7 +300,7 @@ class Stats:
                if type(sel) == type(""):
                        new_list = []
                        for func in list:
-                               if 0<=regex.search(sel, func_std_string(func)):
+                               if re.search(sel, func_std_string(func)):
                                        new_list.append(func)
                else:
                        count = len(list)
index 6e584eb662b9ab59bdcaddb2420200f3dceec3f0..70ac1f8db79af47f458ee521bbf45d279f69f2d5 100644 (file)
@@ -38,7 +38,7 @@
 # There are also some utility functions here.
 
 
-import regex
+import re
 import string
 import time
 
@@ -311,7 +311,7 @@ def unquote(str):
 
 error = 'parseaddr.error'
 
-specials = regex.compile('[][()<>,.;:@\\" \000-\037\177-\377]')
+specials = re.compile(r'[][()<>,.;:@\" \000-\037\177-\377]')
 
 def quote(str):
        return '"%s"' % string.join(
@@ -408,7 +408,7 @@ def parseaddr(address):
                                else:
                                        name.append(token[1])
                        elif token[0] == 1 and cur is addr:
-                               if specials.search(token[1]) >= 0:
+                               if specials.search(token[1]):
                                        cur.append(quote(token[1]))
                                else:
                                        cur.append(token[1])
@@ -423,7 +423,7 @@ def parseaddr(address):
                        if token[0] == 2:
                                name.append(token[1])
                        elif token[0] == 1:
-                               if specials.search(token[1]) >= 0:
+                               if specials.search(token[1]):
                                        addr.append(quote(token[1]))
                                else:
                                        addr.append(token[1])
@@ -563,4 +563,3 @@ if __name__ == '__main__':
        print 'keys =', m.keys()
        print 'values =', m.values()
        print 'items =', m.items()
-       
index 5cf5b6f36711adb223fc8c582991022d57e554b6..3f6597899ffe0d8b4c836b19ac08ec52fa4af345 100644 (file)
@@ -193,17 +193,20 @@ def rfind(s, sub, i = 0, last=None):
        return r
 
 # Convert string to float
+re = None
 def atof(str):
-       import regex
+       global re
+       if re is None:
+               import re
        sign = ''
-       s = str
+       s = strip(str)
        if s and s[0] in '+-':
                sign = s[0]
                s = s[1:]
        if not s:
                raise ValueError, 'non-float argument to string.atof'
        while s[0] == '0' and len(s) > 1 and s[1] in digits: s = s[1:]
-       if regex.match('[0-9]*\(\.[0-9]*\)?\([eE][-+]?[0-9]+\)?', s) != len(s):
+       if not re.match('[0-9]*(\.[0-9]*)?([eE][-+]?[0-9]+)?$', s):
                raise ValueError, 'non-float argument to string.atof'
        try:
                return float(eval(sign + s))
index 5cf5b6f36711adb223fc8c582991022d57e554b6..3f6597899ffe0d8b4c836b19ac08ec52fa4af345 100644 (file)
@@ -193,17 +193,20 @@ def rfind(s, sub, i = 0, last=None):
        return r
 
 # Convert string to float
+re = None
 def atof(str):
-       import regex
+       global re
+       if re is None:
+               import re
        sign = ''
-       s = str
+       s = strip(str)
        if s and s[0] in '+-':
                sign = s[0]
                s = s[1:]
        if not s:
                raise ValueError, 'non-float argument to string.atof'
        while s[0] == '0' and len(s) > 1 and s[1] in digits: s = s[1:]
-       if regex.match('[0-9]*\(\.[0-9]*\)?\([eE][-+]?[0-9]+\)?', s) != len(s):
+       if not re.match('[0-9]*(\.[0-9]*)?([eE][-+]?[0-9]+)?$', s):
                raise ValueError, 'non-float argument to string.atof'
        try:
                return float(eval(sign + s))
index 3d358a3d7743f5dfdc39890ea6307cca9966baa6..888bb41a0931d0a7576f70e2ec997e2c6ba51ab3 100755 (executable)
@@ -7,10 +7,7 @@
 #  To update the symbols in this file, 'cd' to the top directory of
 #  the python source tree after building the interpreter and run:
 #
-#    PYTHONPATH=./Lib ./python Lib/token.py
-#
-#  (this path allows the import of string.py and regexmodule.so
-#  for a site with no installation in place)
+#    python Lib/token.py
 
 #--start constants--
 ENDMARKER = 0
@@ -73,7 +70,7 @@ def ISEOF(x):
 
 
 def main():
-    import regex
+    import re
     import string
     import sys
     args = sys.argv[1:]
@@ -88,13 +85,14 @@ def main():
        sys.exit(1)
     lines = string.splitfields(fp.read(), "\n")
     fp.close()
-    re = regex.compile(
-       "#define[ \t][ \t]*\([A-Z][A-Z_]*\)[ \t][ \t]*\([0-9][0-9]*\)",
-       regex.casefold)
+    prog = re.compile(
+       "#define[ \t][ \t]*([A-Z][A-Z_]*)[ \t][ \t]*([0-9][0-9]*)",
+       re.IGNORECASE)
     tokens = {}
     for line in lines:
-       if re.match(line) > -1:
-           name, val = re.group(1, 2)
+       match = prog.match(line)
+       if match:
+           name, val = match.group(1, 2)
            val = string.atoi(val)
            tokens[val] = name          # reverse so we can sort them...
     keys = tokens.keys()
index ef325e9ff097e8f7af4ff2fd3ba3f9e7850c34c3..358e0cc25e276faa9cef1b5c86dcff427db356dd 100644 (file)
@@ -2,23 +2,22 @@
 # XXX Unfinished.
 # XXX Only the typical form "XXXhhYYY;ddd/hh,ddd/hh" is currently supported.
 
-tzpat = '^\([A-Z][A-Z][A-Z]\)\([-+]?[0-9]+\)\([A-Z][A-Z][A-Z]\);' + \
-         '\([0-9]+\)/\([0-9]+\),\([0-9]+\)/\([0-9]+\)$'
+tzpat = ('^([A-Z][A-Z][A-Z])([-+]?[0-9]+)([A-Z][A-Z][A-Z]);'
+         '([0-9]+)/([0-9]+),([0-9]+)/([0-9]+)$')
 
 tzprog = None
 
 def tzparse(tzstr):
        global tzprog
        if tzprog == None:
-               import regex
-               tzprog = regex.compile(tzpat)
-       if tzprog.match(tzstr) < 0:
+               import re
+               tzprog = re.compile(tzpat)
+       match = tzprog.match(tzstr)
+       if not match:
                raise ValueError, 'not the TZ syntax I understand'
-       regs = tzprog.regs
        subs = []
        for i in range(1, 8):
-               a, b = regs[i]
-               subs.append(tzstr[a:b])
+               subs.append(match.group(i))
        for i in (1, 3, 4, 5, 6):
                subs[i] = eval(subs[i])
        [tzname, delta, dstname, daystart, hourstart, dayend, hourend] = subs