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
7e9b4f58
Commit
7e9b4f58
authored
Feb 09, 2001
by
Eric S. Raymond
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
String method conversion.
parent
9f8cdf58
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
26 additions
and
27 deletions
+26
-27
Lib/cgi.py
Lib/cgi.py
+26
-27
No files found.
Lib/cgi.py
View file @
7e9b4f58
...
@@ -25,7 +25,6 @@ __version__ = "2.5"
...
@@ -25,7 +25,6 @@ __version__ = "2.5"
# Imports
# Imports
# =======
# =======
import
string
import
sys
import
sys
import
os
import
os
import
urllib
import
urllib
...
@@ -125,7 +124,7 @@ def parse(fp=None, environ=os.environ, keep_blank_values=0, strict_parsing=0):
...
@@ -125,7 +124,7 @@ def parse(fp=None, environ=os.environ, keep_blank_values=0, strict_parsing=0):
if
ctype
==
'multipart/form-data'
:
if
ctype
==
'multipart/form-data'
:
return
parse_multipart
(
fp
,
pdict
)
return
parse_multipart
(
fp
,
pdict
)
elif
ctype
==
'application/x-www-form-urlencoded'
:
elif
ctype
==
'application/x-www-form-urlencoded'
:
clength
=
string
.
atoi
(
environ
[
'CONTENT_LENGTH'
])
clength
=
int
(
environ
[
'CONTENT_LENGTH'
])
if
maxlen
and
clength
>
maxlen
:
if
maxlen
and
clength
>
maxlen
:
raise
ValueError
,
'Maximum content length exceeded'
raise
ValueError
,
'Maximum content length exceeded'
qs
=
fp
.
read
(
clength
)
qs
=
fp
.
read
(
clength
)
...
@@ -203,8 +202,8 @@ def parse_qsl(qs, keep_blank_values=0, strict_parsing=0):
...
@@ -203,8 +202,8 @@ def parse_qsl(qs, keep_blank_values=0, strict_parsing=0):
raise
ValueError
,
"bad query field: %s"
%
`name_value`
raise
ValueError
,
"bad query field: %s"
%
`name_value`
continue
continue
if
len
(
nv
[
1
])
or
keep_blank_values
:
if
len
(
nv
[
1
])
or
keep_blank_values
:
name
=
urllib
.
unquote
(
string
.
replace
(
nv
[
0
],
'+'
,
' '
))
name
=
urllib
.
unquote
(
nv
[
0
].
replace
(
'+'
,
' '
))
value
=
urllib
.
unquote
(
string
.
replace
(
nv
[
1
],
'+'
,
' '
))
value
=
urllib
.
unquote
(
nv
[
1
].
replace
(
'+'
,
' '
))
r
.
append
((
name
,
value
))
r
.
append
((
name
,
value
))
return
r
return
r
...
@@ -249,8 +248,8 @@ def parse_multipart(fp, pdict):
...
@@ -249,8 +248,8 @@ def parse_multipart(fp, pdict):
clength
=
headers
.
getheader
(
'content-length'
)
clength
=
headers
.
getheader
(
'content-length'
)
if
clength
:
if
clength
:
try
:
try
:
bytes
=
string
.
atoi
(
clength
)
bytes
=
int
(
clength
)
except
string
.
atoi_e
rror
:
except
ValueE
rror
:
pass
pass
if
bytes
>
0
:
if
bytes
>
0
:
if
maxlen
and
bytes
>
maxlen
:
if
maxlen
and
bytes
>
maxlen
:
...
@@ -266,7 +265,7 @@ def parse_multipart(fp, pdict):
...
@@ -266,7 +265,7 @@ def parse_multipart(fp, pdict):
terminator
=
lastpart
# End outer loop
terminator
=
lastpart
# End outer loop
break
break
if
line
[:
2
]
==
"--"
:
if
line
[:
2
]
==
"--"
:
terminator
=
string
.
strip
(
line
)
terminator
=
line
.
strip
(
)
if
terminator
in
(
nextpart
,
lastpart
):
if
terminator
in
(
nextpart
,
lastpart
):
break
break
lines
.
append
(
line
)
lines
.
append
(
line
)
...
@@ -282,7 +281,7 @@ def parse_multipart(fp, pdict):
...
@@ -282,7 +281,7 @@ def parse_multipart(fp, pdict):
elif
line
[
-
1
:]
==
"
\
n
"
:
elif
line
[
-
1
:]
==
"
\
n
"
:
line
=
line
[:
-
1
]
line
=
line
[:
-
1
]
lines
[
-
1
]
=
line
lines
[
-
1
]
=
line
data
=
string
.
joinfields
(
lines
,
""
)
data
=
""
.
join
(
lines
)
line
=
headers
[
'content-disposition'
]
line
=
headers
[
'content-disposition'
]
if
not
line
:
if
not
line
:
continue
continue
...
@@ -307,15 +306,15 @@ def parse_header(line):
...
@@ -307,15 +306,15 @@ def parse_header(line):
Return the main content-type and a dictionary of options.
Return the main content-type and a dictionary of options.
"""
"""
plist
=
map
(
string
.
strip
,
string
.
splitfields
(
line
,
';'
))
plist
=
map
(
lambda
x
:
x
.
strip
(),
line
.
split
(
';'
))
key
=
string
.
lower
(
plist
[
0
]
)
key
=
plist
[
0
].
lower
(
)
del
plist
[
0
]
del
plist
[
0
]
pdict
=
{}
pdict
=
{}
for
p
in
plist
:
for
p
in
plist
:
i
=
string
.
find
(
p
,
'='
)
i
=
p
.
find
(
'='
)
if
i
>=
0
:
if
i
>=
0
:
name
=
string
.
lower
(
string
.
strip
(
p
[:
i
])
)
name
=
p
[:
i
].
strip
().
lower
(
)
value
=
string
.
strip
(
p
[
i
+
1
:]
)
value
=
p
[
i
+
1
:].
strip
(
)
if
len
(
value
)
>=
2
and
value
[
0
]
==
value
[
-
1
]
==
'"'
:
if
len
(
value
)
>=
2
and
value
[
0
]
==
value
[
-
1
]
==
'"'
:
value
=
value
[
1
:
-
1
]
value
=
value
[
1
:
-
1
]
pdict
[
name
]
=
value
pdict
[
name
]
=
value
...
@@ -426,7 +425,7 @@ class FieldStorage:
...
@@ -426,7 +425,7 @@ class FieldStorage:
self
.
keep_blank_values
=
keep_blank_values
self
.
keep_blank_values
=
keep_blank_values
self
.
strict_parsing
=
strict_parsing
self
.
strict_parsing
=
strict_parsing
if
environ
.
has_key
(
'REQUEST_METHOD'
):
if
environ
.
has_key
(
'REQUEST_METHOD'
):
method
=
string
.
upper
(
environ
[
'REQUEST_METHOD'
]
)
method
=
environ
[
'REQUEST_METHOD'
].
upper
(
)
if
method
==
'GET'
or
method
==
'HEAD'
:
if
method
==
'GET'
or
method
==
'HEAD'
:
if
environ
.
has_key
(
'QUERY_STRING'
):
if
environ
.
has_key
(
'QUERY_STRING'
):
qs
=
environ
[
'QUERY_STRING'
]
qs
=
environ
[
'QUERY_STRING'
]
...
@@ -490,7 +489,7 @@ class FieldStorage:
...
@@ -490,7 +489,7 @@ class FieldStorage:
clen
=
-
1
clen
=
-
1
if
self
.
headers
.
has_key
(
'content-length'
):
if
self
.
headers
.
has_key
(
'content-length'
):
try
:
try
:
clen
=
string
.
atoi
(
self
.
headers
[
'content-length'
])
clen
=
int
(
self
.
headers
[
'content-length'
])
except
:
except
:
pass
pass
if
maxlen
and
clen
>
maxlen
:
if
maxlen
and
clen
>
maxlen
:
...
@@ -647,7 +646,7 @@ class FieldStorage:
...
@@ -647,7 +646,7 @@ class FieldStorage:
self
.
done
=
-
1
self
.
done
=
-
1
break
break
if
line
[:
2
]
==
"--"
:
if
line
[:
2
]
==
"--"
:
strippedline
=
string
.
strip
(
line
)
strippedline
=
line
.
strip
(
)
if
strippedline
==
next
:
if
strippedline
==
next
:
break
break
if
strippedline
==
last
:
if
strippedline
==
last
:
...
@@ -676,7 +675,7 @@ class FieldStorage:
...
@@ -676,7 +675,7 @@ class FieldStorage:
self
.
done
=
-
1
self
.
done
=
-
1
break
break
if
line
[:
2
]
==
"--"
:
if
line
[:
2
]
==
"--"
:
strippedline
=
string
.
strip
(
line
)
strippedline
=
line
.
strip
(
)
if
strippedline
==
next
:
if
strippedline
==
next
:
break
break
if
strippedline
==
last
:
if
strippedline
==
last
:
...
@@ -771,12 +770,12 @@ class InterpFormContentDict(SvFormContentDict):
...
@@ -771,12 +770,12 @@ class InterpFormContentDict(SvFormContentDict):
"""This class is present for backwards compatibility only."""
"""This class is present for backwards compatibility only."""
def
__getitem__
(
self
,
key
):
def
__getitem__
(
self
,
key
):
v
=
SvFormContentDict
.
__getitem__
(
self
,
key
)
v
=
SvFormContentDict
.
__getitem__
(
self
,
key
)
if
v
[
0
]
in
string
.
digits
+
'
+-.'
:
if
v
[
0
]
in
'0123456789
+-.'
:
try
:
return
string
.
atoi
(
v
)
try
:
return
int
(
v
)
except
ValueError
:
except
ValueError
:
try
:
return
string
.
atof
(
v
)
try
:
return
float
(
v
)
except
ValueError
:
pass
except
ValueError
:
pass
return
string
.
strip
(
v
)
return
v
.
strip
(
)
def
values
(
self
):
def
values
(
self
):
result
=
[]
result
=
[]
for
key
in
self
.
keys
():
for
key
in
self
.
keys
():
...
@@ -812,7 +811,7 @@ class FormContent(FormContentDict):
...
@@ -812,7 +811,7 @@ class FormContent(FormContentDict):
def
length
(
self
,
key
):
def
length
(
self
,
key
):
return
len
(
self
.
dict
[
key
])
return
len
(
self
.
dict
[
key
])
def
stripped
(
self
,
key
):
def
stripped
(
self
,
key
):
if
self
.
dict
.
has_key
(
key
):
return
s
tring
.
strip
(
self
.
dict
[
key
][
0
]
)
if
self
.
dict
.
has_key
(
key
):
return
s
elf
.
dict
[
key
][
0
].
strip
(
)
else
:
return
None
else
:
return
None
def
pars
(
self
):
def
pars
(
self
):
return
self
.
dict
return
self
.
dict
...
@@ -870,7 +869,7 @@ def print_exception(type=None, value=None, tb=None, limit=None):
...
@@ -870,7 +869,7 @@ def print_exception(type=None, value=None, tb=None, limit=None):
list
=
traceback
.
format_tb
(
tb
,
limit
)
+
\
list
=
traceback
.
format_tb
(
tb
,
limit
)
+
\
traceback
.
format_exception_only
(
type
,
value
)
traceback
.
format_exception_only
(
type
,
value
)
print
"<PRE>%s<B>%s</B></PRE>"
%
(
print
"<PRE>%s<B>%s</B></PRE>"
%
(
escape
(
string
.
join
(
list
[:
-
1
],
""
)),
escape
(
""
.
join
(
list
[:
-
1
]
)),
escape
(
list
[
-
1
]),
escape
(
list
[
-
1
]),
)
)
del
tb
del
tb
...
@@ -972,11 +971,11 @@ environment as well. Here are some common variable names:
...
@@ -972,11 +971,11 @@ environment as well. Here are some common variable names:
def
escape
(
s
,
quote
=
None
):
def
escape
(
s
,
quote
=
None
):
"""Replace special characters '&', '<' and '>' by SGML entities."""
"""Replace special characters '&', '<' and '>' by SGML entities."""
s
=
s
tring
.
replace
(
s
,
"&"
,
"&"
)
# Must be done first!
s
=
s
.
replace
(
"&"
,
"&"
)
# Must be done first!
s
=
s
tring
.
replace
(
s
,
"<"
,
"<"
)
s
=
s
.
replace
(
"<"
,
"<"
)
s
=
s
tring
.
replace
(
s
,
">"
,
">"
,
)
s
=
s
.
replace
(
">"
,
">"
)
if
quote
:
if
quote
:
s
=
s
tring
.
replace
(
s
,
'"'
,
"""
)
s
=
s
.
replace
(
'"'
,
"""
)
return
s
return
s
...
...
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