Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
d9827c47
Kaydet (Commit)
d9827c47
authored
Agu 03, 2000
tarafından
Jeremy Hylton
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
test the non-multipart sections of the cgi module
üst
ed13b4a5
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
196 additions
and
0 deletions
+196
-0
test_cgi
Lib/test/output/test_cgi
+24
-0
test_cgi.py
Lib/test/test_cgi.py
+172
-0
No files found.
Lib/test/output/test_cgi
0 → 100644
Dosyayı görüntüle @
d9827c47
test_cgi
''
'&'
'&&'
'='
'=&='
'=a'
'&=a'
'=a&'
'=&a'
'b=a'
'b+=a'
'a=b=a'
'a=+b=a'
'&b=a'
'b&=a'
'a=a+b&b=b+c'
'a=a+b&a=b+a'
'x=1&y=2.0&z=2-3.%2b0'
'Hbc5161168c542333633315dee1182227:key_store_seqid=400006&cuyer=r&view=bustomer&order_id=0bb2e248638833d48cb7fed300000f1b&expire=964546263&lobale=en-US&kid=130003.300038&ss=env'
'group_id=5470&set=custom&_assigned_to=31392&_status=1&_category=100&SUBMIT=Browse'
Testing log
Testing initlog 1
Testing log 2
Lib/test/test_cgi.py
0 → 100644
Dosyayı görüntüle @
d9827c47
import
cgi
import
os
import
sys
class
HackedSysModule
:
# The regression test will have real values in sys.argv, which
# will completely confuse the test of the cgi module
argv
=
[]
stdin
=
sys
.
stdin
cgi
.
sys
=
HackedSysModule
()
try
:
from
cStringIO
import
StringIO
except
ImportError
:
from
StringIO
import
StringIO
class
ComparableException
:
def
__init__
(
self
,
err
):
self
.
err
=
err
def
__str__
(
self
):
return
str
(
self
.
err
)
def
__cmp__
(
self
,
anExc
):
if
not
isinstance
(
anExc
,
Exception
):
return
-
1
x
=
cmp
(
self
.
err
.
__class__
,
anExc
.
__class__
)
if
x
!=
0
:
return
x
return
cmp
(
self
.
err
.
args
,
anExc
.
args
)
def
__getattr__
(
self
,
attr
):
return
getattr
(
self
,
self
.
err
)
def
do_test
(
buf
,
method
):
env
=
{}
if
method
==
"GET"
:
fp
=
None
env
[
'REQUEST_METHOD'
]
=
'GET'
env
[
'QUERY_STRING'
]
=
buf
elif
method
==
"POST"
:
fp
=
StringIO
(
buf
)
env
[
'REQUEST_METHOD'
]
=
'POST'
env
[
'CONTENT_TYPE'
]
=
'application/x-www-form-urlencoded'
env
[
'CONTENT_LENGTH'
]
=
str
(
len
(
buf
))
else
:
raise
ValueError
,
"unknown method:
%
s"
%
method
try
:
return
cgi
.
parse
(
fp
,
env
,
strict_parsing
=
1
)
except
StandardError
,
err
:
return
ComparableException
(
err
)
# A list of test cases. Each test case is a a two-tuple that contains
# a string with the query and a dictionary with the expected result.
parse_test_cases
=
[
(
""
,
ValueError
(
"bad query field: ''"
)),
(
"&"
,
ValueError
(
"bad query field: ''"
)),
(
"&&"
,
ValueError
(
"bad query field: ''"
)),
# Should the next few really be valid?
(
"="
,
{}),
(
"=&="
,
{}),
# This rest seem to make sense
(
"=a"
,
{
''
:
[
'a'
]}),
(
"&=a"
,
ValueError
(
"bad query field: ''"
)),
(
"=a&"
,
ValueError
(
"bad query field: ''"
)),
(
"=&a"
,
ValueError
(
"bad query field: 'a'"
)),
(
"b=a"
,
{
'b'
:
[
'a'
]}),
(
"b+=a"
,
{
'b '
:
[
'a'
]}),
(
"a=b=a"
,
{
'a'
:
[
'b=a'
]}),
(
"a=+b=a"
,
{
'a'
:
[
' b=a'
]}),
(
"&b=a"
,
ValueError
(
"bad query field: ''"
)),
(
"b&=a"
,
ValueError
(
"bad query field: 'b'"
)),
(
"a=a+b&b=b+c"
,
{
'a'
:
[
'a b'
],
'b'
:
[
'b c'
]}),
(
"a=a+b&a=b+a"
,
{
'a'
:
[
'a b'
,
'b a'
]}),
(
"x=1&y=2.0&z=2-3.
%2
b0"
,
{
'x'
:
[
'1'
],
'y'
:
[
'2.0'
],
'z'
:
[
'2-3.+0'
]}),
(
"Hbc5161168c542333633315dee1182227:key_store_seqid=400006&cuyer=r&view=bustomer&order_id=0bb2e248638833d48cb7fed300000f1b&expire=964546263&lobale=en-US&kid=130003.300038&ss=env"
,
{
'Hbc5161168c542333633315dee1182227:key_store_seqid'
:
[
'400006'
],
'cuyer'
:
[
'r'
],
'expire'
:
[
'964546263'
],
'kid'
:
[
'130003.300038'
],
'lobale'
:
[
'en-US'
],
'order_id'
:
[
'0bb2e248638833d48cb7fed300000f1b'
],
'ss'
:
[
'env'
],
'view'
:
[
'bustomer'
],
}),
(
"group_id=5470&set=custom&_assigned_to=31392&_status=1&_category=100&SUBMIT=Browse"
,
{
'SUBMIT'
:
[
'Browse'
],
'_assigned_to'
:
[
'31392'
],
'_category'
:
[
'100'
],
'_status'
:
[
'1'
],
'group_id'
:
[
'5470'
],
'set'
:
[
'custom'
],
})
]
def
norm
(
list
):
if
type
(
list
)
==
type
([]):
list
.
sort
()
return
list
def
first_elts
(
list
):
return
map
(
lambda
x
:
x
[
0
],
list
)
def
first_second_elts
(
list
):
return
map
(
lambda
p
:(
p
[
0
],
p
[
1
][
0
]),
list
)
def
main
():
for
orig
,
expect
in
parse_test_cases
:
# Test basic parsing
print
repr
(
orig
)
d
=
do_test
(
orig
,
"GET"
)
assert
d
==
expect
,
"Error parsing
%
s"
%
repr
(
orig
)
d
=
do_test
(
orig
,
"POST"
)
assert
d
==
expect
,
"Error parsing
%
s"
%
repr
(
orig
)
d
=
{
'QUERY_STRING'
:
orig
}
fcd
=
cgi
.
FormContentDict
(
d
)
sd
=
cgi
.
SvFormContentDict
(
d
)
if
type
(
expect
)
==
type
({}):
# test dict interface
assert
len
(
expect
)
==
len
(
fcd
)
assert
norm
(
expect
.
keys
())
==
norm
(
fcd
.
keys
())
assert
norm
(
expect
.
values
())
==
norm
(
fcd
.
values
())
assert
norm
(
expect
.
items
())
==
norm
(
fcd
.
items
())
for
key
in
expect
.
keys
():
expect_val
=
expect
[
key
]
assert
fcd
.
has_key
(
key
)
assert
norm
(
fcd
[
key
])
==
norm
(
expect
[
key
])
if
len
(
expect_val
)
>
1
:
single_value
=
0
else
:
single_value
=
1
try
:
val
=
sd
[
key
]
except
IndexError
:
assert
not
single_value
else
:
assert
single_value
assert
val
==
expect_val
[
0
]
assert
norm
(
sd
.
getlist
(
key
))
==
norm
(
expect_val
)
if
single_value
:
assert
norm
(
sd
.
values
())
==
\
first_elts
(
norm
(
expect
.
values
()))
assert
norm
(
sd
.
items
())
==
\
first_second_elts
(
norm
(
expect
.
items
()))
# Test the weird FormContentDict classes
env
=
{
'QUERY_STRING'
:
"x=1&y=2.0&z=2-3.
%2
b0&1=1abc"
}
expect
=
{
'x'
:
1
,
'y'
:
2.0
,
'z'
:
'2-3.+0'
,
'1'
:
'1abc'
}
d
=
cgi
.
InterpFormContentDict
(
env
)
for
k
,
v
in
expect
.
items
():
assert
d
[
k
]
==
v
for
k
,
v
in
d
.
items
():
assert
expect
[
k
]
==
v
assert
norm
(
expect
.
values
())
==
norm
(
d
.
values
())
print
"Testing log"
cgi
.
initlog
()
cgi
.
log
(
"Testing"
)
cgi
.
logfp
=
sys
.
stdout
cgi
.
initlog
(
"
%
s"
,
"Testing initlog 1"
)
cgi
.
log
(
"
%
s"
,
"Testing log 2"
)
if
os
.
path
.
exists
(
"/dev/null"
):
cgi
.
logfp
=
None
cgi
.
logfile
=
"/dev/null"
cgi
.
initlog
(
"
%
s"
,
"Testing log 3"
)
cgi
.
log
(
"Testing log 4"
)
main
()
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