@@ -34,73 +34,6 @@ def diag_indices(n):
3434# add here explaining their provenance, any changes made, and what versions of
3535# Python require them:
3636
37- # Copied unchanged from Python 2.7.3's re.py module; all I did was add the
38- # import statements at the top.
39- # This code seems to be included in Python 2.5+.
40- import re
41- if optional_dep_ok and hasattr (re , "Scanner" ):
42- Scanner = re .Scanner
43- else :
44- import sre_parse
45- import sre_compile
46- class Scanner :
47- def __init__ (self , lexicon , flags = 0 ):
48- from sre_constants import BRANCH , SUBPATTERN
49- self .lexicon = lexicon
50- # combine phrases into a compound pattern
51- p = []
52- s = sre_parse .Pattern ()
53- s .flags = flags
54- for phrase , action in lexicon :
55- p .append (sre_parse .SubPattern (s , [
56- (SUBPATTERN , (len (p )+ 1 , sre_parse .parse (phrase , flags ))),
57- ]))
58- s .groups = len (p )+ 1
59- p = sre_parse .SubPattern (s , [(BRANCH , (None , p ))])
60- self .scanner = sre_compile .compile (p )
61- def scan (self , string ):
62- result = []
63- append = result .append
64- match = self .scanner .scanner (string ).match
65- i = 0
66- while 1 :
67- m = match ()
68- if not m :
69- break
70- j = m .end ()
71- if i == j :
72- break
73- action = self .lexicon [m .lastindex - 1 ][1 ]
74- if hasattr (action , '__call__' ):
75- self .match = m
76- action = action (self , m .group ())
77- if action is not None :
78- append (action )
79- i = j
80- return result , string [i :]
81-
82- # functools available in Python 2.5+
83- # This is just a cosmetic thing, so don't bother emulating it if we don't
84- # have it.
85- def compat_wraps (f1 ):
86- def do_wrap (f2 ):
87- return f2
88- return do_wrap
89- if optional_dep_ok :
90- try :
91- from functools import wraps
92- except ImportError :
93- wraps = compat_wraps
94- else :
95- wraps = compat_wraps
96-
97- # collections.Mapping available in Python 2.6+
98- import collections
99- if optional_dep_ok and hasattr (collections , "Mapping" ):
100- Mapping = collections .Mapping
101- else :
102- Mapping = dict
103-
10437# OrderedDict is only available in Python 2.7+. compat_ordereddict.py has
10538# comments at the top.
10639import collections
0 commit comments