Make s2b/b2s fail silently if the type is wrong.
These functions throw TypeError exceptions if the parameters are already encoded/decoded. This can be avoided by type checking before attempting to encode/decode the parameters.
This commit is contained in:
parent
b8669546e0
commit
602b55c60a
|
|
@ -26,8 +26,8 @@ if sys.hexversion > 0x3000000:
|
||||||
from io import StringIO
|
from io import StringIO
|
||||||
from http.server import SimpleHTTPRequestHandler
|
from http.server import SimpleHTTPRequestHandler
|
||||||
from urllib.parse import urlsplit
|
from urllib.parse import urlsplit
|
||||||
b2s = lambda buf: buf.decode('latin_1')
|
b2s = lambda buf: buf.decode('latin_1') if isinstance(buf, bytes) else buf
|
||||||
s2b = lambda s: s.encode('latin_1')
|
s2b = lambda s: s.encode('latin_1') if isinstance(s, str) else s
|
||||||
else:
|
else:
|
||||||
# python 2.X
|
# python 2.X
|
||||||
from cStringIO import StringIO
|
from cStringIO import StringIO
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue