Product
Introducing SSO
Streamline your login process and enhance security by enabling Single Sign-On (SSO) on the Socket platform, now available for all customers on the Enterprise plan, supporting 20+ identity providers.
Readme
Python 3 bytearray bencoding library.
Encode all data into byte
. Useful for networking.
>>> from bencode import bencode, bdecode
>>> foo = bencode({"foo": [0, -1, 2, "3", {"4": 5}], "bar": {"baz": 1}})
>>> print(foo)
b'd3:bard3:bazi1ee3:fooli0ei-1ei2e1:3d1:4i5eeee'
>>> bar = bdecode(foo)
>>> print(bar)
{b'bar': {b'baz': 1}, b'foo': [0, -1, 2, b'3', {b'4': 5}]}
decoder
for bdecode
Optional argument in bdecode
function, provide decode bytes to another types. It can be helpful for decode dict key into strings.
decoder
is a callback function with arguments: field_type
, value
field_type
str, possible values: "key"
, "value"
;value
bytes.>>> def custom_decoder(field_type, value):
... if field_type == "key":
... return str(value, "ascii")
... elif field_type == "value":
... return str(value, "utf-8")
... else:
... raise Exception("'field_type' can pass only 'key' and 'value' values")
...
>>> bar = bdecode(foo, decoder=custom_decoder)
>>> print(bar)
{'bar': {'baz': 1}, 'foo': [0, -1, 2, '3', {'4': 5}]}
FAQs
Python 3 bencoding implementation
We found that py3-bencode demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Streamline your login process and enhance security by enabling Single Sign-On (SSO) on the Socket platform, now available for all customers on the Enterprise plan, supporting 20+ identity providers.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.