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
b08b2d31
Commit
b08b2d31
authored
Feb 09, 2001
by
Eric S. Raymond
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
String method conversion.
parent
be9b507b
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
35 additions
and
38 deletions
+35
-38
Lib/formatter.py
Lib/formatter.py
+4
-4
Lib/nturl2path.py
Lib/nturl2path.py
+10
-10
Lib/sre.py
Lib/sre.py
+1
-3
Lib/token.py
Lib/token.py
+3
-3
Lib/tokenize.py
Lib/tokenize.py
+1
-1
Lib/urllib2.py
Lib/urllib2.py
+16
-17
No files found.
Lib/formatter.py
View file @
b08b2d31
...
...
@@ -157,7 +157,7 @@ class AbstractFormatter:
label
=
s
+
label
index
=
index
+
1
if
case
==
'I'
:
return
string
.
upper
(
label
)
return
label
.
upper
(
)
return
label
def
add_flowing_data
(
self
,
data
,
...
...
@@ -369,11 +369,11 @@ class DumbWriter(NullWriter):
def
send_literal_data
(
self
,
data
):
self
.
file
.
write
(
data
)
i
=
string
.
rfind
(
data
,
'
\
n
'
)
i
=
data
.
rfind
(
'
\
n
'
)
if
i
>=
0
:
self
.
col
=
0
data
=
data
[
i
+
1
:]
data
=
string
.
expandtabs
(
data
)
data
=
data
.
expandtabs
(
)
self
.
col
=
self
.
col
+
len
(
data
)
self
.
atbreak
=
0
...
...
@@ -383,7 +383,7 @@ class DumbWriter(NullWriter):
col
=
self
.
col
maxcol
=
self
.
maxcol
write
=
self
.
file
.
write
for
word
in
string
.
split
(
data
):
for
word
in
data
.
split
(
):
if
atbreak
:
if
col
+
len
(
word
)
>=
maxcol
:
write
(
'
\
n
'
)
...
...
Lib/nturl2path.py
View file @
b08b2d31
...
...
@@ -19,15 +19,15 @@ def url2pathname(url):
# convert this to \\host\path\on\remote\host
# (notice halving of slashes at the start of the path)
url
=
url
[
2
:]
components
=
string
.
split
(
url
,
'/'
)
components
=
url
.
split
(
'/'
)
# make sure not to convert quoted slashes :-)
return
urllib
.
unquote
(
string
.
join
(
components
,
'
\
\
'
))
comp
=
string
.
split
(
url
,
'|'
)
return
urllib
.
unquote
(
'
\
\
'
.
join
(
components
))
comp
=
url
.
split
(
'|'
)
if
len
(
comp
)
!=
2
or
comp
[
0
][
-
1
]
not
in
string
.
letters
:
error
=
'Bad URL: '
+
url
raise
IOError
,
error
drive
=
string
.
upper
(
comp
[
0
][
-
1
]
)
components
=
string
.
split
(
comp
[
1
],
'/'
)
drive
=
comp
[
0
][
-
1
].
upper
(
)
components
=
comp
[
1
].
split
(
'/'
)
path
=
drive
+
':'
for
comp
in
components
:
if
comp
:
...
...
@@ -52,15 +52,15 @@ def pathname2url(p):
# convert this to ////host/path/on/remote/host
# (notice doubling of slashes at the start of the path)
p
=
'
\
\
\
\
'
+
p
components
=
string
.
split
(
p
,
'
\
\
'
)
return
urllib
.
quote
(
string
.
join
(
components
,
'/'
))
comp
=
string
.
split
(
p
,
':'
)
components
=
p
.
split
(
'
\
\
'
)
return
urllib
.
quote
(
'/'
.
join
(
components
))
comp
=
p
.
split
(
':'
)
if
len
(
comp
)
!=
2
or
len
(
comp
[
0
])
>
1
:
error
=
'Bad path: '
+
p
raise
IOError
,
error
drive
=
urllib
.
quote
(
string
.
upper
(
comp
[
0
]
))
components
=
string
.
split
(
comp
[
1
],
'
\
\
'
)
drive
=
urllib
.
quote
(
comp
[
0
].
upper
(
))
components
=
comp
[
1
].
split
(
'
\
\
'
)
path
=
'///'
+
drive
+
'|'
for
comp
in
components
:
if
comp
:
...
...
Lib/sre.py
View file @
b08b2d31
...
...
@@ -17,8 +17,6 @@
import
sre_compile
import
sre_parse
import
string
# flags
I
=
IGNORECASE
=
sre_compile
.
SRE_FLAG_IGNORECASE
# ignore case
L
=
LOCALE
=
sre_compile
.
SRE_FLAG_LOCALE
# assume current 8-bit locale
...
...
@@ -109,7 +107,7 @@ _MAXCACHE = 100
def
_join
(
seq
,
sep
):
# internal: join into string having the same type as sep
return
s
tring
.
join
(
seq
,
sep
[:
0
]
)
return
s
ep
[:
0
].
join
(
seq
)
def
_compile
(
*
key
):
# internal: compile pattern
...
...
Lib/token.py
View file @
b08b2d31
...
...
@@ -94,7 +94,7 @@ def main():
except
IOError
,
err
:
sys
.
stdout
.
write
(
"I/O error: %s
\
n
"
%
str
(
err
))
sys
.
exit
(
1
)
lines
=
string
.
splitfields
(
fp
.
read
(),
"
\
n
"
)
lines
=
fp
.
read
().
split
(
"
\
n
"
)
fp
.
close
()
prog
=
re
.
compile
(
"#define[
\
t
][
\
t
]*([A-Z][A-Z_]*)[
\
t
][
\
t
]*([0-9][0-9]*)"
,
...
...
@@ -114,7 +114,7 @@ def main():
except
IOError
,
err
:
sys
.
stderr
.
write
(
"I/O error: %s
\
n
"
%
str
(
err
))
sys
.
exit
(
2
)
format
=
string
.
splitfields
(
fp
.
read
(),
"
\
n
"
)
format
=
fp
.
read
().
split
(
"
\
n
"
)
fp
.
close
()
try
:
start
=
format
.
index
(
"#--start constants--"
)
+
1
...
...
@@ -131,7 +131,7 @@ def main():
except
IOError
,
err
:
sys
.
stderr
.
write
(
"I/O error: %s
\
n
"
%
str
(
err
))
sys
.
exit
(
4
)
fp
.
write
(
string
.
joinfields
(
format
,
"
\
n
"
))
fp
.
write
(
"
\
n
"
.
join
(
format
))
fp
.
close
()
...
...
Lib/tokenize.py
View file @
b08b2d31
...
...
@@ -26,7 +26,7 @@ tok_name[NL] = 'NL'
# Imagnumber is new. Expfloat is corrected to reject '0e4'.
# Note: to quote a backslash in a regex, it must be doubled in a r'aw' string.
def
group
(
*
choices
):
return
'('
+
string
.
join
(
choices
,
'|'
)
+
')'
def
group
(
*
choices
):
return
'('
+
'|'
.
join
(
choices
)
+
')'
def
any
(
*
choices
):
return
apply
(
group
,
choices
)
+
'*'
def
maybe
(
*
choices
):
return
apply
(
group
,
choices
)
+
'?'
...
...
Lib/urllib2.py
View file @
b08b2d31
...
...
@@ -85,7 +85,6 @@ f = urllib2.urlopen('http://www.python.org/')
# gopher can return a socket.error
# check digest against correct (i.e. non-apache) implementation
import
string
import
socket
import
UserDict
import
httplib
...
...
@@ -265,13 +264,13 @@ class OpenerDirector:
self
.
handle_open
[
protocol
]
=
[
handler
]
added
=
1
continue
i
=
string
.
find
(
meth
,
'_'
)
j
=
string
.
find
(
meth
[
i
+
1
:],
'_'
)
+
i
+
1
i
=
meth
.
find
(
'_'
)
j
=
meth
[
i
+
1
:].
find
(
'_'
)
+
i
+
1
if
j
!=
-
1
and
meth
[
i
+
1
:
j
]
==
'error'
:
proto
=
meth
[:
i
]
kind
=
meth
[
j
+
1
:]
try
:
kind
=
string
.
atoi
(
kind
)
kind
=
int
(
kind
)
except
ValueError
:
pass
dict
=
self
.
handle_error
.
get
(
proto
,
{})
...
...
@@ -599,7 +598,7 @@ class HTTPBasicAuthHandler(BaseHandler):
mo
=
HTTPBasicAuthHandler
.
rx
.
match
(
authreq
)
if
mo
:
scheme
,
realm
=
mo
.
groups
()
if
s
tring
.
lower
(
scheme
)
==
'basic'
:
if
s
cheme
.
lower
(
)
==
'basic'
:
return
self
.
retry_http_basic_auth
(
req
,
realm
)
def
retry_http_basic_auth
(
self
,
req
,
realm
):
...
...
@@ -613,7 +612,7 @@ class HTTPBasicAuthHandler(BaseHandler):
user
,
pw
=
self
.
passwd
.
find_user_password
(
realm
,
host
)
if
pw
:
raw
=
"%s:%s"
%
(
user
,
pw
)
auth
=
string
.
strip
(
base64
.
encodestring
(
raw
)
)
auth
=
base64
.
encodestring
(
raw
).
strip
(
)
req
.
add_header
(
'Authorization'
,
'Basic %s'
%
auth
)
resp
=
self
.
parent
.
open
(
req
)
self
.
__current_realm
=
None
...
...
@@ -638,12 +637,12 @@ class HTTPDigestAuthHandler(BaseHandler):
# XXX could be mult. headers
authreq
=
headers
.
get
(
'www-authenticate'
,
None
)
if
authreq
:
kind
=
string
.
split
(
authreq
)[
0
]
kind
=
authreq
.
split
(
)[
0
]
if
kind
==
'Digest'
:
return
self
.
retry_http_digest_auth
(
req
,
authreq
)
def
retry_http_digest_auth
(
self
,
req
,
auth
):
token
,
challenge
=
string
.
split
(
auth
,
' '
,
1
)
token
,
challenge
=
auth
.
split
(
' '
,
1
)
chal
=
parse_keqv_list
(
parse_http_list
(
challenge
))
auth
=
self
.
get_authorization
(
req
,
chal
)
if
auth
:
...
...
@@ -723,7 +722,7 @@ def encode_digest(digest):
hexrep
.
append
(
hex
(
n
)[
-
1
])
n
=
ord
(
c
)
&
0xf
hexrep
.
append
(
hex
(
n
)[
-
1
])
return
string
.
join
(
hexrep
,
''
)
return
''
.
join
(
hexrep
)
class
HTTPHandler
(
BaseHandler
):
...
...
@@ -772,7 +771,7 @@ def parse_keqv_list(l):
"""Parse list of key=value strings where keys are not duplicated."""
parsed
=
{}
for
elt
in
l
:
k
,
v
=
string
.
split
(
elt
,
'='
,
1
)
k
,
v
=
elt
.
split
(
'='
,
1
)
if
v
[
0
]
==
'"'
and
v
[
-
1
]
==
'"'
:
v
=
v
[
1
:
-
1
]
parsed
[
k
]
=
v
...
...
@@ -794,8 +793,8 @@ def parse_http_list(s):
start
=
0
while
i
<
end
:
cur
=
s
[
i
:]
c
=
string
.
find
(
cur
,
','
)
q
=
string
.
find
(
cur
,
'"'
)
c
=
cur
.
find
(
','
)
q
=
cur
.
find
(
'"'
)
if
c
==
-
1
:
list
.
append
(
s
[
start
:])
break
...
...
@@ -822,7 +821,7 @@ def parse_http_list(s):
else
:
inquote
=
1
i
=
i
+
q
+
1
return
map
(
string
.
strip
,
list
)
return
map
(
lambda
x
:
x
.
strip
()
,
list
)
class
FileHandler
(
BaseHandler
):
# Use local file or FTP depending on form of URL
...
...
@@ -872,7 +871,7 @@ class FTPHandler(BaseHandler):
port
=
ftplib
.
FTP_PORT
path
,
attrs
=
splitattr
(
req
.
get_selector
())
path
=
unquote
(
path
)
dirs
=
string
.
splitfields
(
path
,
'/'
)
dirs
=
path
.
split
(
'/'
)
dirs
,
file
=
dirs
[:
-
1
],
dirs
[
-
1
]
if
dirs
and
not
dirs
[
0
]:
dirs
=
dirs
[
1
:]
...
...
@@ -882,9 +881,9 @@ class FTPHandler(BaseHandler):
type
=
file
and
'I'
or
'D'
for
attr
in
attrs
:
attr
,
value
=
splitattr
(
attr
)
if
string
.
lower
(
attr
)
==
'type'
and
\
if
attr
.
lower
(
)
==
'type'
and
\
value
in
(
'a'
,
'A'
,
'i'
,
'I'
,
'd'
,
'D'
):
type
=
string
.
upper
(
value
)
type
=
value
.
upper
(
)
fp
,
retrlen
=
fw
.
retrfile
(
file
,
type
)
if
retrlen
is
not
None
and
retrlen
>=
0
:
sf
=
StringIO
(
'Content-Length: %d
\
n
'
%
retrlen
)
...
...
@@ -1048,7 +1047,7 @@ if __name__ == "__main__":
p
=
CustomProxy
(
'http'
,
at_cnri
,
'proxy.cnri.reston.va.us'
)
ph
=
CustomProxyHandler
(
p
)
install_opener
(
build_opener
(
dauth
,
bauth
,
cfh
,
GopherHandler
,
ph
))
#
install_opener(build_opener(dauth, bauth, cfh, GopherHandler, ph))
for
url
in
urls
:
if
type
(
url
)
==
types
.
TupleType
:
...
...
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