Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
3ccd1e6e
Commit
3ccd1e6e
authored
Oct 22, 1997
by
Guido van Rossum
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Convert all remaining *simple* cases of regex usage to re usage.
parent
9006d299
Changes
23
Hide whitespace changes
Inline
Side-by-side
Showing
23 changed files
with
134 additions
and
144 deletions
+134
-144
Lib/fmt.py
Lib/fmt.py
+5
-4
Lib/fnmatch.py
Lib/fnmatch.py
+6
-9
Lib/fpformat.py
Lib/fpformat.py
+6
-7
Lib/glob.py
Lib/glob.py
+3
-3
Lib/keyword.py
Lib/keyword.py
+9
-9
Lib/lib-old/fmt.py
Lib/lib-old/fmt.py
+5
-4
Lib/mailbox.py
Lib/mailbox.py
+4
-3
Lib/mhlib.py
Lib/mhlib.py
+9
-15
Lib/nntplib.py
Lib/nntplib.py
+9
-10
Lib/pipes.py
Lib/pipes.py
+5
-5
Lib/plat-irix5/cddb.py
Lib/plat-irix5/cddb.py
+5
-6
Lib/plat-irix5/cdplayer.py
Lib/plat-irix5/cdplayer.py
+5
-5
Lib/plat-irix5/flp.py
Lib/plat-irix5/flp.py
+7
-8
Lib/plat-irix6/cddb.py
Lib/plat-irix6/cddb.py
+5
-6
Lib/plat-irix6/cdplayer.py
Lib/plat-irix6/cdplayer.py
+5
-5
Lib/plat-irix6/flp.py
Lib/plat-irix6/flp.py
+7
-8
Lib/posixpath.py
Lib/posixpath.py
+6
-6
Lib/pstats.py
Lib/pstats.py
+2
-2
Lib/rfc822.py
Lib/rfc822.py
+4
-5
Lib/string.py
Lib/string.py
+6
-3
Lib/stringold.py
Lib/stringold.py
+6
-3
Lib/token.py
Lib/token.py
+8
-10
Lib/tzparse.py
Lib/tzparse.py
+7
-8
No files found.
Lib/fmt.py
View file @
3ccd1e6e
...
@@ -461,9 +461,9 @@ class StdwinBackEnd(SavingBackEnd):
...
@@ -461,9 +461,9 @@ class StdwinBackEnd(SavingBackEnd):
self
.
paralist
[
para2
].
invert
(
d
,
pos1
,
pos2
)
self
.
paralist
[
para2
].
invert
(
d
,
pos1
,
pos2
)
#
#
def
search
(
self
,
prog
):
def
search
(
self
,
prog
):
import
re
gex
,
string
import
re
,
string
if
type
(
prog
)
==
type
(
''
):
if
type
(
prog
)
==
type
(
''
):
prog
=
re
gex
.
compile
(
string
.
lower
(
prog
))
prog
=
re
.
compile
(
string
.
lower
(
prog
))
if
self
.
selection
:
if
self
.
selection
:
iold
=
self
.
selection
[
0
][
0
]
iold
=
self
.
selection
[
0
][
0
]
else
:
else
:
...
@@ -474,8 +474,9 @@ class StdwinBackEnd(SavingBackEnd):
...
@@ -474,8 +474,9 @@ class StdwinBackEnd(SavingBackEnd):
continue
continue
p
=
self
.
paralist
[
i
]
p
=
self
.
paralist
[
i
]
text
=
string
.
lower
(
p
.
extract
())
text
=
string
.
lower
(
p
.
extract
())
if
prog
.
search
(
text
)
>=
0
:
match
=
prog
.
search
(
text
)
a
,
b
=
prog
.
regs
[
0
]
if
match
:
a
,
b
=
match
.
group
(
0
)
long1
=
i
,
a
long1
=
i
,
a
long2
=
i
,
b
long2
=
i
,
b
hit
=
long1
,
long2
hit
=
long1
,
long2
...
...
Lib/fnmatch.py
View file @
3ccd1e6e
...
@@ -10,6 +10,8 @@ The function translate(PATTERN) returns a regular expression
...
@@ -10,6 +10,8 @@ The function translate(PATTERN) returns a regular expression
corresponding to PATTERN. (It does not compile it.)
corresponding to PATTERN. (It does not compile it.)
"""
"""
import
re
_cache
=
{}
_cache
=
{}
def
fnmatch
(
name
,
pat
):
def
fnmatch
(
name
,
pat
):
...
@@ -42,11 +44,8 @@ def fnmatchcase(name, pat):
...
@@ -42,11 +44,8 @@ def fnmatchcase(name, pat):
if
not
_cache
.
has_key
(
pat
):
if
not
_cache
.
has_key
(
pat
):
res
=
translate
(
pat
)
res
=
translate
(
pat
)
import
regex
_cache
[
pat
]
=
re
.
compile
(
res
)
save_syntax
=
regex
.
set_syntax
(
0
)
return
_cache
[
pat
].
match
(
name
)
is
not
None
_cache
[
pat
]
=
regex
.
compile
(
res
)
save_syntax
=
regex
.
set_syntax
(
save_syntax
)
return
_cache
[
pat
].
match
(
name
)
==
len
(
name
)
def
translate
(
pat
):
def
translate
(
pat
):
"""Translate a shell PATTERN to a regular expression.
"""Translate a shell PATTERN to a regular expression.
...
@@ -85,8 +84,6 @@ def translate(pat):
...
@@ -85,8 +84,6 @@ def translate(pat):
stuff
=
stuff
[
1
:]
+
stuff
[
0
]
stuff
=
stuff
[
1
:]
+
stuff
[
0
]
stuff
=
'['
+
stuff
+
']'
stuff
=
'['
+
stuff
+
']'
res
=
res
+
stuff
res
=
res
+
stuff
elif
c
in
'
\
\
.+^$'
:
res
=
res
+
(
'
\
\
'
+
c
)
else
:
else
:
res
=
res
+
c
res
=
res
+
re
.
escape
(
c
)
return
res
return
res
+
"$"
Lib/fpformat.py
View file @
3ccd1e6e
...
@@ -11,11 +11,11 @@
...
@@ -11,11 +11,11 @@
# digits_behind: number of digits behind the decimal point
# digits_behind: number of digits behind the decimal point
import
re
gex
import
re
# Compiled regular expression to "decode" a number
# Compiled regular expression to "decode" a number
decoder
=
re
gex
.
compile
(
\
decoder
=
re
.
compile
(
\
'^
\
([-+]?
\
)0*
\
([
0
-9]*
\
)
\
(
\
(
\
.[0-9]*
\
)?
\
)
\
(
\
([eE][-+]?[0-9]+
\
)?
\
)$'
)
'^
([-+]?)0*([0-9]*)((
\
.[
0
-9]*)?)(([eE][-+]?[0-9]+)?
)$'
)
# \0 the whole thing
# \0 the whole thing
# \1 leading sign or empty
# \1 leading sign or empty
# \2 digits left of decimal point
# \2 digits left of decimal point
...
@@ -30,10 +30,9 @@ NotANumber = 'fpformat.NotANumber'
...
@@ -30,10 +30,9 @@ NotANumber = 'fpformat.NotANumber'
# fraction is 0 or more digits
# fraction is 0 or more digits
# expo is an integer
# expo is an integer
def
extract
(
s
):
def
extract
(
s
):
if
decoder
.
match
(
s
)
<
0
:
raise
NotANumber
m
=
decoder
.
match
(
s
)
(
a1
,
b1
),
(
a2
,
b2
),
(
a3
,
b3
),
(
a4
,
b4
),
(
a5
,
b5
)
=
decoder
.
regs
[
1
:
6
]
if
not
m
:
raise
NotANumber
sign
,
intpart
,
fraction
,
exppart
=
\
sign
,
intpart
,
fraction
,
exppart
=
m
.
group
(
1
,
2
,
3
,
5
)
s
[
a1
:
b1
],
s
[
a2
:
b2
],
s
[
a3
:
b3
],
s
[
a5
:
b5
]
if
sign
==
'+'
:
sign
=
''
if
sign
==
'+'
:
sign
=
''
if
fraction
:
fraction
=
fraction
[
1
:]
if
fraction
:
fraction
=
fraction
[
1
:]
if
exppart
:
expo
=
eval
(
exppart
[
1
:])
if
exppart
:
expo
=
eval
(
exppart
[
1
:])
...
...
Lib/glob.py
View file @
3ccd1e6e
...
@@ -2,7 +2,7 @@
...
@@ -2,7 +2,7 @@
import
os
import
os
import
fnmatch
import
fnmatch
import
re
gex
import
re
def
glob
(
pathname
):
def
glob
(
pathname
):
...
@@ -50,7 +50,7 @@ def glob1(dirname, pattern):
...
@@ -50,7 +50,7 @@ def glob1(dirname, pattern):
return
result
return
result
magic_check
=
re
gex
.
compile
(
'[*?[]'
)
magic_check
=
re
.
compile
(
'[*?[]'
)
def
has_magic
(
s
):
def
has_magic
(
s
):
return
magic_check
.
search
(
s
)
>=
0
return
magic_check
.
search
(
s
)
is
not
None
Lib/keyword.py
View file @
3ccd1e6e
...
@@ -7,10 +7,7 @@
...
@@ -7,10 +7,7 @@
# To update the symbols in this file, 'cd' to the top directory of
# To update the symbols in this file, 'cd' to the top directory of
# the python source tree after building the interpreter and run:
# the python source tree after building the interpreter and run:
#
#
# PYTHONPATH=./Lib ./python Lib/keyword.py
# python Lib/keyword.py
#
# (this path allows the import of string.py and regexmodule.so
# for a site with no installation in place)
kwlist
=
[
kwlist
=
[
#--start keywords--
#--start keywords--
...
@@ -52,7 +49,7 @@ for keyword in kwlist:
...
@@ -52,7 +49,7 @@ for keyword in kwlist:
iskeyword
=
kwdict
.
has_key
iskeyword
=
kwdict
.
has_key
def
main
():
def
main
():
import
sys
,
re
gex
,
string
import
sys
,
re
,
string
args
=
sys
.
argv
[
1
:]
args
=
sys
.
argv
[
1
:]
iptfile
=
args
and
args
[
0
]
or
"Python/graminit.c"
iptfile
=
args
and
args
[
0
]
or
"Python/graminit.c"
...
@@ -61,13 +58,15 @@ def main():
...
@@ -61,13 +58,15 @@ def main():
# scan the source file for keywords
# scan the source file for keywords
fp
=
open
(
iptfile
)
fp
=
open
(
iptfile
)
strprog
=
re
gex
.
compile
(
'"
\
([^
"
]+
\
)
"
'
)
strprog
=
re
.
compile
(
'"([^"]+
)"'
)
lines
=
[]
lines
=
[]
while
1
:
while
1
:
line
=
fp
.
readline
()
line
=
fp
.
readline
()
if
not
line
:
break
if
not
line
:
break
if
string
.
find
(
line
,
'{1, "'
)
>
-
1
and
strprog
.
search
(
line
)
>
-
1
:
if
string
.
find
(
line
,
'{1, "'
)
>
-
1
:
lines
.
append
(
" '"
+
strprog
.
group
(
1
)
+
"',
\
n
"
)
match
=
strprog
.
search
(
line
)
if
match
:
lines
.
append
(
" '"
+
match
.
group
(
1
)
+
"',
\
n
"
)
fp
.
close
()
fp
.
close
()
lines
.
sort
()
lines
.
sort
()
...
@@ -90,4 +89,5 @@ def main():
...
@@ -90,4 +89,5 @@ def main():
fp
.
write
(
string
.
join
(
format
,
''
))
fp
.
write
(
string
.
join
(
format
,
''
))
fp
.
close
()
fp
.
close
()
if
__name__
==
"__main__"
:
main
()
if
__name__
==
"__main__"
:
main
()
Lib/lib-old/fmt.py
View file @
3ccd1e6e
...
@@ -461,9 +461,9 @@ class StdwinBackEnd(SavingBackEnd):
...
@@ -461,9 +461,9 @@ class StdwinBackEnd(SavingBackEnd):
self
.
paralist
[
para2
].
invert
(
d
,
pos1
,
pos2
)
self
.
paralist
[
para2
].
invert
(
d
,
pos1
,
pos2
)
#
#
def
search
(
self
,
prog
):
def
search
(
self
,
prog
):
import
re
gex
,
string
import
re
,
string
if
type
(
prog
)
==
type
(
''
):
if
type
(
prog
)
==
type
(
''
):
prog
=
re
gex
.
compile
(
string
.
lower
(
prog
))
prog
=
re
.
compile
(
string
.
lower
(
prog
))
if
self
.
selection
:
if
self
.
selection
:
iold
=
self
.
selection
[
0
][
0
]
iold
=
self
.
selection
[
0
][
0
]
else
:
else
:
...
@@ -474,8 +474,9 @@ class StdwinBackEnd(SavingBackEnd):
...
@@ -474,8 +474,9 @@ class StdwinBackEnd(SavingBackEnd):
continue
continue
p
=
self
.
paralist
[
i
]
p
=
self
.
paralist
[
i
]
text
=
string
.
lower
(
p
.
extract
())
text
=
string
.
lower
(
p
.
extract
())
if
prog
.
search
(
text
)
>=
0
:
match
=
prog
.
search
(
text
)
a
,
b
=
prog
.
regs
[
0
]
if
match
:
a
,
b
=
match
.
group
(
0
)
long1
=
i
,
a
long1
=
i
,
a
long2
=
i
,
b
long2
=
i
,
b
hit
=
long1
,
long2
hit
=
long1
,
long2
...
...
Lib/mailbox.py
View file @
3ccd1e6e
...
@@ -5,7 +5,6 @@
...
@@ -5,7 +5,6 @@
import
rfc822
import
rfc822
import
os
import
os
import
regex
class
_Mailbox
:
class
_Mailbox
:
def
__init__
(
self
,
fp
):
def
__init__
(
self
,
fp
):
...
@@ -117,12 +116,13 @@ class MmdfMailbox(_Mailbox):
...
@@ -117,12 +116,13 @@ class MmdfMailbox(_Mailbox):
class
MHMailbox
:
class
MHMailbox
:
def
__init__
(
self
,
dirname
):
def
__init__
(
self
,
dirname
):
pat
=
regex
.
compile
(
'^[0-9][0-9]*$'
)
import
re
pat
=
re
.
compile
(
'^[0-9][0-9]*$'
)
self
.
dirname
=
dirname
self
.
dirname
=
dirname
files
=
os
.
listdir
(
self
.
dirname
)
files
=
os
.
listdir
(
self
.
dirname
)
self
.
boxes
=
[]
self
.
boxes
=
[]
for
f
in
files
:
for
f
in
files
:
if
pat
.
match
(
f
)
==
len
(
f
)
:
if
pat
.
match
(
f
):
self
.
boxes
.
append
(
f
)
self
.
boxes
.
append
(
f
)
def
next
(
self
):
def
next
(
self
):
...
@@ -187,6 +187,7 @@ def _test():
...
@@ -187,6 +187,7 @@ def _test():
if
not
msg
:
if
not
msg
:
break
break
msgs
.
append
(
msg
)
msgs
.
append
(
msg
)
msg
.
fp
=
None
if
len
(
args
)
>
1
:
if
len
(
args
)
>
1
:
num
=
string
.
atoi
(
args
[
1
])
num
=
string
.
atoi
(
args
[
1
])
print
'Message %d body:'
%
num
print
'Message %d body:'
%
num
...
...
Lib/mhlib.py
View file @
3ccd1e6e
...
@@ -73,7 +73,7 @@ FOLDER_PROTECT = 0700
...
@@ -73,7 +73,7 @@ FOLDER_PROTECT = 0700
import
os
import
os
import
sys
import
sys
from
stat
import
ST_NLINK
from
stat
import
ST_NLINK
import
re
gex
import
re
import
string
import
string
import
mimetools
import
mimetools
import
multifile
import
multifile
...
@@ -236,9 +236,9 @@ class MH:
...
@@ -236,9 +236,9 @@ class MH:
# Class representing a particular folder
# Class representing a particular folder
numericprog
=
re
gex
.
compile
(
'^[1-9][0-9]*$'
)
numericprog
=
re
.
compile
(
'^[1-9][0-9]*$'
)
def
isnumeric
(
str
):
def
isnumeric
(
str
):
return
numericprog
.
match
(
str
)
>=
0
return
numericprog
.
match
(
str
)
is
not
None
class
Folder
:
class
Folder
:
...
@@ -906,15 +906,12 @@ def pickline(file, key, casefold = 1):
...
@@ -906,15 +906,12 @@ def pickline(file, key, casefold = 1):
f
=
open
(
file
,
'r'
)
f
=
open
(
file
,
'r'
)
except
IOError
:
except
IOError
:
return
None
return
None
pat
=
key
+
':'
pat
=
re
.
escape
(
key
)
+
':'
if
casefold
:
prog
=
re
.
compile
(
pat
,
casefold
and
re
.
IGNORECASE
)
prog
=
regex
.
compile
(
pat
,
regex
.
casefold
)
else
:
prog
=
regex
.
compile
(
pat
)
while
1
:
while
1
:
line
=
f
.
readline
()
line
=
f
.
readline
()
if
not
line
:
break
if
not
line
:
break
if
prog
.
match
(
line
)
>=
0
:
if
prog
.
match
(
line
):
text
=
line
[
len
(
key
)
+
1
:]
text
=
line
[
len
(
key
)
+
1
:]
while
1
:
while
1
:
line
=
f
.
readline
()
line
=
f
.
readline
()
...
@@ -931,18 +928,15 @@ def updateline(file, key, value, casefold = 1):
...
@@ -931,18 +928,15 @@ def updateline(file, key, value, casefold = 1):
f
.
close
()
f
.
close
()
except
IOError
:
except
IOError
:
lines
=
[]
lines
=
[]
pat
=
key
+
':
\
(.*
\
)
\
n
'
pat
=
re
.
escape
(
key
)
+
':(.*)
\
n
'
if
casefold
:
prog
=
re
.
compile
(
pat
,
casefold
and
re
.
IGNORECASE
)
prog
=
regex
.
compile
(
pat
,
regex
.
casefold
)
else
:
prog
=
regex
.
compile
(
pat
)
if
value
is
None
:
if
value
is
None
:
newline
=
None
newline
=
None
else
:
else
:
newline
=
'%s: %s
\
n
'
%
(
key
,
value
)
newline
=
'%s: %s
\
n
'
%
(
key
,
value
)
for
i
in
range
(
len
(
lines
)):
for
i
in
range
(
len
(
lines
)):
line
=
lines
[
i
]
line
=
lines
[
i
]
if
prog
.
match
(
line
)
==
len
(
line
)
:
if
prog
.
match
(
line
):
if
newline
is
None
:
if
newline
is
None
:
del
lines
[
i
]
del
lines
[
i
]
else
:
else
:
...
...
Lib/nntplib.py
View file @
3ccd1e6e
...
@@ -29,7 +29,7 @@
...
@@ -29,7 +29,7 @@
# Imports
# Imports
import
re
gex
import
re
import
socket
import
socket
import
string
import
string
...
@@ -313,13 +313,13 @@ class NNTP:
...
@@ -313,13 +313,13 @@ class NNTP:
# - list: list of (nr, value) strings
# - list: list of (nr, value) strings
def
xhdr
(
self
,
hdr
,
str
):
def
xhdr
(
self
,
hdr
,
str
):
pat
=
re
.
compile
(
'^([0-9]+) ?(.*)
\
n
?'
)
resp
,
lines
=
self
.
longcmd
(
'XHDR '
+
hdr
+
' '
+
str
)
resp
,
lines
=
self
.
longcmd
(
'XHDR '
+
hdr
+
' '
+
str
)
for
i
in
range
(
len
(
lines
)):
for
i
in
range
(
len
(
lines
)):
line
=
lines
[
i
]
line
=
lines
[
i
]
n
=
regex
.
match
(
'^[0-9]+'
,
line
)
m
=
pat
.
match
(
line
)
nr
=
line
[:
n
]
if
m
:
if
n
<
len
(
line
)
and
line
[
n
]
==
' '
:
n
=
n
+
1
lines
[
i
]
=
m
.
group
(
1
,
2
)
lines
[
i
]
=
(
nr
,
line
[
n
:])
return
resp
,
lines
return
resp
,
lines
# Process an XOVER command (optional server extension) Arguments:
# Process an XOVER command (optional server extension) Arguments:
...
@@ -354,14 +354,13 @@ class NNTP:
...
@@ -354,14 +354,13 @@ class NNTP:
# - list: list of (name,title) strings
# - list: list of (name,title) strings
def
xgtitle
(
self
,
group
):
def
xgtitle
(
self
,
group
):
line_pat
=
re
gex
.
compile
(
"^
\
([^
\
t]+
\
)[
\
t]+
\
(.*
\
)$"
)
line_pat
=
re
.
compile
(
"^([^
\
t
]+)[
\
t
]+(.*
)$"
)
resp
,
raw_lines
=
self
.
longcmd
(
'XGTITLE '
+
group
)
resp
,
raw_lines
=
self
.
longcmd
(
'XGTITLE '
+
group
)
lines
=
[]
lines
=
[]
for
raw_line
in
raw_lines
:
for
raw_line
in
raw_lines
:
if
line_pat
.
search
(
string
.
strip
(
raw_line
))
==
0
:
match
=
line_pat
.
search
(
string
.
strip
(
raw_line
))
lines
.
append
(
line_pat
.
group
(
1
),
if
match
:
line_pat
.
group
(
2
))
lines
.
append
(
match
.
group
(
1
,
2
))
return
resp
,
lines
return
resp
,
lines
# Process an XPATH command (optional server extension) Arguments:
# Process an XPATH command (optional server extension) Arguments:
...
...
Lib/pipes.py
View file @
3ccd1e6e
...
@@ -61,7 +61,7 @@
...
@@ -61,7 +61,7 @@
import
sys
import
sys
import
re
gex
import
re
import
os
import
os
import
tempfile
import
tempfile
...
@@ -124,10 +124,10 @@ class Template:
...
@@ -124,10 +124,10 @@ class Template:
if
self
.
steps
<>
[]
and
self
.
steps
[
-
1
][
1
]
==
SINK
:
if
self
.
steps
<>
[]
and
self
.
steps
[
-
1
][
1
]
==
SINK
:
raise
ValueError
,
\
raise
ValueError
,
\
'Template.append: already ends with SINK'
'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
,
\
raise
ValueError
,
\
'Template.append: missing $IN in cmd'
'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
,
\
raise
ValueError
,
\
'Template.append: missing $OUT in cmd'
'Template.append: missing $OUT in cmd'
self
.
steps
.
append
((
cmd
,
kind
))
self
.
steps
.
append
((
cmd
,
kind
))
...
@@ -146,10 +146,10 @@ class Template:
...
@@ -146,10 +146,10 @@ class Template:
if
self
.
steps
<>
[]
and
self
.
steps
[
0
][
1
]
==
SOURCE
:
if
self
.
steps
<>
[]
and
self
.
steps
[
0
][
1
]
==
SOURCE
:
raise
ValueError
,
\
raise
ValueError
,
\
'Template.prepend: already begins with SOURCE'
'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
,
\
raise
ValueError
,
\
'Template.prepend: missing $IN in cmd'
'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
,
\
raise
ValueError
,
\
'Template.prepend: missing $OUT in cmd'
'Template.prepend: missing $OUT in cmd'
self
.
steps
.
insert
(
0
,
(
cmd
,
kind
))
self
.
steps
.
insert
(
0
,
(
cmd
,
kind
))
...
...
Lib/plat-irix5/cddb.py
View file @
3ccd1e6e
...
@@ -81,18 +81,17 @@ class Cddb:
...
@@ -81,18 +81,17 @@ class Cddb:
self
.
notes
=
[]
self
.
notes
=
[]
if
not
hasattr
(
self
,
'file'
):
if
not
hasattr
(
self
,
'file'
):
return
return
import
re
gex
import
re
reg
=
re
gex
.
compile
(
'^
\
\
([^.]*
\
\
)
\
\
.
\
\
([^:]*
\
\
):[
\
t
]+
\
\
(.*
\
\
)'
)
reg
=
re
.
compile
(
r'^([^.]*)\
.([^:]*):[
\t ]+(.*
)'
)
while
1
:
while
1
:
line
=
f
.
readline
()
line
=
f
.
readline
()
if
not
line
:
if
not
line
:
break
break
if
reg
.
match
(
line
)
==
-
1
:
match
=
reg
.
match
(
line
)
if
not
match
:
print
'syntax error in '
+
file
print
'syntax error in '
+
file
continue
continue
name1
=
line
[
reg
.
regs
[
1
][
0
]:
reg
.
regs
[
1
][
1
]]
name1
,
name2
,
value
=
match
.
group
(
1
,
2
,
3
)
name2
=
line
[
reg
.
regs
[
2
][
0
]:
reg
.
regs
[
2
][
1
]]
value
=
line
[
reg
.
regs
[
3
][
0
]:
reg
.
regs
[
3
][
1
]]
if
name1
==
'album'
:
if
name1
==
'album'
:
if
name2
==
'artist'
:
if
name2
==
'artist'
:
self
.
artist
=
value
self
.
artist
=
value
...
...
Lib/plat-irix5/cdplayer.py
View file @
3ccd1e6e
...
@@ -39,8 +39,8 @@ class Cdplayer:
...
@@ -39,8 +39,8 @@ class Cdplayer:
f
=
open
(
posix
.
environ
[
'HOME'
]
+
'/'
+
cdplayerrc
,
'r'
)
f
=
open
(
posix
.
environ
[
'HOME'
]
+
'/'
+
cdplayerrc
,
'r'
)
except
IOError
:
except
IOError
:
return
return
import
re
gex
import
re
reg
=
re
gex
.
compile
(
'^
\
\
([^:]*
\
\
):
\
t
\
\
(.*
\
\
)'
)
reg
=
re
.
compile
(
r'^([^:]*):\t(.*
)'
)
s
=
self
.
id
+
'.'
s
=
self
.
id
+
'.'
l
=
len
(
s
)
l
=
len
(
s
)
while
1
:
while
1
:
...
@@ -49,11 +49,11 @@ class Cdplayer:
...
@@ -49,11 +49,11 @@ class Cdplayer:
break
break
if
line
[:
l
]
==
s
:
if
line
[:
l
]
==
s
:
line
=
line
[
l
:]
line
=
line
[
l
:]
if
reg
.
match
(
line
)
==
-
1
:
match
=
reg
.
match
(
line
)
if
not
match
:
print
'syntax error in ~/'
+
cdplayerrc
print
'syntax error in ~/'
+
cdplayerrc
continue
continue
name
=
line
[
reg
.
regs
[
1
][
0
]:
reg
.
regs
[
1
][
1
]]
name
,
valye
=
match
.
group
(
1
,
2
)
value
=
line
[
reg
.
regs
[
2
][
0
]:
reg
.
regs
[
2
][
1
]]
if
name
==
'title'
:
if
name
==
'title'
:
self
.
title
=
value
self
.
title
=
value
elif
name
==
'artist'
:
elif
name
==
'artist'
:
...
...
Lib/plat-irix5/flp.py
View file @
3ccd1e6e
...
@@ -267,19 +267,18 @@ _parse_func = { \
...
@@ -267,19 +267,18 @@ _parse_func = { \
# This function parses a line, and returns either
# This function parses a line, and returns either
# a string or a tuple (name,value)
# a string or a tuple (name,value)
import
re
gex
import
re
prog
=
re
gex
.
compile
(
'^
\
([^:]*
\
): *
\
(.*
\
)'
)
prog
=
re
.
compile
(
'^([^:]*): *(.*
)'
)
def
_parse_line
(
line
):
def
_parse_line
(
line
):
if
prog
.
match
(
line
)
<
0
:
match
=
prog
.
match
(
line
)
if
not
match
:
return
line
return
line
a
=
prog
.
regs
name
,
value
=
match
.
group
(
1
,
2
)
name
=
line
[:
a
[
1
][
1
]]
if
name
[
0
]
==
'N'
:
if
name
[
0
]
==
'N'
:
name
=
string
.
join
fields
(
string
.
split
(
name
),
''
)
name
=
string
.
join
(
string
.
split
(
name
),
''
)
name
=
string
.
lower
(
name
)
name
=
string
.
lower
(
name
)
name
=
string
.
upper
(
name
[
0
])
+
name
[
1
:]
name
=
string
.
capitalize
(
name
)
value
=
line
[
a
[
2
][
0
]:]
try
:
try
:
pf
=
_parse_func
[
name
]
pf
=
_parse_func
[
name
]
except
KeyError
:
except
KeyError
:
...
...
Lib/plat-irix6/cddb.py
View file @
3ccd1e6e
...
@@ -81,18 +81,17 @@ class Cddb:
...
@@ -81,18 +81,17 @@ class Cddb:
self
.
notes
=
[]
self
.
notes
=
[]
if
not
hasattr
(
self
,
'file'
):
if
not
hasattr
(
self
,
'file'
):
return
return
import
re
gex
import
re
reg
=
re
gex
.
compile
(
'^
\
\
([^.]*
\
\
)
\
\
.
\
\
([^:]*
\
\
):[
\
t
]+
\
\
(.*
\
\
)'
)
reg
=
re
.
compile
(
r'^([^.]*)\
.([^:]*):[
\t ]+(.*
)'
)
while
1
:
while
1
:
line
=
f
.
readline
()
line
=
f
.
readline
()
if
not
line
:
if
not
line
:
break
break
if
reg
.
match
(
line
)
==
-
1
:
match
=
reg
.
match
(
line
)
if
not
match
:
print
'syntax error in '
+
file
print
'syntax error in '
+
file
continue
continue
name1
=
line
[
reg
.
regs
[
1
][
0
]:
reg
.
regs
[
1
][
1
]]
name1
,
name2
,
value
=
match
.
group
(
1
,
2
,
3
)
name2
=
line
[
reg
.
regs
[
2
][
0
]:
reg
.
regs
[
2
][
1
]]
value
=
line
[
reg
.
regs
[
3
][
0
]:
reg
.
regs
[
3
][
1
]]
if
name1
==
'album'
:
if
name1
==
'album'
:
if
name2
==
'artist'
:
if
name2
==
'artist'
:
self
.
artist
=
value
self
.
artist
=
value
...
...
Lib/plat-irix6/cdplayer.py
View file @
3ccd1e6e
...
@@ -39,8 +39,8 @@ class Cdplayer:
...
@@ -39,8 +39,8 @@ class Cdplayer:
f
=
open
(
posix
.
environ
[
'HOME'
]
+
'/'
+
cdplayerrc
,
'r'
)
f
=
open
(
posix
.
environ
[
'HOME'
]
+
'/'
+
cdplayerrc
,
'r'
)
except
IOError
:
except
IOError
:
return
return
import
re
gex
import
re
reg
=
re
gex
.
compile
(
'^
\
\
([^:]*
\
\
):
\
t
\
\
(.*
\
\
)'
)
reg
=
re
.
compile
(
r'^([^:]*):\t(.*
)'
)
s
=
self
.
id
+
'.'
s
=
self
.
id
+
'.'
l
=
len
(
s
)
l
=
len
(
s
)
while
1
:
while
1
:
...
@@ -49,11 +49,11 @@ class Cdplayer:
...
@@ -49,11 +49,11 @@ class Cdplayer:
break
break
if
line
[:
l
]
==
s
:
if
line
[:
l
]
==
s
:
line
=
line
[
l
:]
line
=
line
[
l
:]
if
reg
.
match
(
line
)
==
-
1
:
match
=
reg
.
match
(
line
)
if
not
match
:
print
'syntax error in ~/'
+
cdplayerrc
print
'syntax error in ~/'
+
cdplayerrc
continue
continue
name
=
line
[
reg
.
regs
[
1
][
0
]:
reg
.
regs
[
1
][
1
]]
name
,
valye
=
match
.
group
(
1
,
2
)
value
=
line
[
reg
.
regs
[
2
][
0
]:
reg
.
regs
[
2
][
1
]]
if
name
==
'title'
:
if
name
==
'title'
:
self
.
title
=
value
self
.
title
=
value
elif
name
==
'artist'
:
elif
name
==
'artist'
:
...
...
Lib/plat-irix6/flp.py
View file @
3ccd1e6e
...
@@ -267,19 +267,18 @@ _parse_func = { \
...
@@ -267,19 +267,18 @@ _parse_func = { \
# This function parses a line, and returns either
# This function parses a line, and returns either
# a string or a tuple (name,value)
# a string or a tuple (name,value)
import
re
gex
import
re
prog
=
re
gex
.
compile
(
'^
\
([^:]*
\
): *
\
(.*
\
)'
)
prog
=
re
.
compile
(
'^([^:]*): *(.*
)'
)
def
_parse_line
(
line
):
def
_parse_line
(
line
):
if
prog
.
match
(
line
)
<
0
:
match
=
prog
.
match
(
line
)
if
not
match
:
return
line
return
line
a
=
prog
.
regs
name
,
value
=
match
.
group
(
1
,
2
)
name
=
line
[:
a
[
1
][
1
]]
if
name
[
0
]
==
'N'
:
if
name
[
0
]
==
'N'
:
name
=
string
.
join
fields
(
string
.
split
(
name
),
''
)
name
=
string
.
join
(
string
.
split
(
name
),
''
)
name
=
string
.
lower
(
name
)
name
=
string
.
lower
(
name
)
name
=
string
.
upper
(
name
[
0
])
+
name
[
1
:]
name
=
string
.
capitalize
(
name
)
value
=
line
[
a
[
2
][
0
]:]
try
:
try
:
pf
=
_parse_func
[
name
]
pf
=
_parse_func
[
name
]
except
KeyError
:
except
KeyError
:
...
...
Lib/posixpath.py
View file @
3ccd1e6e
...
@@ -266,15 +266,15 @@ def expandvars(path):
...
@@ -266,15 +266,15 @@ def expandvars(path):
if
'$'
not
in
path
:
if
'$'
not
in
path
:
return
path
return
path
if
not
_varprog
:
if
not
_varprog
:
import
re
gex
import
re
_varprog
=
re
gex
.
compile
(
'$
\
([
a
-zA-Z0-9_]+
\
|{[^}]*}
\
)'
)
_varprog
=
re
.
compile
(
r'\
$(
\w+|\
{[^}]*
\}
)'
)
i
=
0
i
=
0
while
1
:
while
1
:
i
=
_varprog
.
search
(
path
,
i
)
m
=
_varprog
.
search
(
path
,
i
)
if
i
<
0
:
if
not
m
:
break
break
name
=
_varprog
.
group
(
1
)
i
,
j
=
m
.
span
(
0
)
j
=
i
+
len
(
_varprog
.
group
(
0
)
)
name
=
m
.
group
(
1
)
if
name
[:
1
]
==
'{'
and
name
[
-
1
:]
==
'}'
:
if
name
[:
1
]
==
'{'
and
name
[
-
1
:]
==
'}'
:
name
=
name
[
1
:
-
1
]
name
=
name
[
1
:
-
1
]
if
os
.
environ
.
has_key
(
name
):
if
os
.
environ
.
has_key
(
name
):
...
...
Lib/pstats.py
View file @
3ccd1e6e
...
@@ -35,7 +35,7 @@ import os
...
@@ -35,7 +35,7 @@ import os
import
time
import
time
import
string
import
string
import
marshal
import
marshal
import
re
gex
import
re
#**************************************************************************
#**************************************************************************
# Class Stats documentation
# Class Stats documentation
...
@@ -300,7 +300,7 @@ class Stats:
...
@@ -300,7 +300,7 @@ class Stats:
if
type
(
sel
)
==
type
(
""
):
if
type
(
sel
)
==
type
(
""
):
new_list
=
[]
new_list
=
[]
for
func
in
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
)
new_list
.
append
(
func
)
else
:
else
:
count
=
len
(
list
)
count
=
len
(
list
)
...
...
Lib/rfc822.py
View file @
3ccd1e6e
...
@@ -38,7 +38,7 @@
...
@@ -38,7 +38,7 @@
# There are also some utility functions here.
# There are also some utility functions here.
import
re
gex
import
re
import
string
import
string
import
time
import
time
...
@@ -311,7 +311,7 @@ def unquote(str):
...
@@ -311,7 +311,7 @@ def unquote(str):
error
=
'parseaddr.error'
error
=
'parseaddr.error'
specials
=
re
gex
.
compile
(
'[][()<>,.;:@
\
\
"
\
000
-
\
037
\
177
-
\
377
]'
)
specials
=
re
.
compile
(
r'[][()<>,.;:@
\" \000-\037\177-\377]'
)
def
quote
(
str
):
def
quote
(
str
):
return
'"%s"'
%
string
.
join
(
return
'"%s"'
%
string
.
join
(
...
@@ -408,7 +408,7 @@ def parseaddr(address):
...
@@ -408,7 +408,7 @@ def parseaddr(address):
else
:
else
:
name
.
append
(
token
[
1
])
name
.
append
(
token
[
1
])
elif
token
[
0
]
==
1
and
cur
is
addr
:
elif
token
[
0
]
==
1
and
cur
is
addr
:
if
specials
.
search
(
token
[
1
])
>=
0
:
if
specials
.
search
(
token
[
1
]):
cur
.
append
(
quote
(
token
[
1
]))
cur
.
append
(
quote
(
token
[
1
]))
else
:
else
:
cur
.
append
(
token
[
1
])
cur
.
append
(
token
[
1
])
...
@@ -423,7 +423,7 @@ def parseaddr(address):
...
@@ -423,7 +423,7 @@ def parseaddr(address):
if
token
[
0
]
==
2
:
if
token
[
0
]
==
2
:
name
.
append
(
token
[
1
])
name
.
append
(
token
[
1
])
elif
token
[
0
]
==
1
:
elif
token
[
0
]
==
1
:
if
specials
.
search
(
token
[
1
])
>=
0
:
if
specials
.
search
(
token
[
1
]):
addr
.
append
(
quote
(
token
[
1
]))
addr
.
append
(
quote
(
token
[
1
]))
else
:
else
:
addr
.
append
(
token
[
1
])
addr
.
append
(
token
[
1
])
...
@@ -563,4 +563,3 @@ if __name__ == '__main__':
...
@@ -563,4 +563,3 @@ if __name__ == '__main__':
print
'keys ='
,
m
.
keys
()
print
'keys ='
,
m
.
keys
()
print
'values ='
,
m
.
values
()
print
'values ='
,
m
.
values
()
print
'items ='
,
m
.
items
()
print
'items ='
,
m
.
items
()
Lib/string.py
View file @
3ccd1e6e
...
@@ -193,17 +193,20 @@ def rfind(s, sub, i = 0, last=None):
...
@@ -193,17 +193,20 @@ def rfind(s, sub, i = 0, last=None):
return
r
return
r
# Convert string to float
# Convert string to float
re
=
None
def
atof
(
str
):
def
atof
(
str
):
import
regex
global
re
if
re
is
None
:
import
re
sign
=
''
sign
=
''
s
=
str
s
=
str
ip
(
str
)
if
s
and
s
[
0
]
in
'+-'
:
if
s
and
s
[
0
]
in
'+-'
:
sign
=
s
[
0
]
sign
=
s
[
0
]
s
=
s
[
1
:]
s
=
s
[
1
:]
if
not
s
:
if
not
s
:
raise
ValueError
,
'non-float argument to string.atof'
raise
ValueError
,
'non-float argument to string.atof'
while
s
[
0
]
==
'0'
and
len
(
s
)
>
1
and
s
[
1
]
in
digits
:
s
=
s
[
1
:]
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'
raise
ValueError
,
'non-float argument to string.atof'
try
:
try
:
return
float
(
eval
(
sign
+
s
))
return
float
(
eval
(
sign
+
s
))
...
...
Lib/stringold.py
View file @
3ccd1e6e
...
@@ -193,17 +193,20 @@ def rfind(s, sub, i = 0, last=None):
...
@@ -193,17 +193,20 @@ def rfind(s, sub, i = 0, last=None):
return
r
return
r
# Convert string to float
# Convert string to float
re
=
None
def
atof
(
str
):
def
atof
(
str
):
import
regex
global
re
if
re
is
None
:
import
re
sign
=
''
sign
=
''
s
=
str
s
=
str
ip
(
str
)
if
s
and
s
[
0
]
in
'+-'
:
if
s
and
s
[
0
]
in
'+-'
:
sign
=
s
[
0
]
sign
=
s
[
0
]
s
=
s
[
1
:]
s
=
s
[
1
:]
if
not
s
:
if
not
s
:
raise
ValueError
,
'non-float argument to string.atof'
raise
ValueError
,
'non-float argument to string.atof'
while
s
[
0
]
==
'0'
and
len
(
s
)
>
1
and
s
[
1
]
in
digits
:
s
=
s
[
1
:]
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'
raise
ValueError
,
'non-float argument to string.atof'
try
:
try
:
return
float
(
eval
(
sign
+
s
))
return
float
(
eval
(
sign
+
s
))
...
...
Lib/token.py
View file @
3ccd1e6e
...
@@ -7,10 +7,7 @@
...
@@ -7,10 +7,7 @@
# To update the symbols in this file, 'cd' to the top directory of
# To update the symbols in this file, 'cd' to the top directory of
# the python source tree after building the interpreter and run:
# the python source tree after building the interpreter and run:
#
#
# PYTHONPATH=./Lib ./python Lib/token.py
# python Lib/token.py
#
# (this path allows the import of string.py and regexmodule.so
# for a site with no installation in place)
#--start constants--
#--start constants--
ENDMARKER
=
0
ENDMARKER
=
0
...
@@ -73,7 +70,7 @@ def ISEOF(x):
...
@@ -73,7 +70,7 @@ def ISEOF(x):
def
main
():
def
main
():
import
re
gex
import
re
import
string
import
string
import
sys
import
sys
args
=
sys
.
argv
[
1
:]
args
=
sys
.
argv
[
1
:]
...
@@ -88,13 +85,14 @@ def main():
...
@@ -88,13 +85,14 @@ def main():
sys
.
exit
(
1
)
sys
.
exit
(
1
)
lines
=
string
.
splitfields
(
fp
.
read
(),
"
\
n
"
)
lines
=
string
.
splitfields
(
fp
.
read
(),
"
\
n
"
)
fp
.
close
()
fp
.
close
()
re
=
regex
.
compile
(
prog
=
re
.
compile
(
"#define[
\
t
][
\
t
]*
\
([A-Z][A-Z_]*
\
)[
\
t
][
\
t
]*
\
([
0
-9][0-9]*
\
)
"
,
"#define[
\
t
][
\
t
]*
([A-Z][A-Z_]*)[
\
t
][
\
t
]*([0-9][0-9]*
)"
,
re
gex.casefold
)
re
.
IGNORECASE
)
tokens
=
{}
tokens
=
{}
for
line
in
lines
:
for
line
in
lines
:
if re.match(line) > -1:
match
=
prog
.
match
(
line
)
name, val = re.group(1, 2)
if
match
:
name
,
val
=
match
.
group
(
1
,
2
)
val
=
string
.
atoi
(
val
)
val
=
string
.
atoi
(
val
)
tokens
[
val
]
=
name
# reverse so we can sort them...
tokens
[
val
]
=
name
# reverse so we can sort them...
keys
=
tokens
.
keys
()
keys
=
tokens
.
keys
()
...
...
Lib/tzparse.py
View file @
3ccd1e6e
...
@@ -2,23 +2,22 @@
...
@@ -2,23 +2,22 @@
# XXX Unfinished.
# XXX Unfinished.
# XXX Only the typical form "XXXhhYYY;ddd/hh,ddd/hh" is currently supported.
# 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]
\
);
'
+
\
tzpat
=
(
'^([A-Z][A-Z][A-Z])([-+]?[0-9]+)([A-Z][A-Z][A-Z]);'
'
\
([
0
-
9
]
+
\
)
/
\
([
0
-
9
]
+
\
),
\
([
0
-
9
]
+
\
)
/
\
([
0
-
9
]
+
\
)
$
'
'
([0-9]+)/([0-9]+),([0-9]+)/([0-9]+)$'
)
tzprog
=
None
tzprog
=
None
def
tzparse
(
tzstr
):
def
tzparse
(
tzstr
):
global
tzprog
global
tzprog
if
tzprog
==
None
:
if
tzprog
==
None
:
import regex
import
re
tzprog = regex.compile(tzpat)
tzprog
=
re
.
compile
(
tzpat
)
if tzprog.match(tzstr) < 0:
match
=
tzprog
.
match
(
tzstr
)
if
not
match
:
raise
ValueError
,
'not the TZ syntax I understand'
raise
ValueError
,
'not the TZ syntax I understand'
regs = tzprog.regs
subs
=
[]
subs
=
[]
for
i
in
range
(
1
,
8
):
for
i
in
range
(
1
,
8
):
a, b = regs[i]
subs
.
append
(
match
.
group
(
i
))
subs.append(tzstr[a:b])
for
i
in
(
1
,
3
,
4
,
5
,
6
):
for
i
in
(
1
,
3
,
4
,
5
,
6
):
subs
[
i
]
=
eval
(
subs
[
i
])
subs
[
i
]
=
eval
(
subs
[
i
])
[
tzname
,
delta
,
dstname
,
daystart
,
hourstart
,
dayend
,
hourend
]
=
subs
[
tzname
,
delta
,
dstname
,
daystart
,
hourstart
,
dayend
,
hourend
]
=
subs
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment