byarse-1.2.0
توضیحات
Serialize Arguments as Bytes!
| ویژگی | مقدار |
|---|---|
| سیستم عامل | OS Independent |
| نام فایل | byarse-1.2.0 |
| نام | byarse |
| نسخه کتابخانه | 1.2.0 |
| نگهدارنده | [] |
| ایمیل نگهدارنده | [] |
| نویسنده | Netriza |
| ایمیل نویسنده | info@netriza.ml |
| آدرس صفحه اصلی | https://github.com/netriza/byarse |
| آدرس اینترنتی | https://pypi.org/project/byarse/ |
| مجوز | - |
# Bytes Argument Serializer
## BAS Object
```python
from byarse import BAS
bas = BAS(
safe=True, # Enable/disable safe mode. Safe mode prevents Pickle objects from being deserialized! (enabled by default)
)
```
## Serialize
```python
serialized = bas.s([
'Hello, world!', # string
b'Hello, world!', # bytes
42, # int
2.5, # float
datetime.datetime.utcnow(), # datetime
]) # b'...'
```
## Deserialize
```python
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.
```python
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
```python
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!)
```
زبان مورد نیاز
| مقدار | نام |
|---|---|
| >=3 | Python |
نحوه نصب
نصب پکیج whl byarse-1.2.0:
pip install byarse-1.2.0.whl
نصب پکیج tar.gz byarse-1.2.0:
pip install byarse-1.2.0.tar.gz