Debian Codegraph @

test/test_rfc3986.doctest

raw
1 >>> from mechanize._rfc3986 import urlsplit, urljoin, remove_dot_segments
2
3 Some common cases
4
5 >>> urlsplit("http://example.com/spam/eggs/spam.html?apples=pears&a=b#foo")
6 ('http', 'example.com', '/spam/eggs/spam.html', 'apples=pears&a=b', 'foo')
7 >>> urlsplit("http://example.com/spam.html#foo")
8 ('http', 'example.com', '/spam.html', None, 'foo')
9 >>> urlsplit("ftp://example.com/foo.gif")
10 ('ftp', 'example.com', '/foo.gif', None, None)
11 >>> urlsplit('ftp://joe:[email protected]:port')
12 ('ftp', 'joe:[email protected]:port', '', None, None)
13 >>> urlsplit("mailto:[email protected]")
14 ('mailto', None, '[email protected]', None, None)
15
16 The five path productions
17
18 path-abempty:
19
20 >>> urlsplit("http://www.example.com")
21 ('http', 'www.example.com', '', None, None)
22 >>> urlsplit("http://www.example.com/foo")
23 ('http', 'www.example.com', '/foo', None, None)
24
25 path-absolute:
26
27 >>> urlsplit("a:/")
28 ('a', None, '/', None, None)
29 >>> urlsplit("a:/b:/c/")
30 ('a', None, '/b:/c/', None, None)
31
32 path-noscheme:
33
34 >>> urlsplit("a:b/:c/")
35 ('a', None, 'b/:c/', None, None)
36
37 path-rootless:
38
39 >>> urlsplit("a:b:/c/")
40 ('a', None, 'b:/c/', None, None)
41
42 path-empty:
43
44 >>> urlsplit("quack:")
45 ('quack', None, '', None, None)
46
47
48 >>> remove_dot_segments("/a/b/c/./../../g")
49 '/a/g'
50 >>> remove_dot_segments("mid/content=5/../6")
51 'mid/6'
52 >>> remove_dot_segments("/b/c/.")
53 '/b/c/'
54 >>> remove_dot_segments("/b/c/./.")
55 '/b/c/'
56 >>> remove_dot_segments(".")
57 ''
58 >>> remove_dot_segments("/.")
59 '/'
60 >>> remove_dot_segments("./")
61 ''
62 >>> remove_dot_segments("/..")
63 '/'
64 >>> remove_dot_segments("/../")
65 '/'
66
67
68 Examples from RFC 3986 section 5.4
69
70 Normal Examples
71
72 >>> base = "http://a/b/c/d;p?q"
73 >>> def join(uri): return urljoin(base, uri)
74 >>> join("g:h")
75 'g:h'
76 >>> join("g")
77 'http://a/b/c/g'
78 >>> join("./g")
79 'http://a/b/c/g'
80 >>> join("g/")
81 'http://a/b/c/g/'
82 >>> join("/g")
83 'http://a/g'
84 >>> join("//g")
85 'http://g'
86 >>> join("?y")
87 'http://a/b/c/d;p?y'
88 >>> join("g?y")
89 'http://a/b/c/g?y'
90 >>> join("#s")
91 'http://a/b/c/d;p?q#s'
92 >>> join("g#s")
93 'http://a/b/c/g#s'
94 >>> join("g?y#s")
95 'http://a/b/c/g?y#s'
96 >>> join(";x")
97 'http://a/b/c/;x'
98 >>> join("g;x")
99 'http://a/b/c/g;x'
100 >>> join("g;x?y#s")
101 'http://a/b/c/g;x?y#s'
102 >>> join("")
103 'http://a/b/c/d;p?q'
104 >>> join(".")
105 'http://a/b/c/'
106 >>> join("./")
107 'http://a/b/c/'
108 >>> join("..")
109 'http://a/b/'
110 >>> join("../")
111 'http://a/b/'
112 >>> join("../g")
113 'http://a/b/g'
114 >>> join("../..")
115 'http://a/'
116 >>> join("../../")
117 'http://a/'
118 >>> join("../../g")
119 'http://a/g'
120
121 Abnormal Examples
122
123 >>> join("../../../g")
124 'http://a/g'
125 >>> join("../../../../g")
126 'http://a/g'
127 >>> join("/./g")
128 'http://a/g'
129 >>> join("/../g")
130 'http://a/g'
131 >>> join("g.")
132 'http://a/b/c/g.'
133 >>> join(".g")
134 'http://a/b/c/.g'
135 >>> join("g..")
136 'http://a/b/c/g..'
137 >>> join("..g")
138 'http://a/b/c/..g'
139 >>> join("./../g")
140 'http://a/b/g'
141 >>> join("./g/.")
142 'http://a/b/c/g/'
143 >>> join("g/./h")
144 'http://a/b/c/g/h'
145 >>> join("g/../h")
146 'http://a/b/c/h'
147 >>> join("g;x=1/./y")
148 'http://a/b/c/g;x=1/y'
149 >>> join("g;x=1/../y")
150 'http://a/b/c/y'
151 >>> join("g?y/./x")
152 'http://a/b/c/g?y/./x'
153 >>> join("g?y/../x")
154 'http://a/b/c/g?y/../x'
155 >>> join("g#s/./x")
156 'http://a/b/c/g#s/./x'
157 >>> join("g#s/../x")
158 'http://a/b/c/g#s/../x'
159 >>> join("http:g")
160 'http://a/b/c/g'
161
162
163 Additional urljoin tests, not taken from RFC:
164
165 >>> join("/..")
166 'http://a/'
167 >>> join("/../")
168 'http://a/'