diff options
author | Jeremy Hylton <jeremy@alum.mit.edu> | 2009-03-26 16:56:59 (GMT) |
---|---|---|
committer | Jeremy Hylton <jeremy@alum.mit.edu> | 2009-03-26 16:56:59 (GMT) |
commit | 230feba5fd4ca3db18775d3cfa89e42284833aac (patch) | |
tree | 8fbcc8dfd27ea8de01ac2e4ff7d635e71aa6b6ef /Lib | |
parent | f819886a7203214993d756a3fcaa275e4f6803cd (diff) | |
download | cpython-230feba5fd4ca3db18775d3cfa89e42284833aac.zip cpython-230feba5fd4ca3db18775d3cfa89e42284833aac.tar.gz cpython-230feba5fd4ca3db18775d3cfa89e42284833aac.tar.bz2 |
urlencode:
Remove dead code branch created by automated conversion from 2.x.
Clean up a few comments.
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/urllib/parse.py | 18 |
1 files changed, 5 insertions, 13 deletions
diff --git a/Lib/urllib/parse.py b/Lib/urllib/parse.py index 044c810..5fd038e 100644 --- a/Lib/urllib/parse.py +++ b/Lib/urllib/parse.py @@ -521,18 +521,17 @@ def urlencode(query, doseq=0): """ if hasattr(query, "items"): - # mapping objects query = query.items() else: - # it's a bother at times that strings and string-like objects are - # sequences... + # It's a bother at times that strings and string-like objects are + # sequences. try: # non-sequence items should not work with len() # non-empty strings will fail this if len(query) and not isinstance(query[0], tuple): raise TypeError - # zero-length sequences of all types will get here and succeed, - # but that's a minor nit - since the original implementation + # Zero-length sequences of all types will get here and succeed, + # but that's a minor nit. Since the original implementation # allowed empty dicts that type of behavior probably should be # preserved for consistency except TypeError: @@ -542,7 +541,6 @@ def urlencode(query, doseq=0): l = [] if not doseq: - # preserve old behavior for k, v in query: k = quote_plus(str(k)) v = quote_plus(str(v)) @@ -553,15 +551,9 @@ def urlencode(query, doseq=0): if isinstance(v, str): v = quote_plus(v) l.append(k + '=' + v) - elif isinstance(v, str): - # is there a reasonable way to convert to ASCII? - # encode generates a string, but "replace" or "ignore" - # lose information and "strict" can raise UnicodeError - v = quote_plus(v.encode("ASCII", "replace")) - l.append(k + '=' + v) else: try: - # is this a sufficient test for sequence-ness? + # Is this a sufficient test for sequence-ness? x = len(v) except TypeError: # not a sequence |