ADAPT-Chase commited on
Commit
994b50e
·
verified ·
1 Parent(s): e197c0a

Add files using upload-large-folder tool

Browse files
Files changed (20) hide show
  1. tool_server/.venv/lib/python3.12/site-packages/dill/tests/__init__.py +22 -0
  2. tool_server/.venv/lib/python3.12/site-packages/dill/tests/__main__.py +35 -0
  3. tool_server/.venv/lib/python3.12/site-packages/dill/tests/test_abc.py +169 -0
  4. tool_server/.venv/lib/python3.12/site-packages/dill/tests/test_check.py +62 -0
  5. tool_server/.venv/lib/python3.12/site-packages/dill/tests/test_classdef.py +340 -0
  6. tool_server/.venv/lib/python3.12/site-packages/dill/tests/test_dataclasses.py +35 -0
  7. tool_server/.venv/lib/python3.12/site-packages/dill/tests/test_detect.py +160 -0
  8. tool_server/.venv/lib/python3.12/site-packages/dill/tests/test_dictviews.py +39 -0
  9. tool_server/.venv/lib/python3.12/site-packages/dill/tests/test_diff.py +107 -0
  10. tool_server/.venv/lib/python3.12/site-packages/dill/tests/test_extendpickle.py +53 -0
  11. tool_server/.venv/lib/python3.12/site-packages/dill/tests/test_fglobals.py +55 -0
  12. tool_server/.venv/lib/python3.12/site-packages/dill/tests/test_file.py +500 -0
  13. tool_server/.venv/lib/python3.12/site-packages/dill/tests/test_functions.py +141 -0
  14. tool_server/.venv/lib/python3.12/site-packages/dill/tests/test_functors.py +39 -0
  15. tool_server/.venv/lib/python3.12/site-packages/dill/tests/test_logger.py +70 -0
  16. tool_server/.venv/lib/python3.12/site-packages/dill/tests/test_mixins.py +121 -0
  17. tool_server/.venv/lib/python3.12/site-packages/diskcache/__pycache__/djangocache.cpython-312.pyc +0 -0
  18. tool_server/.venv/lib/python3.12/site-packages/diskcache/__pycache__/fanout.cpython-312.pyc +0 -0
  19. tool_server/.venv/lib/python3.12/site-packages/diskcache/__pycache__/persistent.cpython-312.pyc +0 -0
  20. tool_server/.venv/lib/python3.12/site-packages/diskcache/__pycache__/recipes.cpython-312.pyc +0 -0
