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
923baea9
Commit
923baea9
authored
Mar 14, 2013
by
Serhiy Storchaka
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #1285086: Get rid of the refcounting hack and speed up urllib.unquote().
parent
2556c838
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
58 additions
and
18 deletions
+58
-18
Lib/urllib.py
Lib/urllib.py
+23
-9
Lib/urlparse.py
Lib/urlparse.py
+33
-9
Misc/NEWS
Misc/NEWS
+2
-0
No files found.
Lib/urllib.py
View file @
923baea9
...
@@ -28,6 +28,7 @@ import os
...
@@ -28,6 +28,7 @@ import os
import
time
import
time
import
sys
import
sys
import
base64
import
base64
import
re
from
urlparse
import
urljoin
as
basejoin
from
urlparse
import
urljoin
as
basejoin
...
@@ -1198,22 +1199,35 @@ def splitvalue(attr):
...
@@ -1198,22 +1199,35 @@ def splitvalue(attr):
_hexdig
=
'0123456789ABCDEFabcdef'
_hexdig
=
'0123456789ABCDEFabcdef'
_hextochr
=
dict
((
a
+
b
,
chr
(
int
(
a
+
b
,
16
)))
_hextochr
=
dict
((
a
+
b
,
chr
(
int
(
a
+
b
,
16
)))
for
a
in
_hexdig
for
b
in
_hexdig
)
for
a
in
_hexdig
for
b
in
_hexdig
)
_asciire
=
re
.
compile
(
'([
\
x00
-
\
x7f
]+)'
)
def
unquote
(
s
):
def
unquote
(
s
):
"""unquote('abc%20def') -> 'abc def'."""
"""unquote('abc%20def') -> 'abc def'."""
res
=
s
.
split
(
'%'
)
if
_is_unicode
(
s
):
if
'%'
not
in
s
:
return
s
bits
=
_asciire
.
split
(
s
)
res
=
[
bits
[
0
]]
append
=
res
.
append
for
i
in
range
(
1
,
len
(
bits
),
2
):
append
(
unquote
(
str
(
bits
[
i
])).
decode
(
'latin1'
))
append
(
bits
[
i
+
1
])
return
''
.
join
(
res
)
bits
=
s
.
split
(
'%'
)
# fastpath
# fastpath
if
len
(
re
s
)
==
1
:
if
len
(
bit
s
)
==
1
:
return
s
return
s
s
=
res
[
0
]
res
=
[
bits
[
0
]]
for
item
in
res
[
1
:]:
append
=
res
.
append
for
item
in
bits
[
1
:]:
try
:
try
:
s
+=
_hextochr
[
item
[:
2
]]
+
item
[
2
:]
append
(
_hextochr
[
item
[:
2
]])
append
(
item
[
2
:])
except
KeyError
:
except
KeyError
:
s
+=
'%'
+
item
append
(
'%'
)
except
UnicodeDecodeError
:
append
(
item
)
s
+=
unichr
(
int
(
item
[:
2
],
16
))
+
item
[
2
:]
return
''
.
join
(
res
)
return
s
def
unquote_plus
(
s
):
def
unquote_plus
(
s
):
"""unquote('%7e/abc+def') -> '~/abc def'"""
"""unquote('%7e/abc+def') -> '~/abc def'"""
...
...
Lib/urlparse.py
View file @
923baea9
...
@@ -28,6 +28,8 @@ test_urlparse.py provides a good indicator of parsing behavior.
...
@@ -28,6 +28,8 @@ test_urlparse.py provides a good indicator of parsing behavior.
"""
"""
import
re
__all__
=
[
"urlparse"
,
"urlunparse"
,
"urljoin"
,
"urldefrag"
,
__all__
=
[
"urlparse"
,
"urlunparse"
,
"urljoin"
,
"urldefrag"
,
"urlsplit"
,
"urlunsplit"
,
"parse_qs"
,
"parse_qsl"
]
"urlsplit"
,
"urlunsplit"
,
"parse_qs"
,
"parse_qsl"
]
...
@@ -311,6 +313,15 @@ def urldefrag(url):
...
@@ -311,6 +313,15 @@ def urldefrag(url):
else
:
else
:
return
url
,
''
return
url
,
''
try
:
unicode
except
NameError
:
def
_is_unicode
(
x
):
return
0
else
:
def
_is_unicode
(
x
):
return
isinstance
(
x
,
unicode
)
# unquote method for parse_qs and parse_qsl
# unquote method for parse_qs and parse_qsl
# Cannot use directly from urllib as it would create a circular reference
# Cannot use directly from urllib as it would create a circular reference
# because urllib uses urlparse methods (urljoin). If you update this function,
# because urllib uses urlparse methods (urljoin). If you update this function,
...
@@ -319,22 +330,35 @@ def urldefrag(url):
...
@@ -319,22 +330,35 @@ def urldefrag(url):
_hexdig
=
'0123456789ABCDEFabcdef'
_hexdig
=
'0123456789ABCDEFabcdef'
_hextochr
=
dict
((
a
+
b
,
chr
(
int
(
a
+
b
,
16
)))
_hextochr
=
dict
((
a
+
b
,
chr
(
int
(
a
+
b
,
16
)))
for
a
in
_hexdig
for
b
in
_hexdig
)
for
a
in
_hexdig
for
b
in
_hexdig
)
_asciire
=
re
.
compile
(
'([
\
x00
-
\
x7f
]+)'
)
def
unquote
(
s
):
def
unquote
(
s
):
"""unquote('abc%20def') -> 'abc def'."""
"""unquote('abc%20def') -> 'abc def'."""
res
=
s
.
split
(
'%'
)
if
_is_unicode
(
s
):
if
'%'
not
in
s
:
return
s
bits
=
_asciire
.
split
(
s
)
res
=
[
bits
[
0
]]
append
=
res
.
append
for
i
in
range
(
1
,
len
(
bits
),
2
):
append
(
unquote
(
str
(
bits
[
i
])).
decode
(
'latin1'
))
append
(
bits
[
i
+
1
])
return
''
.
join
(
res
)
bits
=
s
.
split
(
'%'
)
# fastpath
# fastpath
if
len
(
re
s
)
==
1
:
if
len
(
bit
s
)
==
1
:
return
s
return
s
s
=
res
[
0
]
res
=
[
bits
[
0
]]
for
item
in
res
[
1
:]:
append
=
res
.
append
for
item
in
bits
[
1
:]:
try
:
try
:
s
+=
_hextochr
[
item
[:
2
]]
+
item
[
2
:]
append
(
_hextochr
[
item
[:
2
]])
append
(
item
[
2
:])
except
KeyError
:
except
KeyError
:
s
+=
'%'
+
item
append
(
'%'
)
except
UnicodeDecodeError
:
append
(
item
)
s
+=
unichr
(
int
(
item
[:
2
],
16
))
+
item
[
2
:]
return
''
.
join
(
res
)
return
s
def
parse_qs
(
qs
,
keep_blank_values
=
0
,
strict_parsing
=
0
):
def
parse_qs
(
qs
,
keep_blank_values
=
0
,
strict_parsing
=
0
):
"""Parse a query given as a string argument.
"""Parse a query given as a string argument.
...
...
Misc/NEWS
View file @
923baea9
...
@@ -214,6 +214,8 @@ Core and Builtins
...
@@ -214,6 +214,8 @@ Core and Builtins
Library
Library
-------
-------
- Issue #1285086: Get rid of the refcounting hack and speed up urllib.unquote().
- Issue #17368: Fix an off-by-one error in the Python JSON decoder that caused
- Issue #17368: Fix an off-by-one error in the Python JSON decoder that caused
a failure while decoding empty object literals when object_pairs_hook was
a failure while decoding empty object literals when object_pairs_hook was
specified.
specified.
...
...
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