MCPcopy Index your code
hub / github.com/clips/pattern / encode_string

Function encode_string

pattern/web/__init__.py:75–86  ·  view source on GitHub ↗

Returns the given value as a Python byte string (if possible).

(v, encoding="utf-8")

Source from the content-addressed store, hash-verified

73 return unicode(v)
74
75def encode_string(v, encoding="utf-8"):
76 """ Returns the given value as a Python byte string (if possible).
77 """
78 if isinstance(encoding, basestring):
79 encoding = ((encoding,),) + (("windows-1252",), ("utf-8", "ignore"))
80 if isinstance(v, unicode):
81 for e in encoding:
82 try: return v.encode(*e)
83 except:
84 pass
85 return v
86 return str(v)
87
88u = decode_utf8 = decode_string
89s = encode_utf8 = encode_string

Callers

nothing calls this directly

Calls 2

strFunction · 0.85
encodeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…