py3: check if quote_plus returns bytes or str

On python3, there is explicit decoding already, so this would fail.
This commit is contained in:
Eli Schwartz 2019-04-10 08:33:02 -04:00
parent 57eaee584d
commit 3243aeaa04
No known key found for this signature in database
GPG Key ID: CEB167EFB5722BD6
2 changed files with 8 additions and 2 deletions

View File

@ -51,7 +51,10 @@ all_author_searches = AUTHOR_SEARCHES.__iter__
def qquote(val):
if not isinstance(val, bytes):
val = val.encode('utf-8')
return quote_plus(val).decode('utf-8')
ans = quote_plus(val)
if isinstance(ans, bytes):
ans = ans.decode('utf-8')
return ans
def url_for(template, data):

View File

@ -74,7 +74,10 @@ def query(br, url, key, dump_raw=None, limit=1, parser=parse_html, timeout=60):
def quote_term(x):
return quote_plus(x.encode('utf-8')).decode('utf-8')
ans = quote_plus(x.encode('utf-8'))
if isinstance(ans, bytes):
ans = ans.decode('utf-8')
return ans
# DDG + Wayback machine {{{