Serialize Arguments as Bytes!
Project description
Bytes Argument Serializer
BAS Object
from byarse import BAS
bas = BAS(
safe=True, # Enable/disable safe mode. Safe mode prevents Pickle objects from being deserialized! (enabled by default)
)
Serialize
serialized = bas.s([
'Hello, world!', # string
b'Hello, world!', # bytes
42, # int
2.5, # float
datetime.datetime.utcnow(), # datetime
]) # b'...'
Deserialize
data = bas.u(
serialized
)
Pickle
You can have anything Pickleable be pickled and unpickled automatically by Byarse.
Pickle can be potentially dangerous, so try not to avoid it, or sign and verify all serializations with something like HMAC!
Safe mode must be set to False
for pickled objects to be deserialized.
class Test:
a = 1
serialized bas.s([
Pickle(Test)
]) # b'...'
self.safe = False
bas.u(serialized) # <class 'Test'>
self.safe = True
bas.u(serialized) # raises TypeError
Example Program
import os, datetime
from byarse import Pickle
from byarse import BAS
bas = BAS(safe=True) # Serializer/Deserializer
class Test: # Test class (for pickling)
randomdata = os.urandom(16)
i = input("Read or write? (r/w)\n")
if i.lower().startswith('w'): # 'w'
# ----
# Serialize
# ----
with open('test', 'wb') as f:
f.write(bas.s([
'Hello, world!',
b'Hello, world!',
42,
2.5,
datetime.datetime.utcnow(),
# Pickle(Test) # Will raise TypeError when read if safe mode is enabled.
]))
else: # 'r'
# ----
# Deserialize
# ----
with open('test', 'rb') as f:
ua = bas.u(f.read()) # Unserialize
for i in ua:
print(type(i).__name__, ':', i) # Output: "type : argument" (ex. str : Hello, world!)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
byarse-1.2.0.tar.gz
(3.3 kB
view details)
Built Distribution
File details
Details for the file byarse-1.2.0.tar.gz
.
File metadata
- Download URL: byarse-1.2.0.tar.gz
- Upload date:
- Size: 3.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.3.1 requests-toolbelt/0.8.0 tqdm/4.46.1 CPython/3.8.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d7bdfb325d20428d06089e5c7bad238c451f26a46c7d74d053a0f1b7d75fafbb |
|
MD5 | b26a8300936aea3215b03d71ae4f08a6 |
|
BLAKE2b-256 | 5beff402c75b11ba9a24beb695cb63e618bf26ac8c4974e05ec5cce802010b8f |
File details
Details for the file byarse-1.2.0-py3-none-any.whl
.
File metadata
- Download URL: byarse-1.2.0-py3-none-any.whl
- Upload date:
- Size: 3.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.3.1 requests-toolbelt/0.8.0 tqdm/4.46.1 CPython/3.8.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e48f6c147ec13b19b8dc7ba4f1ed9323b3990c4fee8559c22bdf8e16c2b29fae |
|
MD5 | 0b37e1a1a87aaac0708841d7868beca1 |
|
BLAKE2b-256 | ecebaa42e8db84ade4c81774601c3123c40e370e29aca90433e0f6173bc445c2 |