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

Shortcuts on this page

r m x   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

35 statements  

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-2025 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 dump, dumps, load, loads, copy, 

28 Pickler, Unpickler, register, pickle, pickles, check, 

29 DEFAULT_PROTOCOL, HIGHEST_PROTOCOL, HANDLE_FMODE, CONTENTS_FMODE, FILE_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 

45objects = {} 

46# local import of dill._objects 

47#from . import _objects 

48#objects.update(_objects.succeeds) 

49#del _objects 

50 

51# local import of dill.objtypes 

52from . import objtypes as types 

53 

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

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

56 

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

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

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

60 types to the ``dill.types`` module. 

61 

62 Args: 

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

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

65 

66 Returns: 

67 None 

68 """ 

69 from importlib import reload 

70 # local import of dill.objects 

71 from . import _objects 

72 if pickleable: 

73 objects.update(_objects.succeeds) 

74 else: 

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

76 if unpickleable: 

77 objects.update(_objects.failures) 

78 else: 

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

80 objects.update(_objects.registered) 

81 del _objects 

82 # reset contents of types to 'empty' 

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

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

85 # add corresponding types from objects to types 

86 reload(types) 

87 

88def extend(use_dill=True): 

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

90 

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

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

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

94 

95 Args: 

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

97 

98 Returns: 

99 None 

100 ''' 

101 from ._dill import _revert_extension, _extend 

102 if use_dill: _extend() 

103 else: _revert_extension() 

104 return 

105 

106extend() 

107 

108 

109def license(): 

110 """print license""" 

111 print (__license__) 

112 return 

113 

114def citation(): 

115 """print citation""" 

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

117 return 

118 

119# end of file