]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/python/test/pickle2.py
1 # Copyright David Abrahams 2004. Distributed under the Boost
2 # Software License, Version 1.0. (See accompanying
3 # file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
4 from __future__
import print_function
5 r
'''>>> import pickle2_ext
7 >>> pickle2_ext.world.__module__
9 >>> pickle2_ext.world.__safe_for_unpickling__
11 >>> pickle2_ext.world.__name__
13 >>> pickle2_ext.world('Hello').__reduce__()
14 (<class 'pickle2_ext.world'>, ('Hello',), (0,))
15 >>> for number in (24, 42):
16 ... wd = pickle2_ext.world('California')
17 ... wd.set_secret_number(number)
18 ... pstr = pickle.dumps(wd)
19 ... wl = pickle.loads(pstr)
20 ... print(wd.greet(), wd.get_secret_number())
21 ... print(wl.greet(), wl.get_secret_number())
22 Hello from California! 24
23 Hello from California! 24
24 Hello from California! 42
25 Hello from California! 0
27 # Now show that the __dict__ is not taken care of.
28 >>> wd = pickle2_ext.world('California')
32 >>> try: pstr = pickle.dumps(wd)
33 ... except RuntimeError as err: print(err)
35 Incomplete pickle support (__getstate_manages_dict__ not set)
44 return doctest
.testmod(sys
.modules
.get(__name__
))
46 if __name__
== '__main__':
50 if (status
== 0): print("Done.")