tool_server/.venv/lib/python3.12/site-packages/dill/tests/__init__.py ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python
2
+ #
3
+ # Author: Mike McKerns (mmckerns @caltech and @uqfoundation)
4
+ # Copyright (c) 2018-2025 The Uncertainty Quantification Foundation.
5
+ # License: 3-clause BSD. The full license text is available at:
6
+ # - https://github.com/uqfoundation/dill/blob/master/LICENSE
7
+ """
8
+ to run this test suite, first build and install `dill`.
9
+
10
+ $ python -m pip install ../..
11
+
12
+
13
+ then run the tests with:
14
+
15
+ $ python -m dill.tests
16
+
17
+
18
+ or, if `nose` is installed:
19
+
20
+ $ nosetests
21
+
22
+ """
tool_server/.venv/lib/python3.12/site-packages/dill/tests/__main__.py ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python
2
+ #
3
+ # Author: Mike McKerns (mmckerns @caltech and @uqfoundation)
4
+ # Copyright (c) 2018-2025 The Uncertainty Quantification Foundation.
5
+ # License: 3-clause BSD. The full license text is available at:
6
+ # - https://github.com/uqfoundation/dill/blob/master/LICENSE
7
+
8
+ import glob
9
+ import os
10
+ import sys
11
+ import subprocess as sp
12
+ python = sys.executable
13
+ try:
14
+ import pox
15
+ python = pox.which_python(version=True) or python
16
+ except ImportError:
17
+ pass
18
+ shell = sys.platform[:3] == 'win'
19
+
20
+ suite = os.path.dirname(__file__) or os.path.curdir
21
+ tests = glob.glob(suite + os.path.sep + 'test_*.py')
22
+
23
+
24
+ if __name__ == '__main__':
25
+
26
+ failed = 0
27
+ for test in tests:
28
+ p = sp.Popen([python, test], shell=shell).wait()
29
+ if p:
30
+ print('F', end='', flush=True)
31
+ failed = 1
32
+ else:
33
+ print('.', end='', flush=True)
34
+ print('')
35
+ exit(failed)
tool_server/.venv/lib/python3.12/site-packages/dill/tests/test_abc.py ADDED
@@ -0,0 +1,169 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python
2
+ #
3
+ # Author: Mike McKerns (mmckerns @caltech and @uqfoundation)
4
+ # Copyright (c) 2023-2025 The Uncertainty Quantification Foundation.
5
+ # License: 3-clause BSD. The full license text is available at:
6
+ # - https://github.com/uqfoundation/dill/blob/master/LICENSE
7
+ """
8
+ test dill's ability to pickle abstract base class objects
9
+ """
10
+ import dill
11
+ import abc
12
+ from abc import ABC
13
+ import warnings
14
+
15
+ from types import FunctionType
16
+
17
+ dill.settings['recurse'] = True
18
+
19
+ class OneTwoThree(ABC):
20
+ @abc.abstractmethod
21
+ def foo(self):
22
+ """A method"""
23
+ pass
24
+
25
+ @property
26
+ @abc.abstractmethod
27
+ def bar(self):
28
+ """Property getter"""
29
+ pass
30
+
31
+ @bar.setter
32
+ @abc.abstractmethod
33
+ def bar(self, value):
34
+ """Property setter"""
35
+ pass
36
+
37
+ @classmethod
38
+ @abc.abstractmethod
39
+ def cfoo(cls):
40
+ """Class method"""
41
+ pass
42
+
43
+ @staticmethod
44
+ @abc.abstractmethod
45
+ def sfoo():
46
+ """Static method"""
47
+ pass
48
+
49
+ class EasyAsAbc(OneTwoThree):
50
+ def __init__(self):
51
+ self._bar = None
52
+
53
+ def foo(self):
54
+ return "Instance Method FOO"
55
+
56
+ @property
57
+ def bar(self):
58
+ return self._bar
59
+
60
+ @bar.setter
61
+ def bar(self, value):
62
+ self._bar = value
63
+
64
+ @classmethod
65
+ def cfoo(cls):
66
+ return "Class Method CFOO"
67
+
68
+ @staticmethod
69
+ def sfoo():
70
+ return "Static Method SFOO"
71
+
72
+ def test_abc_non_local():
73
+ assert dill.copy(OneTwoThree) is not OneTwoThree
74
+ assert dill.copy(EasyAsAbc) is not EasyAsAbc
75
+
76
+ with warnings.catch_warnings():
77
+ warnings.simplefilter("ignore", dill.PicklingWarning)
78
+ assert dill.copy(OneTwoThree, byref=True) is OneTwoThree
79
+ assert dill.copy(EasyAsAbc, byref=True) is EasyAsAbc
80
+
81
+ instance = EasyAsAbc()
82
+ # Set a property that StockPickle can't preserve
83
+ instance.bar = lambda x: x**2
84
+ depickled = dill.copy(instance)
85
+ assert type(depickled) is type(instance) #NOTE: issue #612, test_abc_local
86
+ #NOTE: dill.copy of local (or non-local) classes should (not) be the same?
87
+ assert type(depickled.bar) is FunctionType
88
+ assert depickled.bar(3) == 9
89
+ assert depickled.sfoo() == "Static Method SFOO"
90
+ assert depickled.cfoo() == "Class Method CFOO"
91
+ assert depickled.foo() == "Instance Method FOO"
92
+
93
+ def test_abc_local():
94
+ """
95
+ Test using locally scoped ABC class
96
+ """
97
+ class LocalABC(ABC):
98
+ @abc.abstractmethod
99
+ def foo(self):
100
+ pass
101
+
102
+ def baz(self):
103
+ return repr(self)
104
+
105
+ labc = dill.copy(LocalABC)
106
+ assert labc is not LocalABC
107
+ assert type(labc) is type(LocalABC)
108
+ #NOTE: dill.copy of local (or non-local) classes should (not) be the same?
109
+ # <class '__main__.LocalABC'>
110
+ # <class '__main__.test_abc_local.<locals>.LocalABC'>
111
+
112
+ class Real(labc):
113
+ def foo(self):
114
+ return "True!"
115
+
116
+ def baz(self):
117
+ return "My " + super(Real, self).baz()
118
+
119
+ real = Real()
120
+ assert real.foo() == "True!"
121
+
122
+ try:
123
+ labc()
124
+ except TypeError as e:
125
+ # Expected error
126
+ pass
127
+ else:
128
+ print('Failed to raise type error')
129
+ assert False
130
+
131
+ labc2, pik = dill.copy((labc, Real()))
132
+ assert 'Real' == type(pik).__name__
133
+ assert '.Real' in type(pik).__qualname__
134
+ assert type(pik) is not Real
135
+ assert labc2 is not LocalABC
136
+ assert labc2 is not labc
137
+ assert isinstance(pik, labc2)
138
+ assert not isinstance(pik, labc)
139
+ assert not isinstance(pik, LocalABC)
140
+ assert pik.baz() == "My " + repr(pik)
141
+
142
+ def test_meta_local_no_cache():
143
+ """
144
+ Test calling metaclass and cache registration
145
+ """
146
+ LocalMetaABC = abc.ABCMeta('LocalMetaABC', (), {})
147
+
148
+ class ClassyClass:
149
+ pass
150
+
151
+ class KlassyClass:
152
+ pass
153
+
154
+ LocalMetaABC.register(ClassyClass)
155
+
156
+ assert not issubclass(KlassyClass, LocalMetaABC)
157
+ assert issubclass(ClassyClass, LocalMetaABC)
158
+
159
+ res = dill.dumps((LocalMetaABC, ClassyClass, KlassyClass))
160
+
161
+ lmabc, cc, kc = dill.loads(res)
162
+ assert type(lmabc) == type(LocalMetaABC)
163
+ assert not issubclass(kc, lmabc)
164
+ assert issubclass(cc, lmabc)
165
+
166
+ if __name__ == '__main__':
167
+ test_abc_non_local()
168
+ test_abc_local()
169
+ test_meta_local_no_cache()
tool_server/.venv/lib/python3.12/site-packages/dill/tests/test_check.py ADDED
@@ -0,0 +1,62 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ from dill import check
10
+ import sys
11
+
12
+ from dill.temp import capture
13
+
14
+
15
+ #FIXME: this doesn't catch output... it's from the internal call
16
+ def raise_check(func, **kwds):
17
+ try:
18
+ with capture('stdout') as out:
19
+ check(func, **kwds)
20
+ except Exception:
21
+ e = sys.exc_info()[1]
22
+ raise AssertionError(str(e))
23
+ else:
24
+ assert 'Traceback' not in out.getvalue()
25
+ finally:
26
+ out.close()
27
+
28
+
29
+ f = lambda x:x**2
30
+
31
+
32
+ def test_simple(verbose=None):
33
+ raise_check(f, verbose=verbose)
34
+
35
+
36
+ def test_recurse(verbose=None):
37
+ raise_check(f, recurse=True, verbose=verbose)
38
+
39
+
40
+ def test_byref(verbose=None):
41
+ raise_check(f, byref=True, verbose=verbose)
42
+
43
+
44
+ def test_protocol(verbose=None):
45
+ raise_check(f, protocol=True, verbose=verbose)
46
+
47
+
48
+ def test_python(verbose=None):
49
+ raise_check(f, python=None, verbose=verbose)
50
+
51
+
52
+ #TODO: test incompatible versions
53
+ #TODO: test dump failure
54
+ #TODO: test load failure
55
+
56
+
57
+ if __name__ == '__main__':
58
+ test_simple()
59
+ test_recurse()
60
+ test_byref()
61
+ test_protocol()
62
+ test_python()
tool_server/.venv/lib/python3.12/site-packages/dill/tests/test_classdef.py ADDED
@@ -0,0 +1,340 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ import dill
10
+ from enum import EnumMeta
11
+ import sys
12
+ dill.settings['recurse'] = True
13
+
14
+ # test classdefs
15
+ class _class:
16
+ def _method(self):
17
+ pass
18
+ def ok(self):
19
+ return True
20
+
21
+ class _class2:
22
+ def __call__(self):
23
+ pass
24
+ def ok(self):
25
+ return True
26
+
27
+ class _newclass(object):
28
+ def _method(self):
29
+ pass
30
+ def ok(self):
31
+ return True
32
+
33
+ class _newclass2(object):
34
+ def __call__(self):
35
+ pass
36
+ def ok(self):
37
+ return True
38
+
39
+ class _meta(type):
40
+ pass
41
+
42
+ def __call__(self):
43
+ pass
44
+ def ok(self):
45
+ return True
46
+
47
+ _mclass = _meta("_mclass", (object,), {"__call__": __call__, "ok": ok})
48
+
49
+ del __call__
50
+ del ok
51
+
52
+ o = _class()
53
+ oc = _class2()
54
+ n = _newclass()
55
+ nc = _newclass2()
56
+ m = _mclass()
57
+
58
+ if sys.hexversion < 0x03090000:
59
+ import typing
60
+ class customIntList(typing.List[int]):
61
+ pass
62
+ else:
63
+ class customIntList(list[int]):
64
+ pass
65
+
66
+ # test pickles for class instances
67
+ def test_class_instances():
68
+ assert dill.pickles(o)
69
+ assert dill.pickles(oc)
70
+ assert dill.pickles(n)
71
+ assert dill.pickles(nc)
72
+ assert dill.pickles(m)
73
+
74
+ def test_class_objects():
75
+ clslist = [_class,_class2,_newclass,_newclass2,_mclass]
76
+ objlist = [o,oc,n,nc,m]
77
+ _clslist = [dill.dumps(obj) for obj in clslist]
78
+ _objlist = [dill.dumps(obj) for obj in objlist]
79
+
80
+ for obj in clslist:
81
+ globals().pop(obj.__name__)
82
+ del clslist
83
+ for obj in ['o','oc','n','nc']:
84
+ globals().pop(obj)
85
+ del objlist
86
+ del obj
87
+
88
+ for obj,cls in zip(_objlist,_clslist):
89
+ _cls = dill.loads(cls)
90
+ _obj = dill.loads(obj)
91
+ assert _obj.ok()
92
+ assert _cls.ok(_cls())
93
+ if _cls.__name__ == "_mclass":
94
+ assert type(_cls).__name__ == "_meta"
95
+
96
+ # test NoneType
97
+ def test_specialtypes():
98
+ assert dill.pickles(type(None))
99
+ assert dill.pickles(type(NotImplemented))
100
+ assert dill.pickles(type(Ellipsis))
101
+ assert dill.pickles(type(EnumMeta))
102
+
103
+ from collections import namedtuple
104
+ Z = namedtuple("Z", ['a','b'])
105
+ Zi = Z(0,1)
106
+ X = namedtuple("Y", ['a','b'])
107
+ X.__name__ = "X"
108
+ X.__qualname__ = "X" #XXX: name must 'match' or fails to pickle
109
+ Xi = X(0,1)
110
+ Bad = namedtuple("FakeName", ['a','b'])
111
+ Badi = Bad(0,1)
112
+ Defaults = namedtuple('Defaults', ['x', 'y'], defaults=[1])
113
+ Defaultsi = Defaults(2)
114
+
115
+ # test namedtuple
116
+ def test_namedtuple():
117
+ assert Z is dill.loads(dill.dumps(Z))
118
+ assert Zi == dill.loads(dill.dumps(Zi))
119
+ assert X is dill.loads(dill.dumps(X))
120
+ assert Xi == dill.loads(dill.dumps(Xi))
121
+ assert Defaults is dill.loads(dill.dumps(Defaults))
122
+ assert Defaultsi == dill.loads(dill.dumps(Defaultsi))
123
+ assert Bad is not dill.loads(dill.dumps(Bad))
124
+ assert Bad._fields == dill.loads(dill.dumps(Bad))._fields
125
+ assert tuple(Badi) == tuple(dill.loads(dill.dumps(Badi)))
126
+
127
+ class A:
128
+ class B(namedtuple("C", ["one", "two"])):
129
+ '''docstring'''
130
+ B.__module__ = 'testing'
131
+
132
+ a = A()
133
+ assert dill.copy(a)
134
+
135
+ assert dill.copy(A.B).__name__ == 'B'
136
+ assert dill.copy(A.B).__qualname__.endswith('.<locals>.A.B')
137
+ assert dill.copy(A.B).__doc__ == 'docstring'
138
+ assert dill.copy(A.B).__module__ == 'testing'
139
+
140
+ from typing import NamedTuple
141
+
142
+ def A():
143
+ class B(NamedTuple):
144
+ x: int
145
+ return B
146
+
147
+ assert type(dill.copy(A()(8))).__qualname__ == type(A()(8)).__qualname__
148
+
149
+ def test_dtype():
150
+ try:
151
+ import numpy as np
152
+
153
+ dti = np.dtype('int')
154
+ assert np.dtype == dill.copy(np.dtype)
155
+ assert dti == dill.copy(dti)
156
+ except ImportError: pass
157
+
158
+
159
+ def test_array_nested():
160
+ try:
161
+ import numpy as np
162
+
163
+ x = np.array([1])
164
+ y = (x,)
165
+ assert y == dill.copy(y)
166
+
167
+ except ImportError: pass
168
+
169
+
170
+ def test_array_subclass():
171
+ try:
172
+ import numpy as np
173
+
174
+ class TestArray(np.ndarray):
175
+ def __new__(cls, input_array, color):
176
+ obj = np.asarray(input_array).view(cls)
177
+ obj.color = color
178
+ return obj
179
+ def __array_finalize__(self, obj):
180
+ if obj is None:
181
+ return
182
+ if isinstance(obj, type(self)):
183
+ self.color = obj.color
184
+ def __getnewargs__(self):
185
+ return np.asarray(self), self.color
186
+
187
+ a1 = TestArray(np.zeros(100), color='green')
188
+ if not dill._dill.IS_PYPY:
189
+ assert dill.pickles(a1)
190
+ assert a1.__dict__ == dill.copy(a1).__dict__
191
+
192
+ a2 = a1[0:9]
193
+ if not dill._dill.IS_PYPY:
194
+ assert dill.pickles(a2)
195
+ assert a2.__dict__ == dill.copy(a2).__dict__
196
+
197
+ class TestArray2(np.ndarray):
198
+ color = 'blue'
199
+
200
+ a3 = TestArray2([1,2,3,4,5])
201
+ a3.color = 'green'
202
+ if not dill._dill.IS_PYPY:
203
+ assert dill.pickles(a3)
204
+ assert a3.__dict__ == dill.copy(a3).__dict__
205
+
206
+ except ImportError: pass
207
+
208
+
209
+ def test_method_decorator():
210
+ class A(object):
211
+ @classmethod
212
+ def test(cls):
213
+ pass
214
+
215
+ a = A()
216
+
217
+ res = dill.dumps(a)
218
+ new_obj = dill.loads(res)
219
+ new_obj.__class__.test()
220
+
221
+ # test slots
222
+ class Y(object):
223
+ __slots__ = ('y', '__weakref__')
224
+ def __init__(self, y):
225
+ self.y = y
226
+
227
+ value = 123
228
+ y = Y(value)
229
+
230
+ class Y2(object):
231
+ __slots__ = 'y'
232
+ def __init__(self, y):
233
+ self.y = y
234
+
235
+ def test_slots():
236
+ assert dill.pickles(Y)
237
+ assert dill.pickles(y)
238
+ assert dill.pickles(Y.y)
239
+ assert dill.copy(y).y == value
240
+ assert dill.copy(Y2(value)).y == value
241
+
242
+ def test_origbases():
243
+ assert dill.copy(customIntList).__orig_bases__ == customIntList.__orig_bases__
244
+
245
+ def test_attr():
246
+ import attr
247
+ @attr.s
248
+ class A:
249
+ a = attr.ib()
250
+
251
+ v = A(1)
252
+ assert dill.copy(v) == v
253
+
254
+ def test_metaclass():
255
+ class metaclass_with_new(type):
256
+ def __new__(mcls, name, bases, ns, **kwds):
257
+ cls = super().__new__(mcls, name, bases, ns, **kwds)
258
+ assert mcls is not None
259
+ assert cls.method(mcls)
260
+ return cls
261
+ def method(cls, mcls):
262
+ return isinstance(cls, mcls)
263
+
264
+ l = locals()
265
+ exec("""class subclass_with_new(metaclass=metaclass_with_new):
266
+ def __new__(cls):
267
+ self = super().__new__(cls)
268
+ return self""", None, l)
269
+ subclass_with_new = l['subclass_with_new']
270
+
271
+ assert dill.copy(subclass_with_new())
272
+
273
+ def test_enummeta():
274
+ from http import HTTPStatus
275
+ import enum
276
+ assert dill.copy(HTTPStatus.OK) is HTTPStatus.OK
277
+ assert dill.copy(enum.EnumMeta) is enum.EnumMeta
278
+
279
+ def test_inherit(): #NOTE: see issue #612
280
+ class Foo:
281
+ w = 0
282
+ x = 1
283
+ y = 1.1
284
+ a = ()
285
+ b = (1,)
286
+ n = None
287
+
288
+ class Bar(Foo):
289
+ w = 2
290
+ x = 1
291
+ y = 1.1
292
+ z = 0.2
293
+ a = ()
294
+ b = (1,)
295
+ c = (2,)
296
+ n = None
297
+
298
+ Baz = dill.copy(Bar)
299
+
300
+ import platform
301
+ is_pypy = platform.python_implementation() == 'PyPy'
302
+ assert Bar.__dict__ == Baz.__dict__
303
+ # ints
304
+ assert 'w' in Bar.__dict__ and 'w' in Baz.__dict__
305
+ assert Bar.__dict__['w'] is Baz.__dict__['w']
306
+ assert 'x' in Bar.__dict__ and 'x' in Baz.__dict__
307
+ assert Bar.__dict__['x'] is Baz.__dict__['x']
308
+ # floats
309
+ assert 'y' in Bar.__dict__ and 'y' in Baz.__dict__
310
+ same = Bar.__dict__['y'] is Baz.__dict__['y']
311
+ assert same if is_pypy else not same
312
+ assert 'z' in Bar.__dict__ and 'z' in Baz.__dict__
313
+ same = Bar.__dict__['z'] is Baz.__dict__['z']
314
+ assert same if is_pypy else not same
315
+ # tuples
316
+ assert 'a' in Bar.__dict__ and 'a' in Baz.__dict__
317
+ assert Bar.__dict__['a'] is Baz.__dict__['a']
318
+ assert 'b' in Bar.__dict__ and 'b' in Baz.__dict__
319
+ assert Bar.__dict__['b'] is not Baz.__dict__['b']
320
+ assert 'c' in Bar.__dict__ and 'c' in Baz.__dict__
321
+ assert Bar.__dict__['c'] is not Baz.__dict__['c']
322
+ # None
323
+ assert 'n' in Bar.__dict__ and 'n' in Baz.__dict__
324
+ assert Bar.__dict__['n'] is Baz.__dict__['n']
325
+
326
+
327
+ if __name__ == '__main__':
328
+ test_class_instances()
329
+ test_class_objects()
330
+ test_specialtypes()
331
+ test_namedtuple()
332
+ test_dtype()
333
+ test_array_nested()
334
+ test_array_subclass()
335
+ test_method_decorator()
336
+ test_slots()
337
+ test_origbases()
338
+ test_metaclass()
339
+ test_enummeta()
340
+ test_inherit()
tool_server/.venv/lib/python3.12/site-packages/dill/tests/test_dataclasses.py ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python
2
+ #
3
+ # Author: Mike McKerns (mmckerns @caltech and @uqfoundation)
4
+ # Author: Anirudh Vegesana (avegesan@cs.stanford.edu)
5
+ # Copyright (c) 2022-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
+ test pickling a dataclass
10
+ """
11
+
12
+ import dill
13
+ import dataclasses
14
+
15
+ def test_dataclasses():
16
+ # Issue #500
17
+ @dataclasses.dataclass
18
+ class A:
19
+ x: int
20
+ y: str
21
+
22
+ @dataclasses.dataclass
23
+ class B:
24
+ a: A
25
+
26
+ a = A(1, "test")
27
+ before = B(a)
28
+ save = dill.dumps(before)
29
+ after = dill.loads(save)
30
+ assert before != after # classes don't match
31
+ assert before == B(A(**dataclasses.asdict(after.a)))
32
+ assert dataclasses.asdict(before) == dataclasses.asdict(after)
33
+
34
+ if __name__ == '__main__':
35
+ test_dataclasses()
tool_server/.venv/lib/python3.12/site-packages/dill/tests/test_detect.py ADDED
@@ -0,0 +1,160 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ from dill.detect import baditems, badobjects, badtypes, errors, parent, at, globalvars
10
+ from dill import settings
11
+ from dill._dill import IS_PYPY
12
+ from pickle import PicklingError
13
+
14
+ import inspect
15
+ import sys
16
+ import os
17
+
18
+ def test_bad_things():
19
+ f = inspect.currentframe()
20
+ assert baditems(f) == [f]
21
+ #assert baditems(globals()) == [f] #XXX
22
+ assert badobjects(f) is f
23
+ assert badtypes(f) == type(f)
24
+ assert type(errors(f)) is TypeError
25
+ d = badtypes(f, 1)
26
+ assert isinstance(d, dict)
27
+ assert list(badobjects(f, 1).keys()) == list(d.keys())
28
+ assert list(errors(f, 1).keys()) == list(d.keys())
29
+ s = set([(err.__class__.__name__,err.args[0]) for err in list(errors(f, 1).values())])
30
+ a = dict(s)
31
+ if not os.environ.get('COVERAGE'): #XXX: travis-ci
32
+ proxy = 0 if type(f.f_locals) is dict else 1
33
+ assert len(s) == len(a) + proxy # TypeError (and possibly PicklingError)
34
+ n = 2
35
+ assert len(a) is n if 'PicklingError' in a.keys() else n-1
36
+
37
+ def test_parent():
38
+ x = [4,5,6,7]
39
+ listiter = iter(x)
40
+ obj = parent(listiter, list)
41
+ assert obj is x
42
+
43
+ if IS_PYPY: assert parent(obj, int) is None
44
+ else: assert parent(obj, int) is x[-1] # python oddly? finds last int
45
+ assert at(id(at)) is at
46
+
47
+ a, b, c = 1, 2, 3
48
+
49
+ def squared(x):
50
+ return a+x**2
51
+
52
+ def foo(x):
53
+ def bar(y):
54
+ return squared(x)+y
55
+ return bar
56
+
57
+ class _class:
58
+ def _method(self):
59
+ pass
60
+ def ok(self):
61
+ return True
62
+
63
+ def test_globals():
64
+ def f():
65
+ a
66
+ def g():
67
+ b
68
+ def h():
69
+ c
70
+ assert globalvars(f) == dict(a=1, b=2, c=3)
71
+
72
+ res = globalvars(foo, recurse=True)
73
+ assert set(res) == set(['squared', 'a'])
74
+ res = globalvars(foo, recurse=False)
75
+ assert res == {}
76
+ zap = foo(2)
77
+ res = globalvars(zap, recurse=True)
78
+ assert set(res) == set(['squared', 'a'])
79
+ res = globalvars(zap, recurse=False)
80
+ assert set(res) == set(['squared'])
81
+ del zap
82
+ res = globalvars(squared)
83
+ assert set(res) == set(['a'])
84
+ # FIXME: should find referenced __builtins__
85
+ #res = globalvars(_class, recurse=True)
86
+ #assert set(res) == set(['True'])
87
+ #res = globalvars(_class, recurse=False)
88
+ #assert res == {}
89
+ #res = globalvars(_class.ok, recurse=True)
90
+ #assert set(res) == set(['True'])
91
+ #res = globalvars(_class.ok, recurse=False)
92
+ #assert set(res) == set(['True'])
93
+
94
+
95
+ #98 dill ignores __getstate__ in interactive lambdas
96
+ bar = [0]
97
+
98
+ class Foo(object):
99
+ def __init__(self):
100
+ pass
101
+ def __getstate__(self):
102
+ bar[0] = bar[0]+1
103
+ return {}
104
+ def __setstate__(self, data):
105
+ pass
106
+
107
+ f = Foo()
108
+
109
+ def test_getstate():
110
+ from dill import dumps, loads
111
+ dumps(f)
112
+ b = bar[0]
113
+ dumps(lambda: f, recurse=False) # doesn't call __getstate__
114
+ assert bar[0] == b
115
+ dumps(lambda: f, recurse=True) # calls __getstate__
116
+ assert bar[0] == b + 1
117
+
118
+ #97 serialize lambdas in test files
119
+ def test_deleted():
120
+ global sin
121
+ from dill import dumps, loads
122
+ from math import sin, pi
123
+
124
+ def sinc(x):
125
+ return sin(x)/x
126
+
127
+ settings['recurse'] = True
128
+ _sinc = dumps(sinc)
129
+ sin = globals().pop('sin')
130
+ sin = 1
131
+ del sin
132
+ sinc_ = loads(_sinc) # no NameError... pickling preserves 'sin'
133
+ res = sinc_(1)
134
+ from math import sin
135
+ assert sinc(1) == res
136
+
137
+
138
+ def test_lambdify():
139
+ try:
140
+ from sympy import symbols, lambdify
141
+ except ImportError:
142
+ return
143
+ settings['recurse'] = True
144
+ x = symbols("x")
145
+ y = x**2
146
+ f = lambdify([x], y)
147
+ z = min
148
+ d = globals()
149
+ globalvars(f, recurse=True, builtin=True)
150
+ assert z is min
151
+ assert d is globals()
152
+
153
+
154
+ if __name__ == '__main__':
155
+ test_bad_things()
156
+ test_parent()
157
+ test_globals()
158
+ test_getstate()
159
+ test_deleted()
160
+ test_lambdify()
tool_server/.venv/lib/python3.12/site-packages/dill/tests/test_dictviews.py ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python
2
+ #
3
+ # Author: Mike McKerns (mmckerns @caltech and @uqfoundation)
4
+ # Author: Anirudh Vegesana (avegesan@cs.stanford.edu)
5
+ # Copyright (c) 2021-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
+ import dill
10
+ from dill._dill import OLD310, MAPPING_PROXY_TRICK, DictProxyType
11
+
12
+ def test_dictproxy():
13
+ assert dill.copy(DictProxyType({'a': 2}))
14
+
15
+ def test_dictviews():
16
+ x = {'a': 1}
17
+ assert dill.copy(x.keys())
18
+ assert dill.copy(x.values())
19
+ assert dill.copy(x.items())
20
+
21
+ def test_dictproxy_trick():
22
+ if not OLD310 and MAPPING_PROXY_TRICK:
23
+ x = {'a': 1}
24
+ all_views = (x.values(), x.items(), x.keys(), x)
25
+ seperate_views = dill.copy(all_views)
26
+ new_x = seperate_views[-1]
27
+ new_x['b'] = 2
28
+ new_x['c'] = 1
29
+ assert len(new_x) == 3 and len(x) == 1
30
+ assert len(seperate_views[0]) == 3 and len(all_views[0]) == 1
31
+ assert len(seperate_views[1]) == 3 and len(all_views[1]) == 1
32
+ assert len(seperate_views[2]) == 3 and len(all_views[2]) == 1
33
+ assert dict(all_views[1]) == x
34
+ assert dict(seperate_views[1]) == new_x
35
+
36
+ if __name__ == '__main__':
37
+ test_dictproxy()
38
+ test_dictviews()
39
+ test_dictproxy_trick()
tool_server/.venv/lib/python3.12/site-packages/dill/tests/test_diff.py ADDED
@@ -0,0 +1,107 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ from dill import __diff as diff
10
+
11
+ import sys
12
+ IS_PYPY = not hasattr(sys, 'getrefcount')
13
+
14
+ class A:
15
+ pass
16
+
17
+ def test_diff():
18
+ a = A()
19
+ b = A()
20
+ c = A()
21
+ a.a = b
22
+ b.a = c
23
+ diff.memorise(a)
24
+ assert not diff.has_changed(a)
25
+ c.a = 1
26
+ assert diff.has_changed(a)
27
+ diff.memorise(c, force=True)
28
+ assert not diff.has_changed(a)
29
+ c.a = 2
30
+ assert diff.has_changed(a)
31
+ changed = diff.whats_changed(a)
32
+ assert list(changed[0].keys()) == ["a"]
33
+ assert not changed[1]
34
+
35
+ a2 = []
36
+ b2 = [a2]
37
+ c2 = [b2]
38
+ diff.memorise(c2)
39
+ assert not diff.has_changed(c2)
40
+ a2.append(1)
41
+ assert diff.has_changed(c2)
42
+ changed = diff.whats_changed(c2)
43
+ assert changed[0] == {}
44
+ assert changed[1]
45
+
46
+ a3 = {}
47
+ b3 = {1: a3}
48
+ c3 = {1: b3}
49
+ diff.memorise(c3)
50
+ assert not diff.has_changed(c3)
51
+ a3[1] = 1
52
+ assert diff.has_changed(c3)
53
+ changed = diff.whats_changed(c3)
54
+ assert changed[0] == {}
55
+ assert changed[1]
56
+
57
+ if not IS_PYPY:
58
+ import abc
59
+ # make sure the "_abc_invaldation_counter" doesn't make test fail
60
+ diff.memorise(abc.ABCMeta, force=True)
61
+ assert not diff.has_changed(abc)
62
+ abc.ABCMeta.zzz = 1
63
+ assert diff.has_changed(abc)
64
+ changed = diff.whats_changed(abc)
65
+ assert list(changed[0].keys()) == ["ABCMeta"]
66
+ assert not changed[1]
67
+
68
+ '''
69
+ import Queue
70
+ diff.memorise(Queue, force=True)
71
+ assert not diff.has_changed(Queue)
72
+ Queue.Queue.zzz = 1
73
+ assert diff.has_changed(Queue)
74
+ changed = diff.whats_changed(Queue)
75
+ assert list(changed[0].keys()) == ["Queue"]
76
+ assert not changed[1]
77
+
78
+ import math
79
+ diff.memorise(math, force=True)
80
+ assert not diff.has_changed(math)
81
+ math.zzz = 1
82
+ assert diff.has_changed(math)
83
+ changed = diff.whats_changed(math)
84
+ assert list(changed[0].keys()) == ["zzz"]
85
+ assert not changed[1]
86
+ '''
87
+
88
+ a = A()
89
+ b = A()
90
+ c = A()
91
+ a.a = b
92
+ b.a = c
93
+ diff.memorise(a)
94
+ assert not diff.has_changed(a)
95
+ c.a = 1
96
+ assert diff.has_changed(a)
97
+ diff.memorise(c, force=True)
98
+ assert not diff.has_changed(a)
99
+ del c.a
100
+ assert diff.has_changed(a)
101
+ changed = diff.whats_changed(a)
102
+ assert list(changed[0].keys()) == ["a"]
103
+ assert not changed[1]
104
+
105
+
106
+ if __name__ == '__main__':
107
+ test_diff()
tool_server/.venv/lib/python3.12/site-packages/dill/tests/test_extendpickle.py ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ import dill as pickle
10
+ from io import BytesIO as StringIO
11
+
12
+
13
+ def my_fn(x):
14
+ return x * 17
15
+
16
+
17
+ def test_extend():
18
+ obj = lambda : my_fn(34)
19
+ assert obj() == 578
20
+
21
+ obj_io = StringIO()
22
+ pickler = pickle.Pickler(obj_io)
23
+ pickler.dump(obj)
24
+
25
+ obj_str = obj_io.getvalue()
26
+
27
+ obj2_io = StringIO(obj_str)
28
+ unpickler = pickle.Unpickler(obj2_io)
29
+ obj2 = unpickler.load()
30
+
31
+ assert obj2() == 578
32
+
33
+
34
+ def test_isdill():
35
+ obj_io = StringIO()
36
+ pickler = pickle.Pickler(obj_io)
37
+ assert pickle._dill.is_dill(pickler) is True
38
+
39
+ pickler = pickle._dill.StockPickler(obj_io)
40
+ assert pickle._dill.is_dill(pickler) is False
41
+
42
+ try:
43
+ import multiprocess as mp
44
+ pickler = mp.reduction.ForkingPickler(obj_io)
45
+ assert pickle._dill.is_dill(pickler, child=True) is True
46
+ assert pickle._dill.is_dill(pickler, child=False) is False
47
+ except Exception:
48
+ pass
49
+
50
+
51
+ if __name__ == '__main__':
52
+ test_extend()
53
+ test_isdill()
tool_server/.venv/lib/python3.12/site-packages/dill/tests/test_fglobals.py ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python
2
+ #
3
+ # Author: Mike McKerns (mmckerns @caltech and @uqfoundation)
4
+ # Copyright (c) 2021-2025 The Uncertainty Quantification Foundation.
5
+ # License: 3-clause BSD. The full license text is available at:
6
+ # - https://github.com/uqfoundation/dill/blob/master/LICENSE
7
+
8
+ import dill
9
+ dill.settings['recurse'] = True
10
+
11
+ def get_fun_with_strftime():
12
+ def fun_with_strftime():
13
+ import datetime
14
+ return datetime.datetime.strptime("04-01-1943", "%d-%m-%Y").strftime(
15
+ "%Y-%m-%d %H:%M:%S"
16
+ )
17
+ return fun_with_strftime
18
+
19
+
20
+ def get_fun_with_strftime2():
21
+ import datetime
22
+ return datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
23
+
24
+
25
+ def test_doc_dill_issue_219():
26
+ back_fn = dill.loads(dill.dumps(get_fun_with_strftime()))
27
+ assert back_fn() == "1943-01-04 00:00:00"
28
+ dupl = dill.loads(dill.dumps(get_fun_with_strftime2))
29
+ assert dupl() == get_fun_with_strftime2()
30
+
31
+
32
+ def get_fun_with_internal_import():
33
+ def fun_with_import():
34
+ import re
35
+ return re.compile("$")
36
+ return fun_with_import
37
+
38
+
39
+ def test_method_with_internal_import_should_work():
40
+ import re
41
+ back_fn = dill.loads(dill.dumps(get_fun_with_internal_import()))
42
+ import inspect
43
+ if hasattr(inspect, 'getclosurevars'):
44
+ vars = inspect.getclosurevars(back_fn)
45
+ assert vars.globals == {}
46
+ assert vars.nonlocals == {}
47
+ assert back_fn() == re.compile("$")
48
+ assert "__builtins__" in back_fn.__globals__
49
+
50
+
51
+ if __name__ == "__main__":
52
+ import sys
53
+ if (sys.version_info[:3] != (3,10,0) or sys.version_info[3] != 'alpha'):
54
+ test_doc_dill_issue_219()
55
+ test_method_with_internal_import_should_work()
tool_server/.venv/lib/python3.12/site-packages/dill/tests/test_file.py ADDED
@@ -0,0 +1,500 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ import os
10
+ import sys
11
+ import string
12
+ import random
13
+
14
+ import dill
15
+
16
+
17
+ dill.settings['recurse'] = True
18
+
19
+ fname = "_test_file.txt"
20
+ rand_chars = list(string.ascii_letters) + ["\n"] * 40 # bias newline
21
+
22
+ buffer_error = ValueError("invalid buffer size")
23
+ dne_error = FileNotFoundError("[Errno 2] No such file or directory: '%s'" % fname)
24
+
25
+
26
+ def write_randomness(number=200):
27
+ f = open(fname, "w")
28
+ for i in range(number):
29
+ f.write(random.choice(rand_chars))
30
+ f.close()
31
+ f = open(fname, "r")
32
+ contents = f.read()
33
+ f.close()
34
+ return contents
35
+
36
+
37
+ def trunc_file():
38
+ open(fname, "w").close()
39
+
40
+
41
+ def throws(op, args, exc):
42
+ try:
43
+ op(*args)
44
+ except type(exc):
45
+ return sys.exc_info()[1].args == exc.args
46
+ else:
47
+ return False
48
+
49
+
50
+ def teardown_module():
51
+ if os.path.exists(fname):
52
+ os.remove(fname)
53
+
54
+
55
+ def bench(strictio, fmode, skippypy):
56
+ import platform
57
+ if skippypy and platform.python_implementation() == 'PyPy':
58
+ # Skip for PyPy...
59
+ return
60
+
61
+ # file exists, with same contents
62
+ # read
63
+
64
+ write_randomness()
65
+
66
+ f = open(fname, "r")
67
+ _f = dill.loads(dill.dumps(f, fmode=fmode))#, strictio=strictio))
68
+ assert _f.mode == f.mode
69
+ assert _f.tell() == f.tell()
70
+ assert _f.read() == f.read()
71
+ f.close()
72
+ _f.close()
73
+
74
+ # write
75
+
76
+ f = open(fname, "w")
77
+ f.write("hello")
78
+ f_dumped = dill.dumps(f, fmode=fmode)#, strictio=strictio)
79
+ f1mode = f.mode
80
+ ftell = f.tell()
81
+ f.close()
82
+ f2 = dill.loads(f_dumped) #FIXME: fails due to pypy/issues/1233
83
+ # TypeError: expected py_object instance instead of str
84
+ f2mode = f2.mode
85
+ f2tell = f2.tell()
86
+ f2name = f2.name
87
+ f2.write(" world!")
88
+ f2.close()
89
+
90
+ if fmode == dill.HANDLE_FMODE:
91
+ assert open(fname).read() == " world!"
92
+ assert f2mode == f1mode
93
+ assert f2tell == 0
94
+ elif fmode == dill.CONTENTS_FMODE:
95
+ assert open(fname).read() == "hello world!"
96
+ assert f2mode == f1mode
97
+ assert f2tell == ftell
98
+ assert f2name == fname
99
+ elif fmode == dill.FILE_FMODE:
100
+ assert open(fname).read() == "hello world!"
101
+ assert f2mode == f1mode
102
+ assert f2tell == ftell
103
+ else:
104
+ raise RuntimeError("Unknown file mode '%s'" % fmode)
105
+
106
+ # append
107
+
108
+ trunc_file()
109
+
110
+ f = open(fname, "a")
111
+ f.write("hello")
112
+ f_dumped = dill.dumps(f, fmode=fmode)#, strictio=strictio)
113
+ f1mode = f.mode
114
+ ftell = f.tell()
115
+ f.close()
116
+ f2 = dill.loads(f_dumped)
117
+ f2mode = f2.mode
118
+ f2tell = f2.tell()
119
+ f2.write(" world!")
120
+ f2.close()
121
+
122
+ assert f2mode == f1mode
123
+ if fmode == dill.CONTENTS_FMODE:
124
+ assert open(fname).read() == "hello world!"
125
+ assert f2tell == ftell
126
+ elif fmode == dill.HANDLE_FMODE:
127
+ assert open(fname).read() == "hello world!"
128
+ assert f2tell == ftell
129
+ elif fmode == dill.FILE_FMODE:
130
+ assert open(fname).read() == "hello world!"
131
+ assert f2tell == ftell
132
+ else:
133
+ raise RuntimeError("Unknown file mode '%s'" % fmode)
134
+
135
+ # file exists, with different contents (smaller size)
136
+ # read
137
+
138
+ write_randomness()
139
+
140
+ f = open(fname, "r")
141
+ fstr = f.read()
142
+ f_dumped = dill.dumps(f, fmode=fmode)#, strictio=strictio)
143
+ f1mode = f.mode
144
+ ftell = f.tell()
145
+ f.close()
146
+ _flen = 150
147
+ _fstr = write_randomness(number=_flen)
148
+
149
+ if strictio: # throw error if ftell > EOF
150
+ assert throws(dill.loads, (f_dumped,), buffer_error)
151
+ else:
152
+ f2 = dill.loads(f_dumped)
153
+ assert f2.mode == f1mode
154
+ if fmode == dill.CONTENTS_FMODE:
155
+ assert f2.tell() == _flen
156
+ assert f2.read() == ""
157
+ f2.seek(0)
158
+ assert f2.read() == _fstr
159
+ assert f2.tell() == _flen # 150
160
+ elif fmode == dill.HANDLE_FMODE:
161
+ assert f2.tell() == 0
162
+ assert f2.read() == _fstr
163
+ assert f2.tell() == _flen # 150
164
+ elif fmode == dill.FILE_FMODE:
165
+ assert f2.tell() == ftell # 200
166
+ assert f2.read() == ""
167
+ f2.seek(0)
168
+ assert f2.read() == fstr
169
+ assert f2.tell() == ftell # 200
170
+ else:
171
+ raise RuntimeError("Unknown file mode '%s'" % fmode)
172
+ f2.close()
173
+
174
+ # write
175
+
176
+ write_randomness()
177
+
178
+ f = open(fname, "w")
179
+ f.write("hello")
180
+ f_dumped = dill.dumps(f, fmode=fmode)#, strictio=strictio)
181
+ f1mode = f.mode
182
+ ftell = f.tell()
183
+ f.close()
184
+ fstr = open(fname).read()
185
+
186
+ f = open(fname, "w")
187
+ f.write("h")
188
+ _ftell = f.tell()
189
+ f.close()
190
+
191
+ if strictio: # throw error if ftell > EOF
192
+ assert throws(dill.loads, (f_dumped,), buffer_error)
193
+ else:
194
+ f2 = dill.loads(f_dumped)
195
+ f2mode = f2.mode
196
+ f2tell = f2.tell()
197
+ f2.write(" world!")
198
+ f2.close()
199
+ if fmode == dill.CONTENTS_FMODE:
200
+ assert open(fname).read() == "h world!"
201
+ assert f2mode == f1mode
202
+ assert f2tell == _ftell
203
+ elif fmode == dill.HANDLE_FMODE:
204
+ assert open(fname).read() == " world!"
205
+ assert f2mode == f1mode
206
+ assert f2tell == 0
207
+ elif fmode == dill.FILE_FMODE:
208
+ assert open(fname).read() == "hello world!"
209
+ assert f2mode == f1mode
210
+ assert f2tell == ftell
211
+ else:
212
+ raise RuntimeError("Unknown file mode '%s'" % fmode)
213
+ f2.close()
214
+
215
+ # append
216
+
217
+ trunc_file()
218
+
219
+ f = open(fname, "a")
220
+ f.write("hello")
221
+ f_dumped = dill.dumps(f, fmode=fmode)#, strictio=strictio)
222
+ f1mode = f.mode
223
+ ftell = f.tell()
224
+ f.close()
225
+ fstr = open(fname).read()
226
+
227
+ f = open(fname, "w")
228
+ f.write("h")
229
+ _ftell = f.tell()
230
+ f.close()
231
+
232
+ if strictio: # throw error if ftell > EOF
233
+ assert throws(dill.loads, (f_dumped,), buffer_error)
234
+ else:
235
+ f2 = dill.loads(f_dumped)
236
+ f2mode = f2.mode
237
+ f2tell = f2.tell()
238
+ f2.write(" world!")
239
+ f2.close()
240
+ assert f2mode == f1mode
241
+ if fmode == dill.CONTENTS_FMODE:
242
+ # position of writes cannot be changed on some OSs
243
+ assert open(fname).read() == "h world!"
244
+ assert f2tell == _ftell
245
+ elif fmode == dill.HANDLE_FMODE:
246
+ assert open(fname).read() == "h world!"
247
+ assert f2tell == _ftell
248
+ elif fmode == dill.FILE_FMODE:
249
+ assert open(fname).read() == "hello world!"
250
+ assert f2tell == ftell
251
+ else:
252
+ raise RuntimeError("Unknown file mode '%s'" % fmode)
253
+ f2.close()
254
+
255
+ # file does not exist
256
+ # read
257
+
258
+ write_randomness()
259
+
260
+ f = open(fname, "r")
261
+ fstr = f.read()
262
+ f_dumped = dill.dumps(f, fmode=fmode)#, strictio=strictio)
263
+ f1mode = f.mode
264
+ ftell = f.tell()
265
+ f.close()
266
+
267
+ os.remove(fname)
268
+
269
+ if strictio: # throw error if file DNE
270
+ assert throws(dill.loads, (f_dumped,), dne_error)
271
+ else:
272
+ f2 = dill.loads(f_dumped)
273
+ assert f2.mode == f1mode
274
+ if fmode == dill.CONTENTS_FMODE:
275
+ # FIXME: this fails on systems where f2.tell() always returns 0
276
+ # assert f2.tell() == ftell # 200
277
+ assert f2.read() == ""
278
+ f2.seek(0)
279
+ assert f2.read() == ""
280
+ assert f2.tell() == 0
281
+ elif fmode == dill.FILE_FMODE:
282
+ assert f2.tell() == ftell # 200
283
+ assert f2.read() == ""
284
+ f2.seek(0)
285
+ assert f2.read() == fstr
286
+ assert f2.tell() == ftell # 200
287
+ elif fmode == dill.HANDLE_FMODE:
288
+ assert f2.tell() == 0
289
+ assert f2.read() == ""
290
+ assert f2.tell() == 0
291
+ else:
292
+ raise RuntimeError("Unknown file mode '%s'" % fmode)
293
+ f2.close()
294
+
295
+ # write
296
+
297
+ write_randomness()
298
+
299
+ f = open(fname, "w+")
300
+ f.write("hello")
301
+ f_dumped = dill.dumps(f, fmode=fmode)#, strictio=strictio)
302
+ ftell = f.tell()
303
+ f1mode = f.mode
304
+ f.close()
305
+
306
+ os.remove(fname)
307
+
308
+ if strictio: # throw error if file DNE
309
+ assert throws(dill.loads, (f_dumped,), dne_error)
310
+ else:
311
+ f2 = dill.loads(f_dumped)
312
+ f2mode = f2.mode
313
+ f2tell = f2.tell()
314
+ f2.write(" world!")
315
+ f2.close()
316
+ if fmode == dill.CONTENTS_FMODE:
317
+ assert open(fname).read() == " world!"
318
+ assert f2mode == 'w+'
319
+ assert f2tell == 0
320
+ elif fmode == dill.HANDLE_FMODE:
321
+ assert open(fname).read() == " world!"
322
+ assert f2mode == f1mode
323
+ assert f2tell == 0
324
+ elif fmode == dill.FILE_FMODE:
325
+ assert open(fname).read() == "hello world!"
326
+ assert f2mode == f1mode
327
+ assert f2tell == ftell
328
+ else:
329
+ raise RuntimeError("Unknown file mode '%s'" % fmode)
330
+
331
+ # append
332
+
333
+ trunc_file()
334
+
335
+ f = open(fname, "a")
336
+ f.write("hello")
337
+ f_dumped = dill.dumps(f, fmode=fmode)#, strictio=strictio)
338
+ ftell = f.tell()
339
+ f1mode = f.mode
340
+ f.close()
341
+
342
+ os.remove(fname)
343
+
344
+ if strictio: # throw error if file DNE
345
+ assert throws(dill.loads, (f_dumped,), dne_error)
346
+ else:
347
+ f2 = dill.loads(f_dumped)
348
+ f2mode = f2.mode
349
+ f2tell = f2.tell()
350
+ f2.write(" world!")
351
+ f2.close()
352
+ assert f2mode == f1mode
353
+ if fmode == dill.CONTENTS_FMODE:
354
+ assert open(fname).read() == " world!"
355
+ assert f2tell == 0
356
+ elif fmode == dill.HANDLE_FMODE:
357
+ assert open(fname).read() == " world!"
358
+ assert f2tell == 0
359
+ elif fmode == dill.FILE_FMODE:
360
+ assert open(fname).read() == "hello world!"
361
+ assert f2tell == ftell
362
+ else:
363
+ raise RuntimeError("Unknown file mode '%s'" % fmode)
364
+
365
+ # file exists, with different contents (larger size)
366
+ # read
367
+
368
+ write_randomness()
369
+
370
+ f = open(fname, "r")
371
+ fstr = f.read()
372
+ f_dumped = dill.dumps(f, fmode=fmode)#, strictio=strictio)
373
+ f1mode = f.mode
374
+ ftell = f.tell()
375
+ f.close()
376
+ _flen = 250
377
+ _fstr = write_randomness(number=_flen)
378
+
379
+ # XXX: no safe_file: no way to be 'safe'?
380
+
381
+ f2 = dill.loads(f_dumped)
382
+ assert f2.mode == f1mode
383
+ if fmode == dill.CONTENTS_FMODE:
384
+ assert f2.tell() == ftell # 200
385
+ assert f2.read() == _fstr[ftell:]
386
+ f2.seek(0)
387
+ assert f2.read() == _fstr
388
+ assert f2.tell() == _flen # 250
389
+ elif fmode == dill.HANDLE_FMODE:
390
+ assert f2.tell() == 0
391
+ assert f2.read() == _fstr
392
+ assert f2.tell() == _flen # 250
393
+ elif fmode == dill.FILE_FMODE:
394
+ assert f2.tell() == ftell # 200
395
+ assert f2.read() == ""
396
+ f2.seek(0)
397
+ assert f2.read() == fstr
398
+ assert f2.tell() == ftell # 200
399
+ else:
400
+ raise RuntimeError("Unknown file mode '%s'" % fmode)
401
+ f2.close() # XXX: other alternatives?
402
+
403
+ # write
404
+
405
+ f = open(fname, "w")
406
+ f.write("hello")
407
+ f_dumped = dill.dumps(f, fmode=fmode)#, strictio=strictio)
408
+ f1mode = f.mode
409
+ ftell = f.tell()
410
+
411
+ fstr = open(fname).read()
412
+
413
+ f.write(" and goodbye!")
414
+ _ftell = f.tell()
415
+ f.close()
416
+
417
+ # XXX: no safe_file: no way to be 'safe'?
418
+
419
+ f2 = dill.loads(f_dumped)
420
+ f2mode = f2.mode
421
+ f2tell = f2.tell()
422
+ f2.write(" world!")
423
+ f2.close()
424
+ if fmode == dill.CONTENTS_FMODE:
425
+ assert open(fname).read() == "hello world!odbye!"
426
+ assert f2mode == f1mode
427
+ assert f2tell == ftell
428
+ elif fmode == dill.HANDLE_FMODE:
429
+ assert open(fname).read() == " world!"
430
+ assert f2mode == f1mode
431
+ assert f2tell == 0
432
+ elif fmode == dill.FILE_FMODE:
433
+ assert open(fname).read() == "hello world!"
434
+ assert f2mode == f1mode
435
+ assert f2tell == ftell
436
+ else:
437
+ raise RuntimeError("Unknown file mode '%s'" % fmode)
438
+ f2.close()
439
+
440
+ # append
441
+
442
+ trunc_file()
443
+
444
+ f = open(fname, "a")
445
+ f.write("hello")
446
+ f_dumped = dill.dumps(f, fmode=fmode)#, strictio=strictio)
447
+ f1mode = f.mode
448
+ ftell = f.tell()
449
+ fstr = open(fname).read()
450
+
451
+ f.write(" and goodbye!")
452
+ _ftell = f.tell()
453
+ f.close()
454
+
455
+ # XXX: no safe_file: no way to be 'safe'?
456
+
457
+ f2 = dill.loads(f_dumped)
458
+ f2mode = f2.mode
459
+ f2tell = f2.tell()
460
+ f2.write(" world!")
461
+ f2.close()
462
+ assert f2mode == f1mode
463
+ if fmode == dill.CONTENTS_FMODE:
464
+ assert open(fname).read() == "hello and goodbye! world!"
465
+ assert f2tell == ftell
466
+ elif fmode == dill.HANDLE_FMODE:
467
+ assert open(fname).read() == "hello and goodbye! world!"
468
+ assert f2tell == _ftell
469
+ elif fmode == dill.FILE_FMODE:
470
+ assert open(fname).read() == "hello world!"
471
+ assert f2tell == ftell
472
+ else:
473
+ raise RuntimeError("Unknown file mode '%s'" % fmode)
474
+ f2.close()
475
+
476
+
477
+ def test_nostrictio_handlefmode():
478
+ bench(False, dill.HANDLE_FMODE, False)
479
+ teardown_module()
480
+
481
+
482
+ def test_nostrictio_filefmode():
483
+ bench(False, dill.FILE_FMODE, False)
484
+ teardown_module()
485
+
486
+
487
+ def test_nostrictio_contentsfmode():
488
+ bench(False, dill.CONTENTS_FMODE, True)
489
+ teardown_module()
490
+
491
+
492
+ #bench(True, dill.HANDLE_FMODE, False)
493
+ #bench(True, dill.FILE_FMODE, False)
494
+ #bench(True, dill.CONTENTS_FMODE, True)
495
+
496
+
497
+ if __name__ == '__main__':
498
+ test_nostrictio_handlefmode()
499
+ test_nostrictio_filefmode()
500
+ test_nostrictio_contentsfmode()
tool_server/.venv/lib/python3.12/site-packages/dill/tests/test_functions.py ADDED
@@ -0,0 +1,141 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python
2
+ #
3
+ # Author: Mike McKerns (mmckerns @caltech and @uqfoundation)
4
+ # Copyright (c) 2019-2025 The Uncertainty Quantification Foundation.
5
+ # License: 3-clause BSD. The full license text is available at:
6
+ # - https://github.com/uqfoundation/dill/blob/master/LICENSE
7
+
8
+ import functools
9
+ import dill
10
+ import sys
11
+ dill.settings['recurse'] = True
12
+
13
+
14
+ def function_a(a):
15
+ return a
16
+
17
+
18
+ def function_b(b, b1):
19
+ return b + b1
20
+
21
+
22
+ def function_c(c, c1=1):
23
+ return c + c1
24
+
25
+
26
+ def function_d(d, d1, d2=1):
27
+ """doc string"""
28
+ return d + d1 + d2
29
+
30
+ function_d.__module__ = 'a module'
31
+
32
+
33
+ exec('''
34
+ def function_e(e, *e1, e2=1, e3=2):
35
+ return e + sum(e1) + e2 + e3''')
36
+
37
+ globalvar = 0
38
+
39
+ @functools.lru_cache(None)
40
+ def function_with_cache(x):
41
+ global globalvar
42
+ globalvar += x
43
+ return globalvar
44
+
45
+
46
+ def function_with_unassigned_variable():
47
+ if False:
48
+ value = None
49
+ return (lambda: value)
50
+
51
+
52
+ def test_issue_510():
53
+ # A very bizzare use of functions and methods that pickle doesn't get
54
+ # correctly for odd reasons.
55
+ class Foo:
56
+ def __init__(self):
57
+ def f2(self):
58
+ return self
59
+ self.f2 = f2.__get__(self)
60
+
61
+ import dill, pickletools
62
+ f = Foo()
63
+ f1 = dill.copy(f)
64
+ assert f1.f2() is f1
65
+
66
+
67
+ def test_functions():
68
+ dumped_func_a = dill.dumps(function_a)
69
+ assert dill.loads(dumped_func_a)(0) == 0
70
+
71
+ dumped_func_b = dill.dumps(function_b)
72
+ assert dill.loads(dumped_func_b)(1,2) == 3
73
+
74
+ dumped_func_c = dill.dumps(function_c)
75
+ assert dill.loads(dumped_func_c)(1) == 2
76
+ assert dill.loads(dumped_func_c)(1, 2) == 3
77
+
78
+ dumped_func_d = dill.dumps(function_d)
79
+ assert dill.loads(dumped_func_d).__doc__ == function_d.__doc__
80
+ assert dill.loads(dumped_func_d).__module__ == function_d.__module__
81
+ assert dill.loads(dumped_func_d)(1, 2) == 4
82
+ assert dill.loads(dumped_func_d)(1, 2, 3) == 6
83
+ assert dill.loads(dumped_func_d)(1, 2, d2=3) == 6
84
+
85
+ function_with_cache(1)
86
+ globalvar = 0
87
+ dumped_func_cache = dill.dumps(function_with_cache)
88
+ assert function_with_cache(2) == 3
89
+ assert function_with_cache(1) == 1
90
+ assert function_with_cache(3) == 6
91
+ assert function_with_cache(2) == 3
92
+
93
+ empty_cell = function_with_unassigned_variable()
94
+ cell_copy = dill.loads(dill.dumps(empty_cell))
95
+ assert 'empty' in str(cell_copy.__closure__[0])
96
+ try:
97
+ cell_copy()
98
+ except Exception:
99
+ # this is good
100
+ pass
101
+ else:
102
+ raise AssertionError('cell_copy() did not read an empty cell')
103
+
104
+ exec('''
105
+ dumped_func_e = dill.dumps(function_e)
106
+ assert dill.loads(dumped_func_e)(1, 2) == 6
107
+ assert dill.loads(dumped_func_e)(1, 2, 3) == 9
108
+ assert dill.loads(dumped_func_e)(1, 2, e2=3) == 8
109
+ assert dill.loads(dumped_func_e)(1, 2, e2=3, e3=4) == 10
110
+ assert dill.loads(dumped_func_e)(1, 2, 3, e2=4) == 12
111
+ assert dill.loads(dumped_func_e)(1, 2, 3, e2=4, e3=5) == 15''')
112
+
113
+ def test_code_object():
114
+ import warnings
115
+ from dill._dill import ALL_CODE_PARAMS, CODE_PARAMS, CODE_VERSION, _create_code
116
+ code = function_c.__code__
117
+ warnings.filterwarnings('ignore', category=DeprecationWarning) # issue 597
118
+ LNOTAB = getattr(code, 'co_lnotab', b'')
119
+ if warnings.filters: del warnings.filters[0]
120
+ fields = {f: getattr(code, 'co_'+f) for f in CODE_PARAMS}
121
+ fields.setdefault('posonlyargcount', 0) # python >= 3.8
122
+ fields.setdefault('lnotab', LNOTAB) # python <= 3.9
123
+ fields.setdefault('linetable', b'') # python >= 3.10
124
+ fields.setdefault('qualname', fields['name']) # python >= 3.11
125
+ fields.setdefault('exceptiontable', b'') # python >= 3.11
126
+ fields.setdefault('endlinetable', None) # python == 3.11a
127
+ fields.setdefault('columntable', None) # python == 3.11a
128
+
129
+ for version, _, params in ALL_CODE_PARAMS:
130
+ args = tuple(fields[p] for p in params.split())
131
+ try:
132
+ _create_code(*args)
133
+ if version >= (3,10):
134
+ _create_code(fields['lnotab'], *args)
135
+ except Exception as error:
136
+ raise Exception("failed to construct code object with format version {}".format(version)) from error
137
+
138
+ if __name__ == '__main__':
139
+ test_functions()
140
+ test_issue_510()
141
+ test_code_object()
tool_server/.venv/lib/python3.12/site-packages/dill/tests/test_functors.py ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ import functools
10
+ import dill
11
+ dill.settings['recurse'] = True
12
+
13
+
14
+ def f(a, b, c): # without keywords
15
+ pass
16
+
17
+
18
+ def g(a, b, c=2): # with keywords
19
+ pass
20
+
21
+
22
+ def h(a=1, b=2, c=3): # without args
23
+ pass
24
+
25
+
26
+ def test_functools():
27
+ fp = functools.partial(f, 1, 2)
28
+ gp = functools.partial(g, 1, c=2)
29
+ hp = functools.partial(h, 1, c=2)
30
+ bp = functools.partial(int, base=2)
31
+
32
+ assert dill.pickles(fp, safe=True)
33
+ assert dill.pickles(gp, safe=True)
34
+ assert dill.pickles(hp, safe=True)
35
+ assert dill.pickles(bp, safe=True)
36
+
37
+
38
+ if __name__ == '__main__':
39
+ test_functools()
tool_server/.venv/lib/python3.12/site-packages/dill/tests/test_logger.py ADDED
@@ -0,0 +1,70 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python
2
+
3
+ # Author: Leonardo Gama (@leogama)
4
+ # Copyright (c) 2022-2025 The Uncertainty Quantification Foundation.
5
+ # License: 3-clause BSD. The full license text is available at:
6
+ # - https://github.com/uqfoundation/dill/blob/master/LICENSE
7
+
8
+ import logging
9
+ import re
10
+ import tempfile
11
+
12
+ import dill
13
+ from dill import detect
14
+ from dill.logger import stderr_handler, adapter as logger
15
+
16
+ try:
17
+ from StringIO import StringIO
18
+ except ImportError:
19
+ from io import StringIO
20
+
21
+ test_obj = {'a': (1, 2), 'b': object(), 'f': lambda x: x**2, 'big': list(range(10))}
22
+
23
+ def test_logging(should_trace):
24
+ buffer = StringIO()
25
+ handler = logging.StreamHandler(buffer)
26
+ logger.addHandler(handler)
27
+ try:
28
+ dill.dumps(test_obj)
29
+ if should_trace:
30
+ regex = re.compile(r'(\S*┬ \w.*[^)]' # begin pickling object
31
+ r'|│*└ # \w.* \[\d+ (\wi)?B])' # object written (with size)
32
+ )
33
+ for line in buffer.getvalue().splitlines():
34
+ assert regex.fullmatch(line)
35
+ return buffer.getvalue()
36
+ else:
37
+ assert buffer.getvalue() == ""
38
+ finally:
39
+ logger.removeHandler(handler)
40
+ buffer.close()
41
+
42
+ def test_trace_to_file(stream_trace):
43
+ file = tempfile.NamedTemporaryFile(mode='r')
44
+ with detect.trace(file.name, mode='w'):
45
+ dill.dumps(test_obj)
46
+ file_trace = file.read()
47
+ file.close()
48
+ # Apparently, objects can change location in memory...
49
+ reghex = re.compile(r'0x[0-9A-Za-z]+')
50
+ file_trace, stream_trace = reghex.sub('0x', file_trace), reghex.sub('0x', stream_trace)
51
+ # PyPy prints dictionary contents with repr(dict)...
52
+ regdict = re.compile(r'(dict\.__repr__ of ).*')
53
+ file_trace, stream_trace = regdict.sub(r'\1{}>', file_trace), regdict.sub(r'\1{}>', stream_trace)
54
+ assert file_trace == stream_trace
55
+
56
+ if __name__ == '__main__':
57
+ logger.removeHandler(stderr_handler)
58
+ test_logging(should_trace=False)
59
+ detect.trace(True)
60
+ test_logging(should_trace=True)
61
+ detect.trace(False)
62
+ test_logging(should_trace=False)
63
+
64
+ loglevel = logging.ERROR
65
+ logger.setLevel(loglevel)
66
+ with detect.trace():
67
+ stream_trace = test_logging(should_trace=True)
68
+ test_logging(should_trace=False)
69
+ assert logger.getEffectiveLevel() == loglevel
70
+ test_trace_to_file(stream_trace)
tool_server/.venv/lib/python3.12/site-packages/dill/tests/test_mixins.py ADDED
@@ -0,0 +1,121 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ import dill
10
+ dill.settings['recurse'] = True
11
+
12
+
13
+ def wtf(x,y,z):
14
+ def zzz():
15
+ return x
16
+ def yyy():
17
+ return y
18
+ def xxx():
19
+ return z
20
+ return zzz,yyy
21
+
22
+
23
+ def quad(a=1, b=1, c=0):
24
+ inverted = [False]
25
+ def invert():
26
+ inverted[0] = not inverted[0]
27
+ def dec(f):
28
+ def func(*args, **kwds):
29
+ x = f(*args, **kwds)
30
+ if inverted[0]: x = -x
31
+ return a*x**2 + b*x + c
32
+ func.__wrapped__ = f
33
+ func.invert = invert
34
+ func.inverted = inverted
35
+ return func
36
+ return dec
37
+
38
+
39
+ @quad(a=0,b=2)
40
+ def double_add(*args):
41
+ return sum(args)
42
+
43
+
44
+ fx = sum([1,2,3])
45
+
46
+
47
+ ### to make it interesting...
48
+ def quad_factory(a=1,b=1,c=0):
49
+ def dec(f):
50
+ def func(*args,**kwds):
51
+ fx = f(*args,**kwds)
52
+ return a*fx**2 + b*fx + c
53
+ return func
54
+ return dec
55
+
56
+
57
+ @quad_factory(a=0,b=4,c=0)
58
+ def quadish(x):
59
+ return x+1
60
+
61
+
62
+ quadratic = quad_factory()
63
+
64
+
65
+ def doubler(f):
66
+ def inner(*args, **kwds):
67
+ fx = f(*args, **kwds)
68
+ return 2*fx
69
+ return inner
70
+
71
+
72
+ @doubler
73
+ def quadruple(x):
74
+ return 2*x
75
+
76
+
77
+ def test_mixins():
78
+ # test mixins
79
+ assert double_add(1,2,3) == 2*fx
80
+ double_add.invert()
81
+ assert double_add(1,2,3) == -2*fx
82
+
83
+ _d = dill.copy(double_add)
84
+ assert _d(1,2,3) == -2*fx
85
+ #_d.invert() #FIXME: fails seemingly randomly
86
+ #assert _d(1,2,3) == 2*fx
87
+
88
+ assert _d.__wrapped__(1,2,3) == fx
89
+
90
+ # XXX: issue or feature? in python3.4, inverted is linked through copy
91
+ if not double_add.inverted[0]:
92
+ double_add.invert()
93
+
94
+ # test some stuff from source and pointers
95
+ ds = dill.source
96
+ dd = dill.detect
97
+ assert ds.getsource(dd.freevars(quadish)['f']) == '@quad_factory(a=0,b=4,c=0)\ndef quadish(x):\n return x+1\n'
98
+ assert ds.getsource(dd.freevars(quadruple)['f']) == '@doubler\ndef quadruple(x):\n return 2*x\n'
99
+ assert ds.importable(quadish, source=False) == 'from %s import quadish\n' % __name__
100
+ assert ds.importable(quadruple, source=False) == 'from %s import quadruple\n' % __name__
101
+ assert ds.importable(quadratic, source=False) == 'from %s import quadratic\n' % __name__
102
+ assert ds.importable(double_add, source=False) == 'from %s import double_add\n' % __name__
103
+ assert ds.importable(quadruple, source=True) == 'def doubler(f):\n def inner(*args, **kwds):\n fx = f(*args, **kwds)\n return 2*fx\n return inner\n\n@doubler\ndef quadruple(x):\n return 2*x\n'
104
+ #***** #FIXME: this needs work
105
+ result = ds.importable(quadish, source=True)
106
+ a,b,c,_,result = result.split('\n',4)
107
+ assert result == 'def quad_factory(a=1,b=1,c=0):\n def dec(f):\n def func(*args,**kwds):\n fx = f(*args,**kwds)\n return a*fx**2 + b*fx + c\n return func\n return dec\n\n@quad_factory(a=0,b=4,c=0)\ndef quadish(x):\n return x+1\n'
108
+ assert set([a,b,c]) == set(['a = 0', 'c = 0', 'b = 4'])
109
+ result = ds.importable(quadratic, source=True)
110
+ a,b,c,result = result.split('\n',3)
111
+ assert result == '\ndef dec(f):\n def func(*args,**kwds):\n fx = f(*args,**kwds)\n return a*fx**2 + b*fx + c\n return func\n'
112
+ assert set([a,b,c]) == set(['a = 1', 'c = 0', 'b = 1'])
113
+ result = ds.importable(double_add, source=True)
114
+ a,b,c,d,_,result = result.split('\n',5)
115
+ assert result == 'def quad(a=1, b=1, c=0):\n inverted = [False]\n def invert():\n inverted[0] = not inverted[0]\n def dec(f):\n def func(*args, **kwds):\n x = f(*args, **kwds)\n if inverted[0]: x = -x\n return a*x**2 + b*x + c\n func.__wrapped__ = f\n func.invert = invert\n func.inverted = inverted\n return func\n return dec\n\n@quad(a=0,b=2)\ndef double_add(*args):\n return sum(args)\n'
116
+ assert set([a,b,c,d]) == set(['a = 0', 'c = 0', 'b = 2', 'inverted = [True]'])
117
+ #*****
118
+
119
+
120
+ if __name__ == '__main__':
121
+ test_mixins()
tool_server/.venv/lib/python3.12/site-packages/diskcache/__pycache__/djangocache.cpython-312.pyc ADDED
Binary file (18.7 kB). View file
 
tool_server/.venv/lib/python3.12/site-packages/diskcache/__pycache__/fanout.cpython-312.pyc ADDED
Binary file (30.2 kB). View file
 
tool_server/.venv/lib/python3.12/site-packages/diskcache/__pycache__/persistent.cpython-312.pyc ADDED
Binary file (43.3 kB). View file
 
tool_server/.venv/lib/python3.12/site-packages/diskcache/__pycache__/recipes.cpython-312.pyc ADDED
Binary file (20.1 kB). View file