Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/dill/__init__.py: 53%

34 statements  

« prev     ^ index     » next       coverage.py v7.2.7, created at 2023-06-07 06:35 +0000

1#!/usr/bin/env python 

2# 

3# Author: Mike McKerns (mmckerns @caltech and @uqfoundation) 

4# Copyright (c) 2008-2016 California Institute of Technology. 

5# Copyright (c) 2016-2022 The Uncertainty Quantification Foundation. 

6# License: 3-clause BSD. The full license text is available at: 

7# - https://github.com/uqfoundation/dill/blob/master/LICENSE 

8 

9# author, version, license, and long description 

10try: # the package is installed 

11 from .__info__ import __version__, __author__, __doc__, __license__ 

12except: # pragma: no cover 

13 import os 

14 import sys 

15 parent = os.path.dirname(os.path.abspath(os.path.dirname(__file__))) 

16 sys.path.append(parent) 

17 # get distribution meta info  

18 from version import (__version__, __author__, 

19 get_license_text, get_readme_as_rst) 

20 __license__ = get_license_text(os.path.join(parent, 'LICENSE')) 

21 __license__ = "\n%s" % __license__ 

22 __doc__ = get_readme_as_rst(os.path.join(parent, 'README.md')) 

23 del os, sys, parent, get_license_text, get_readme_as_rst 

24 

25 

26from ._dill import ( 

27 Pickler, Unpickler, 

28 check, copy, dump, dumps, load, loads, pickle, pickles, register, 

29 DEFAULT_PROTOCOL, HIGHEST_PROTOCOL, CONTENTS_FMODE, FILE_FMODE, HANDLE_FMODE, 

30 PickleError, PickleWarning, PicklingError, PicklingWarning, UnpicklingError, 

31 UnpicklingWarning, 

32) 

33from .session import ( 

34 dump_module, load_module, load_module_asdict, 

35 dump_session, load_session # backward compatibility 

36) 

37from . import detect, logger, session, source, temp 

38 

39# get global settings 

40from .settings import settings 

41 

42# make sure "trace" is turned off 

43logger.trace(False) 

44 

45from importlib import reload 

46 

47objects = {} 

48# local import of dill._objects 

49#from . import _objects 

50#objects.update(_objects.succeeds) 

51#del _objects 

52 

53# local import of dill.objtypes 

54from . import objtypes as types 

55 

56def load_types(pickleable=True, unpickleable=True): 

57 """load pickleable and/or unpickleable types to ``dill.types`` 

58 

59 ``dill.types`` is meant to mimic the ``types`` module, providing a 

60 registry of object types. By default, the module is empty (for import 

61 speed purposes). Use the ``load_types`` function to load selected object 

62 types to the ``dill.types`` module. 

63 

64 Args: 

65 pickleable (bool, default=True): if True, load pickleable types. 

66 unpickleable (bool, default=True): if True, load unpickleable types. 

67 

68 Returns: 

69 None 

70 """ 

71 # local import of dill.objects 

72 from . import _objects 

73 if pickleable: 

74 objects.update(_objects.succeeds) 

75 else: 

76 [objects.pop(obj,None) for obj in _objects.succeeds] 

77 if unpickleable: 

78 objects.update(_objects.failures) 

79 else: 

80 [objects.pop(obj,None) for obj in _objects.failures] 

81 objects.update(_objects.registered) 

82 del _objects 

83 # reset contents of types to 'empty' 

84 [types.__dict__.pop(obj) for obj in list(types.__dict__.keys()) \ 

85 if obj.find('Type') != -1] 

86 # add corresponding types from objects to types 

87 reload(types) 

88 

89def extend(use_dill=True): 

90 '''add (or remove) dill types to/from the pickle registry 

91 

92 by default, ``dill`` populates its types to ``pickle.Pickler.dispatch``. 

93 Thus, all ``dill`` types are available upon calling ``'import pickle'``. 

94 To drop all ``dill`` types from the ``pickle`` dispatch, *use_dill=False*. 

95 

96 Args: 

97 use_dill (bool, default=True): if True, extend the dispatch table. 

98 

99 Returns: 

100 None 

101 ''' 

102 from ._dill import _revert_extension, _extend 

103 if use_dill: _extend() 

104 else: _revert_extension() 

105 return 

106 

107extend() 

108 

109 

110def license(): 

111 """print license""" 

112 print (__license__) 

113 return 

114 

115def citation(): 

116 """print citation""" 

117 print (__doc__[-491:-118]) 

118 return 

119 

120# end of file