Skip to content

Commit

Permalink
unicode -> str
Browse files Browse the repository at this point in the history
  • Loading branch information
ifduyue committed Aug 4, 2023
1 parent bad665e commit f0dc3a6
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions urlfetch.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import http.cookies as Cookie

basestring = (str, bytes)
unicode = str
b = lambda s: s.encode("latin-1")
u = lambda s: s

Expand Down Expand Up @@ -320,7 +319,7 @@ def content(self):

@cached_property
def text(self):
"""Response body in unicode."""
"""Response body in str."""
return mb_code(self.content)

@cached_property
Expand Down Expand Up @@ -858,7 +857,7 @@ def parse_url(url):
password, host, port and http_host
"""
try:
url = unicode(url)
url = str(url)
except UnicodeDecodeError:
pass

Expand Down Expand Up @@ -907,15 +906,16 @@ def get_proxies_from_environ():

def mb_code(s, coding=None, errors="replace"):
"""encoding/decoding helper."""
if isinstance(s, unicode):
if isinstance(s, str):
return s if coding is None else s.encode(coding, errors=errors)
for c in ("utf-8", "gb2312", "gbk", "gb18030", "big5"):
try:
s = s.decode(c)
return s if coding is None else s.encode(coding, errors=errors)
except:
pass
return unicode(s, errors=errors)

return str(s, errors=errors)


def random_useragent(filename=True):
Expand Down

0 comments on commit f0dc3a6

Please sign in to comment.