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
e1b13d20
Commit
e1b13d20
authored
Aug 24, 2005
by
Georg Brandl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Bug #735248: Fix urllib2.parse_http_list.
parent
256372c8
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
44 additions
and
39 deletions
+44
-39
Lib/test/test_urllib2.py
Lib/test/test_urllib2.py
+8
-0
Lib/urllib2.py
Lib/urllib2.py
+36
-39
No files found.
Lib/test/test_urllib2.py
View file @
e1b13d20
...
...
@@ -45,6 +45,14 @@ class TrivialTests(unittest.TestCase):
# test the new-in-2.5 httpresponses dictionary
self
.
assertEquals
(
urllib2
.
httpresponses
[
404
],
"Not Found"
)
def
test_parse_http_list
(
self
):
tests
=
[(
'a,b,c'
,
[
'a'
,
'b'
,
'c'
]),
(
'path"o,l"og"i"cal, example'
,
[
'path"o,l"og"i"cal'
,
'example'
]),
(
'a, b, "c", "d", "e,f", g, h'
,
[
'a'
,
'b'
,
'"c"'
,
'"d"'
,
'"e,f"'
,
'g'
,
'h'
]),
(
'a="b
\
\
"c", d="e
\
\
,f", g="h
\
\
\
\
i"'
,
[
'a="b"c"'
,
'd="e,f"'
,
'g="h
\
\
i"'
])]
for
string
,
list
in
tests
:
self
.
assertEquals
(
urllib2
.
parse_http_list
(
string
),
list
)
class
MockOpener
:
addheaders
=
[]
...
...
Lib/urllib2.py
View file @
e1b13d20
...
...
@@ -1069,49 +1069,46 @@ def parse_keqv_list(l):
def
parse_http_list
(
s
):
"""Parse lists as described by RFC 2068 Section 2.
In particular, parse comma-separated lists where the elements of
the list may include quoted-strings. A quoted-string could
contain a comma.
contain a comma. A non-quoted string could have quotes in the
middle. Neither commas nor quotes count if they are escaped.
Only double-quotes count, not single-quotes.
"""
# XXX this function could probably use more testing
list
=
[]
end
=
len
(
s
)
i
=
0
inquote
=
0
start
=
0
while
i
<
end
:
cur
=
s
[
i
:]
c
=
cur
.
find
(
','
)
q
=
cur
.
find
(
'"'
)
if
c
==
-
1
:
list
.
append
(
s
[
start
:])
break
if
q
==
-
1
:
if
inquote
:
raise
ValueError
,
"unbalanced quotes"
else
:
list
.
append
(
s
[
start
:
i
+
c
])
i
=
i
+
c
+
1
res
=
[]
part
=
''
escape
=
quote
=
False
for
cur
in
s
:
if
escape
:
part
+=
cur
escape
=
False
continue
if
quote
:
if
cur
==
'
\
\
'
:
escape
=
True
continue
if
inquote
:
if
q
<
c
:
list
.
append
(
s
[
start
:
i
+
c
])
i
=
i
+
c
+
1
start
=
i
inquote
=
0
else
:
i
=
i
+
q
else
:
if
c
<
q
:
list
.
append
(
s
[
start
:
i
+
c
])
i
=
i
+
c
+
1
start
=
i
else
:
inquote
=
1
i
=
i
+
q
+
1
return
map
(
lambda
x
:
x
.
strip
(),
list
)
elif
cur
==
'"'
:
quote
=
False
part
+=
cur
continue
if
cur
==
','
:
res
.
append
(
part
)
part
=
''
continue
if
cur
==
'"'
:
quote
=
True
part
+=
cur
# append last part
if
part
:
res
.
append
(
part
)
return
[
part
.
strip
()
for
part
in
res
]
class
FileHandler
(
BaseHandler
):
# Use local file or FTP depending on form of URL
...
...
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