mirror of
https://github.com/python/cpython.git
synced 2025-08-17 07:11:51 +00:00
Rolled back revisions 81259,81265 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk (due to 2.6.6 release candidate freeze)
This commit is contained in:
parent
66983a09d3
commit
6980342c34
2 changed files with 25 additions and 34 deletions
|
@ -94,7 +94,7 @@ def urlretrieve(url, filename=None, reporthook=None, data=None):
|
||||||
def urlcleanup():
|
def urlcleanup():
|
||||||
if _urlopener:
|
if _urlopener:
|
||||||
_urlopener.cleanup()
|
_urlopener.cleanup()
|
||||||
_safe_quoters.clear()
|
_safemaps.clear()
|
||||||
ftpcache.clear()
|
ftpcache.clear()
|
||||||
|
|
||||||
# check for SSL
|
# check for SSL
|
||||||
|
@ -1165,24 +1165,20 @@ def splitvalue(attr):
|
||||||
return attr, None
|
return attr, None
|
||||||
|
|
||||||
_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)
|
|
||||||
|
|
||||||
def unquote(s):
|
def unquote(s):
|
||||||
"""unquote('abc%20def') -> 'abc def'."""
|
"""unquote('abc%20def') -> 'abc def'."""
|
||||||
res = s.split('%')
|
res = s.split('%')
|
||||||
# fastpath
|
for i in xrange(1, len(res)):
|
||||||
if len(res) == 1:
|
item = res[i]
|
||||||
return s
|
|
||||||
s = res[0]
|
|
||||||
for item in res[1:]:
|
|
||||||
try:
|
try:
|
||||||
s += _hextochr[item[:2]] + item[2:]
|
res[i] = _hextochr[item[:2]] + item[2:]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
s += '%' + item
|
res[i] = '%' + item
|
||||||
except UnicodeDecodeError:
|
except UnicodeDecodeError:
|
||||||
s += unichr(int(item[:2], 16)) + item[2:]
|
res[i] = unichr(int(item[:2], 16)) + item[2:]
|
||||||
return s
|
return "".join(res)
|
||||||
|
|
||||||
def unquote_plus(s):
|
def unquote_plus(s):
|
||||||
"""unquote('%7e/abc+def') -> '~/abc def'"""
|
"""unquote('%7e/abc+def') -> '~/abc def'"""
|
||||||
|
@ -1192,10 +1188,7 @@ def unquote_plus(s):
|
||||||
always_safe = ('ABCDEFGHIJKLMNOPQRSTUVWXYZ'
|
always_safe = ('ABCDEFGHIJKLMNOPQRSTUVWXYZ'
|
||||||
'abcdefghijklmnopqrstuvwxyz'
|
'abcdefghijklmnopqrstuvwxyz'
|
||||||
'0123456789' '_.-')
|
'0123456789' '_.-')
|
||||||
_safe_map = {}
|
_safemaps = {}
|
||||||
for i, c in zip(xrange(256), str(bytearray(xrange(256)))):
|
|
||||||
_safe_map[c] = c if (i < 128 and c in always_safe) else '%{0:02X}'.format(i)
|
|
||||||
_safe_quoters = {}
|
|
||||||
|
|
||||||
def quote(s, safe = '/'):
|
def quote(s, safe = '/'):
|
||||||
"""quote('abc def') -> 'abc%20def'
|
"""quote('abc def') -> 'abc%20def'
|
||||||
|
@ -1218,21 +1211,18 @@ def quote(s, safe='/'):
|
||||||
called on a path where the existing slash characters are used as
|
called on a path where the existing slash characters are used as
|
||||||
reserved characters.
|
reserved characters.
|
||||||
"""
|
"""
|
||||||
# fastpath
|
|
||||||
if not s:
|
|
||||||
return s
|
|
||||||
cachekey = (safe, always_safe)
|
cachekey = (safe, always_safe)
|
||||||
try:
|
try:
|
||||||
(quoter, safe) = _safe_quoters[cachekey]
|
safe_map = _safemaps[cachekey]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
safe_map = _safe_map.copy()
|
safe += always_safe
|
||||||
safe_map.update([(c, c) for c in safe])
|
safe_map = {}
|
||||||
quoter = safe_map.__getitem__
|
for i in range(256):
|
||||||
safe = always_safe + safe
|
c = chr(i)
|
||||||
_safe_quoters[cachekey] = (quoter, safe)
|
safe_map[c] = (c in safe) and c or ('%%%02X' % i)
|
||||||
if not s.rstrip(safe):
|
_safemaps[cachekey] = safe_map
|
||||||
return s
|
res = map(safe_map.__getitem__, s)
|
||||||
return ''.join(map(quoter, s))
|
return ''.join(res)
|
||||||
|
|
||||||
def quote_plus(s, safe = ''):
|
def quote_plus(s, safe = ''):
|
||||||
"""Quote the query fragment of a URL; replacing ' ' with '+'"""
|
"""Quote the query fragment of a URL; replacing ' ' with '+'"""
|
||||||
|
@ -1403,6 +1393,7 @@ if sys.platform == 'darwin':
|
||||||
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
def getproxies_macosx_sysconf():
|
def getproxies_macosx_sysconf():
|
||||||
"""Return a dictionary of scheme -> proxy server URL mappings.
|
"""Return a dictionary of scheme -> proxy server URL mappings.
|
||||||
|
|
||||||
|
@ -1411,6 +1402,8 @@ if sys.platform == 'darwin':
|
||||||
"""
|
"""
|
||||||
return _get_proxies()
|
return _get_proxies()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def proxy_bypass(host):
|
def proxy_bypass(host):
|
||||||
if getproxies_environment():
|
if getproxies_environment():
|
||||||
return proxy_bypass_environment(host)
|
return proxy_bypass_environment(host)
|
||||||
|
|
|
@ -12,8 +12,6 @@ What's New in Python 2.6.6?
|
||||||
Library
|
Library
|
||||||
-------
|
-------
|
||||||
|
|
||||||
- Issue #1285086: Speed up urllib.quote and urllib.unquote for simple cases.
|
|
||||||
|
|
||||||
- Issue #5798: Handle select.poll flag oddities properly on OS X.
|
- Issue #5798: Handle select.poll flag oddities properly on OS X.
|
||||||
This fixes test_asynchat and test_smtplib failures on OS X.
|
This fixes test_asynchat and test_smtplib failures on OS X.
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue