MCPcopy Create free account
hub / github.com/webpy/webpy / safestr

Function safestr

web/utils.py:354–367  ·  view source on GitHub ↗

r""" Converts any given object to utf-8 encoded string. >>> safestr('hello') 'hello' >>> safestr(2) '2'

(obj, encoding="utf-8")

Source from the content-addressed store, hash-verified

352
353
354def safestr(obj, encoding="utf-8"):
355 r"""
356 Converts any given object to utf-8 encoded string.
357
358 >>> safestr('hello')
359 'hello'
360 >>> safestr(2)
361 '2'
362 """
363
364 if obj and hasattr(obj, "__next__"):
365 return [safestr(i) for i in obj]
366 else:
367 return str(obj)
368
369
370# Since Python3, utf-8 encoded strings and unicode strings are the same thing

Callers 8

queryMethod · 0.85
__str__Method · 0.85
listifyMethod · 0.85
__init__Method · 0.85
headerFunction · 0.85
setcookieFunction · 0.85
emailerrors_internalFunction · 0.85
generate_codeMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected