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):
257
257
def u_safe (s ):
258
258
return s
259
259
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
+
260
270
def strlen (data , encoding = None ):
261
271
# encoding is for compat with PY2
262
272
return len (data )
@@ -302,6 +312,14 @@ def u_safe(s):
302
312
except :
303
313
return s
304
314
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
+
305
323
def strlen (data , encoding = None ):
306
324
try :
307
325
data = data .decode (encoding )
You can’t perform that action at this time.
0 commit comments