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

Function encode_string

pattern/web/cache/__init__.py:27–38  ·  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

25 return unicode(v)
26
27def encode_string(v, encoding="utf-8"):
28 """ Returns the given value as a Python byte string (if possible).
29 """
30 if isinstance(encoding, basestring):
31 encoding = ((encoding,),) + (("windows-1252",), ("utf-8", "ignore"))
32 if isinstance(v, unicode):
33 for e in encoding:
34 try: return v.encode(*e)
35 except:
36 pass
37 return v
38 return str(v)
39
40decode_utf8 = decode_string
41encode_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…