pickle: Add trivial pickle implementation using repr()/exec().

pull/118/head
Paul Sokolovsky 2014-05-01 10:47:56 +03:00
rodzic b975f8652c
commit dffb8ac59b
3 zmienionych plików z 35 dodań i 0 usunięć

14
pickle/pickle.py 100644
Wyświetl plik

@ -0,0 +1,14 @@
def dump(obj, f):
f.write(repr(obj))
def dumps(obj):
return repr(obj)
def load(f):
s = f.read()
return loads(s)
def loads(s):
d = {}
exec("v=" + s, d)
return d["v"]

14
pickle/setup.py 100644
Wyświetl plik

@ -0,0 +1,14 @@
import sys
# Remove current dir from sys.path, otherwise distutils will peek up our
# module instead of system.
sys.path.pop(0)
from setuptools import setup
setup(name='micropython-pickle',
version='0.0.1',
description='pickle module to MicroPython',
url='https://github.com/micropython/micropython/issues/405',
author='Paul Sokolovsky',
author_email='micro-python@googlegroups.com',
license='MIT',
py_modules=['pickle'])

Wyświetl plik

@ -0,0 +1,7 @@
import pickle
import sys
import io
pickle.dump({1:2}, sys.stdout)
print(pickle.loads("{4:5}"))