[Python-checkins] r81271 - in python/branches/py3k: Lib/urllib/parse.py Misc/NEWS (original) (raw)

florent.xicluna python-checkins at python.org
Mon May 17 19:33:07 CEST 2010


Author: florent.xicluna Date: Mon May 17 19:33:07 2010 New Revision: 81271

Log: Issue #1285086: Speed up urllib.parse functions: quote, quote_from_bytes, unquote, unquote_to_bytes.

Recorded merge of revisions 81265 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk

........ r81265 | florent.xicluna | 2010-05-17 15:35:09 +0200 (lun, 17 mai 2010) | 2 lines

Issue #1285086: Speed up urllib.quote and urllib.unquote for simple cases. ........

Modified: python/branches/py3k/ (props changed) python/branches/py3k/Lib/urllib/parse.py python/branches/py3k/Misc/NEWS

Modified: python/branches/py3k/Lib/urllib/parse.py

--- python/branches/py3k/Lib/urllib/parse.py (original) +++ python/branches/py3k/Lib/urllib/parse.py Mon May 17 19:33:07 2010 @@ -41,7 +41,7 @@ uses_netloc = ['ftp', 'http', 'gopher', 'nntp', 'telnet', 'imap', 'wais', 'file', 'mms', 'https', 'shttp', 'snews', 'prospero', 'rtsp', 'rtspu', 'rsync', '',

non_hierarchical = ['gopher', 'hdl', 'mailto', 'news', 'telnet', 'wais', 'imap', 'snews', 'sip', 'sips'] uses_params = ['ftp', 'hdl', 'prospero', 'http', 'imap', @@ -307,17 +307,20 @@ """unquote_to_bytes('abc%20def') -> b'abc def'.""" # Note: strings are encoded as UTF-8. This is only an issue if it contains # unescaped non-ASCII characters, which URIs should not.

def unquote(string, encoding='utf-8', errors='replace'): """Replace %xx escapes by their single-character equivalent. The optional @@ -329,36 +332,39 @@

 unquote('abc%20def') -> 'abc def'.
 """

def parse_qs(qs, keep_blank_values=False, strict_parsing=False): """Parse a query given as a string argument. @@ -439,7 +445,8 @@ b'abcdefghijklmnopqrstuvwxyz' b'0123456789' b'_.-') -_safe_quoters= {} +_ALWAYS_SAFE_BYTES = bytes(_ALWAYS_SAFE) +_safe_quoters = {}

class Quoter(collections.defaultdict): """A mapping from bytes (in range(0,256)) to strings. @@ -451,7 +458,7 @@ # of cached keys don't call Python code at all). def init(self, safe): """safe: bytes object."""

@@ -459,7 +466,7 @@

 def __missing__(self, b):
     # Handle a cache miss. Store quoted string in cache and return.

@@ -493,6 +500,8 @@ errors='strict' (unsupported characters raise a UnicodeEncodeError). """ if isinstance(string, str):

@@ -527,18 +536,22 @@ not perform string-to-bytes encoding. It always returns an ASCII string. quote_from_bytes(b'abc def\xab') -> 'abc%20def%AB' """

def urlencode(query, doseq=False): """Encode a sequence of two-element tuples or dictionary into a URL query string.

Modified: python/branches/py3k/Misc/NEWS

--- python/branches/py3k/Misc/NEWS (original) +++ python/branches/py3k/Misc/NEWS Mon May 17 19:33:07 2010 @@ -366,6 +366,9 @@ Library

+- Issue #1285086: Speed up urllib.parse functions: quote, quote_from_bytes,



More information about the Python-checkins mailing list