pickle4.py 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  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. r'''>>> import pickle4_ext
  5. >>> import pickle
  6. >>> def world_getinitargs(self):
  7. ... return (self.get_country(),)
  8. >>> pickle4_ext.world.__getinitargs__ = world_getinitargs
  9. >>> pickle4_ext.world.__module__
  10. 'pickle4_ext'
  11. >>> pickle4_ext.world.__safe_for_unpickling__
  12. 1
  13. >>> pickle4_ext.world.__name__
  14. 'world'
  15. >>> pickle4_ext.world('Hello').__reduce__()
  16. (<class 'pickle4_ext.world'>, ('Hello',))
  17. >>> wd = pickle4_ext.world('California')
  18. >>> pstr = pickle.dumps(wd)
  19. >>> wl = pickle.loads(pstr)
  20. >>> print(wd.greet())
  21. Hello from California!
  22. >>> print(wl.greet())
  23. Hello from California!
  24. '''
  25. def run(args = None):
  26. import sys
  27. import doctest
  28. if args is not None:
  29. sys.argv = args
  30. return doctest.testmod(sys.modules.get(__name__))
  31. if __name__ == '__main__':
  32. print("running...")
  33. import sys
  34. status = run()[0]
  35. if (status == 0): print("Done.")
  36. sys.exit(status)