blob: 4d93289f2e6dac6ad2adcbd5b9e77945871e1a09 [file] [log] [blame]
Jeremy Hylton6102e292000-08-31 15:48:10 +00001# Minimal test of the quote function
Marc-André Lemburg36619082001-01-17 19:11:13 +00002from test_support import verify, verbose
Jeremy Hylton6102e292000-08-31 15:48:10 +00003import urllib
4
5chars = 'abcdefghijklmnopqrstuvwxyz'\
6 '\337\340\341\342\343\344\345\346\347\350\351\352\353\354\355\356' \
7 '\357\360\361\362\363\364\365\366\370\371\372\373\374\375\376\377' \
8 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' \
9 '\300\301\302\303\304\305\306\307\310\311\312\313\314\315\316\317' \
10 '\320\321\322\323\324\325\326\330\331\332\333\334\335\336'
11
Tim Peterscc583632001-01-19 07:00:08 +000012expected = 'abcdefghijklmnopqrstuvwxyz' \
13 '%DF%E0%E1%E2%E3%E4%E5%E6%E7%E8%E9%EA%EB%EC%ED%EE' \
14 '%EF%F0%F1%F2%F3%F4%F5%F6%F8%F9%FA%FB%FC%FD%FE%FF' \
15 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' \
16 '%C0%C1%C2%C3%C4%C5%C6%C7%C8%C9%CA%CB%CC%CD%CE%CF' \
17 '%D0%D1%D2%D3%D4%D5%D6%D8%D9%DA%DB%DC%DD%DE'
Jeremy Hylton6102e292000-08-31 15:48:10 +000018
19test = urllib.quote(chars)
Tim Peters1a8a53d2001-01-19 06:06:37 +000020verify(test == expected, "urllib.quote problem 1")
Jeremy Hylton7ae51bf2000-09-14 16:59:07 +000021test2 = urllib.unquote(expected)
Marc-André Lemburg36619082001-01-17 19:11:13 +000022verify(test2 == chars)
Jeremy Hylton7ae51bf2000-09-14 16:59:07 +000023
24in1 = "abc/def"
25out1_1 = "abc/def"
Tim Peterscc583632001-01-19 07:00:08 +000026out1_2 = "abc%2Fdef"
Jeremy Hylton7ae51bf2000-09-14 16:59:07 +000027
Tim Peters1a8a53d2001-01-19 06:06:37 +000028verify(urllib.quote(in1) == out1_1, "urllib.quote problem 2")
29verify(urllib.quote(in1, '') == out1_2, "urllib.quote problem 3")
Jeremy Hylton7ae51bf2000-09-14 16:59:07 +000030
31in2 = "abc?def"
Tim Peterscc583632001-01-19 07:00:08 +000032out2_1 = "abc%3Fdef"
Jeremy Hylton7ae51bf2000-09-14 16:59:07 +000033out2_2 = "abc?def"
34
Tim Peters1a8a53d2001-01-19 06:06:37 +000035verify(urllib.quote(in2) == out2_1, "urllib.quote problem 4")
36verify(urllib.quote(in2, '?') == out2_2, "urllib.quote problem 5")
Skip Montanaroe78b92a2001-01-20 20:22:30 +000037
38in3 = {"p1":"v1","p2":"v2"}
39exp3_1 = "p2=v2&p1=v1"
40exp3_2 = "p1=v1&p2=v2"
41act3 = urllib.urlencode(in3)
42verify(act3==exp3_1 or act3==exp3_2, "urllib.urlencode problem 1")
43
44in4 = {"p1":["v1","v2"]}
45exp4 = "p1=v1&p1=v2"
46act4 = urllib.urlencode(in4,doseq=1)
47verify(act4==exp4, "urllib.urlencode problem 2")
48
49in5 = in4
50exp5 = "p1=%5B%27v1%27%2C+%27v2%27%5D"
51act5 = urllib.urlencode(in5)
52verify(act5==exp5, "urllib.urlencode problem 3")