MCPcopy Create free account
hub / github.com/Boris-code/feapder / encode

Method encode

feapder/db/redisdb.py:24–50  ·  view source on GitHub ↗

Return a bytestring or bytes-like representation of the value

(self, value)

Source from the content-addressed store, hash-verified

22
23class Encoder(_Encoder):
24 def encode(self, value):
25 "Return a bytestring or bytes-like representation of the value"
26 if isinstance(value, (bytes, memoryview)):
27 return value
28 # elif isinstance(value, bool):
29 # # special case bool since it is a subclass of int
30 # raise DataError(
31 # "Invalid input of type: 'bool'. Convert to a "
32 # "bytes, string, int or float first."
33 # )
34 elif isinstance(value, float):
35 value = repr(value).encode()
36 elif isinstance(value, int):
37 # python 2 repr() on longs is '123L', so use str() instead
38 value = str(value).encode()
39 elif isinstance(value, (list, dict, tuple)):
40 value = str(value)
41 elif not isinstance(value, str):
42 # a value we don't know how to deal with. throw an error
43 typename = type(value).__name__
44 raise DataError(
45 "Invalid input of type: '%s'. Convert to a "
46 "bytes, string, int or float first." % typename
47 )
48 if isinstance(value, str):
49 value = value.encode(self.encoding, self.encoding_errors)
50 return value
51
52
53redis.connection.Encoder = Encoder

Callers 13

docsify.min.jsFile · 0.80
_make_hashfuncsFunction · 0.80
get_md5Function · 0.80
get_sha1Function · 0.80
get_base64Function · 0.80
dingding_warningFunction · 0.80
wechat_warningFunction · 0.80
feishu_warningFunction · 0.80
create_root_nodeFunction · 0.80
from_textMethod · 0.80
openMethod · 0.80
downloadMethod · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected