File tree Expand file tree Collapse file tree 1 file changed +18
-0
lines changed Expand file tree Collapse file tree 1 file changed +18
-0
lines changed Original file line number Diff line number Diff line change @@ -257,6 +257,16 @@ def u(s):
257257 def u_safe (s ):
258258 return s
259259
260+ def to_str (s ):
261+ """
262+ Convert bytes and non-string into Python 3 str
263+ """
264+ if isinstance (s , binary_type ):
265+ s = bytes_to_str (s )
266+ elif not isinstance (s , string_types ):
267+ s = str (s )
268+ return s
269+
260270 def strlen (data , encoding = None ):
261271 # encoding is for compat with PY2
262272 return len (data )
@@ -302,6 +312,14 @@ def u_safe(s):
302312 except :
303313 return s
304314
315+ def to_str (s ):
316+ """
317+ Convert unicode and non-string into Python 2 str
318+ """
319+ if not isinstance (s , string_types ):
320+ s = str (s )
321+ return s
322+
305323 def strlen (data , encoding = None ):
306324 try :
307325 data = data .decode (encoding )
You can’t perform that action at this time.
0 commit comments