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

Add files using upload-large-folder tool

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. .gitattributes +1 -0
  2. tool_server/.venv/lib/python3.12/site-packages/dill/__pycache__/__diff.cpython-312.pyc +0 -0
  3. tool_server/.venv/lib/python3.12/site-packages/dill/__pycache__/__info__.cpython-312.pyc +0 -0
  4. tool_server/.venv/lib/python3.12/site-packages/dill/__pycache__/__init__.cpython-312.pyc +0 -0
  5. tool_server/.venv/lib/python3.12/site-packages/dill/__pycache__/_dill.cpython-312.pyc +3 -0
  6. tool_server/.venv/lib/python3.12/site-packages/dill/__pycache__/_objects.cpython-312.pyc +0 -0
  7. tool_server/.venv/lib/python3.12/site-packages/dill/__pycache__/_shims.cpython-312.pyc +0 -0
  8. tool_server/.venv/lib/python3.12/site-packages/dill/__pycache__/detect.cpython-312.pyc +0 -0
  9. tool_server/.venv/lib/python3.12/site-packages/dill/__pycache__/logger.cpython-312.pyc +0 -0
  10. tool_server/.venv/lib/python3.12/site-packages/dill/__pycache__/objtypes.cpython-312.pyc +0 -0
  11. tool_server/.venv/lib/python3.12/site-packages/dill/__pycache__/pointers.cpython-312.pyc +0 -0
  12. tool_server/.venv/lib/python3.12/site-packages/dill/__pycache__/session.cpython-312.pyc +0 -0
  13. tool_server/.venv/lib/python3.12/site-packages/dill/__pycache__/settings.cpython-312.pyc +0 -0
  14. tool_server/.venv/lib/python3.12/site-packages/dill/__pycache__/source.cpython-312.pyc +0 -0
  15. tool_server/.venv/lib/python3.12/site-packages/dill/__pycache__/temp.cpython-312.pyc +0 -0
  16. tool_server/.venv/lib/python3.12/site-packages/dill/tests/__pycache__/__init__.cpython-312.pyc +0 -0
  17. tool_server/.venv/lib/python3.12/site-packages/dill/tests/__pycache__/__main__.cpython-312.pyc +0 -0
  18. tool_server/.venv/lib/python3.12/site-packages/dill/tests/__pycache__/test_abc.cpython-312.pyc +0 -0
  19. tool_server/.venv/lib/python3.12/site-packages/dill/tests/__pycache__/test_check.cpython-312.pyc +0 -0
  20. tool_server/.venv/lib/python3.12/site-packages/dill/tests/__pycache__/test_classdef.cpython-312.pyc +0 -0
  21. tool_server/.venv/lib/python3.12/site-packages/dill/tests/__pycache__/test_dataclasses.cpython-312.pyc +0 -0
  22. tool_server/.venv/lib/python3.12/site-packages/dill/tests/__pycache__/test_detect.cpython-312.pyc +0 -0
  23. tool_server/.venv/lib/python3.12/site-packages/dill/tests/__pycache__/test_dictviews.cpython-312.pyc +0 -0
  24. tool_server/.venv/lib/python3.12/site-packages/dill/tests/__pycache__/test_diff.cpython-312.pyc +0 -0
  25. tool_server/.venv/lib/python3.12/site-packages/dill/tests/__pycache__/test_extendpickle.cpython-312.pyc +0 -0
  26. tool_server/.venv/lib/python3.12/site-packages/dill/tests/__pycache__/test_fglobals.cpython-312.pyc +0 -0
  27. tool_server/.venv/lib/python3.12/site-packages/dill/tests/__pycache__/test_file.cpython-312.pyc +0 -0
  28. tool_server/.venv/lib/python3.12/site-packages/dill/tests/__pycache__/test_functions.cpython-312.pyc +0 -0
  29. tool_server/.venv/lib/python3.12/site-packages/dill/tests/__pycache__/test_functors.cpython-312.pyc +0 -0
  30. tool_server/.venv/lib/python3.12/site-packages/dill/tests/__pycache__/test_logger.cpython-312.pyc +0 -0
  31. tool_server/.venv/lib/python3.12/site-packages/dill/tests/__pycache__/test_mixins.cpython-312.pyc +0 -0
  32. tool_server/.venv/lib/python3.12/site-packages/dill/tests/__pycache__/test_module.cpython-312.pyc +0 -0
  33. tool_server/.venv/lib/python3.12/site-packages/dill/tests/__pycache__/test_moduledict.cpython-312.pyc +0 -0
  34. tool_server/.venv/lib/python3.12/site-packages/dill/tests/__pycache__/test_nested.cpython-312.pyc +0 -0
  35. tool_server/.venv/lib/python3.12/site-packages/dill/tests/__pycache__/test_objects.cpython-312.pyc +0 -0
  36. tool_server/.venv/lib/python3.12/site-packages/dill/tests/test_module.py +84 -0
  37. tool_server/.venv/lib/python3.12/site-packages/dill/tests/test_moduledict.py +54 -0
  38. tool_server/.venv/lib/python3.12/site-packages/dill/tests/test_nested.py +135 -0
  39. tool_server/.venv/lib/python3.12/site-packages/dill/tests/test_objects.py +63 -0
  40. tool_server/.venv/lib/python3.12/site-packages/dill/tests/test_properties.py +62 -0
  41. tool_server/.venv/lib/python3.12/site-packages/dill/tests/test_pycapsule.py +45 -0
  42. tool_server/.venv/lib/python3.12/site-packages/dill/tests/test_recursive.py +177 -0
  43. tool_server/.venv/lib/python3.12/site-packages/dill/tests/test_registered.py +64 -0
  44. tool_server/.venv/lib/python3.12/site-packages/dill/tests/test_restricted.py +27 -0
  45. tool_server/.venv/lib/python3.12/site-packages/dill/tests/test_selected.py +126 -0
  46. tool_server/.venv/lib/python3.12/site-packages/dill/tests/test_session.py +280 -0
  47. tool_server/.venv/lib/python3.12/site-packages/dill/tests/test_source.py +173 -0
  48. tool_server/.venv/lib/python3.12/site-packages/dill/tests/test_sources.py +190 -0
  49. tool_server/.venv/lib/python3.12/site-packages/dill/tests/test_temp.py +103 -0
  50. tool_server/.venv/lib/python3.12/site-packages/dill/tests/test_threads.py +46 -0
.gitattributes CHANGED
@@ -4082,3 +4082,4 @@ tool_server/.venv/lib/python3.12/site-packages/nvidia/cusolver/lib/libcusolver.s
4082
  tool_server/.venv/lib/python3.12/site-packages/nvidia/cusolver/lib/libcusolverMg.so.11 filter=lfs diff=lfs merge=lfs -text
4083
  tool_server/.venv/lib/python3.12/site-packages/httptools/parser/parser.cpython-312-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
4084
  tool_server/.venv/lib/python3.12/site-packages/httptools/parser/url_parser.cpython-312-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
 
 
4082
  tool_server/.venv/lib/python3.12/site-packages/nvidia/cusolver/lib/libcusolverMg.so.11 filter=lfs diff=lfs merge=lfs -text
4083
  tool_server/.venv/lib/python3.12/site-packages/httptools/parser/parser.cpython-312-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
4084
  tool_server/.venv/lib/python3.12/site-packages/httptools/parser/url_parser.cpython-312-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
4085
+ tool_server/.venv/lib/python3.12/site-packages/dill/__pycache__/_dill.cpython-312.pyc filter=lfs diff=lfs merge=lfs -text
tool_server/.venv/lib/python3.12/site-packages/dill/__pycache__/__diff.cpython-312.pyc ADDED
Binary file (8.98 kB). View file
 
tool_server/.venv/lib/python3.12/site-packages/dill/__pycache__/__info__.cpython-312.pyc ADDED
Binary file (10.7 kB). View file
 
tool_server/.venv/lib/python3.12/site-packages/dill/__pycache__/__init__.cpython-312.pyc ADDED
Binary file (4.71 kB). View file
 
tool_server/.venv/lib/python3.12/site-packages/dill/__pycache__/_dill.cpython-312.pyc ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:073c8c67521dd43059935fb5278ddf889af845e97e8e8f4cc40a1704102c7123
3
+ size 103684
tool_server/.venv/lib/python3.12/site-packages/dill/__pycache__/_objects.cpython-312.pyc ADDED
Binary file (25.9 kB). View file
 
tool_server/.venv/lib/python3.12/site-packages/dill/__pycache__/_shims.cpython-312.pyc ADDED
Binary file (7.67 kB). View file
 
tool_server/.venv/lib/python3.12/site-packages/dill/__pycache__/detect.cpython-312.pyc ADDED
Binary file (13.4 kB). View file
 
tool_server/.venv/lib/python3.12/site-packages/dill/__pycache__/logger.cpython-312.pyc ADDED
Binary file (12.6 kB). View file
 
tool_server/.venv/lib/python3.12/site-packages/dill/__pycache__/objtypes.cpython-312.pyc ADDED
Binary file (648 Bytes). View file
 
tool_server/.venv/lib/python3.12/site-packages/dill/__pycache__/pointers.cpython-312.pyc ADDED
Binary file (4.95 kB). View file
 
tool_server/.venv/lib/python3.12/site-packages/dill/__pycache__/session.cpython-312.pyc ADDED
Binary file (26.4 kB). View file
 
tool_server/.venv/lib/python3.12/site-packages/dill/__pycache__/settings.cpython-312.pyc ADDED
Binary file (376 Bytes). View file
 
tool_server/.venv/lib/python3.12/site-packages/dill/__pycache__/source.cpython-312.pyc ADDED
Binary file (41.2 kB). View file
 
tool_server/.venv/lib/python3.12/site-packages/dill/__pycache__/temp.cpython-312.pyc ADDED
Binary file (9.46 kB). View file
 
tool_server/.venv/lib/python3.12/site-packages/dill/tests/__pycache__/__init__.cpython-312.pyc ADDED
Binary file (388 Bytes). View file
 
tool_server/.venv/lib/python3.12/site-packages/dill/tests/__pycache__/__main__.cpython-312.pyc ADDED
Binary file (1.31 kB). View file
 
tool_server/.venv/lib/python3.12/site-packages/dill/tests/__pycache__/test_abc.cpython-312.pyc ADDED
Binary file (7.93 kB). View file
 
tool_server/.venv/lib/python3.12/site-packages/dill/tests/__pycache__/test_check.cpython-312.pyc ADDED
Binary file (2.12 kB). View file
 
tool_server/.venv/lib/python3.12/site-packages/dill/tests/__pycache__/test_classdef.cpython-312.pyc ADDED
Binary file (19.6 kB). View file
 
tool_server/.venv/lib/python3.12/site-packages/dill/tests/__pycache__/test_dataclasses.cpython-312.pyc ADDED
Binary file (1.57 kB). View file
 
tool_server/.venv/lib/python3.12/site-packages/dill/tests/__pycache__/test_detect.cpython-312.pyc ADDED
Binary file (7.66 kB). View file
 
tool_server/.venv/lib/python3.12/site-packages/dill/tests/__pycache__/test_dictviews.cpython-312.pyc ADDED
Binary file (2.17 kB). View file
 
tool_server/.venv/lib/python3.12/site-packages/dill/tests/__pycache__/test_diff.cpython-312.pyc ADDED
Binary file (3.51 kB). View file
 
tool_server/.venv/lib/python3.12/site-packages/dill/tests/__pycache__/test_extendpickle.cpython-312.pyc ADDED
Binary file (2.19 kB). View file
 
tool_server/.venv/lib/python3.12/site-packages/dill/tests/__pycache__/test_fglobals.cpython-312.pyc ADDED
Binary file (2.9 kB). View file
 
tool_server/.venv/lib/python3.12/site-packages/dill/tests/__pycache__/test_file.cpython-312.pyc ADDED
Binary file (19.3 kB). View file
 
tool_server/.venv/lib/python3.12/site-packages/dill/tests/__pycache__/test_functions.cpython-312.pyc ADDED
Binary file (7.11 kB). View file
 
tool_server/.venv/lib/python3.12/site-packages/dill/tests/__pycache__/test_functors.cpython-312.pyc ADDED
Binary file (1.46 kB). View file
 
tool_server/.venv/lib/python3.12/site-packages/dill/tests/__pycache__/test_logger.cpython-312.pyc ADDED
Binary file (3.67 kB). View file
 
tool_server/.venv/lib/python3.12/site-packages/dill/tests/__pycache__/test_mixins.cpython-312.pyc ADDED
Binary file (6.91 kB). View file
 
tool_server/.venv/lib/python3.12/site-packages/dill/tests/__pycache__/test_module.cpython-312.pyc ADDED
Binary file (3.18 kB). View file
 
tool_server/.venv/lib/python3.12/site-packages/dill/tests/__pycache__/test_moduledict.cpython-312.pyc ADDED
Binary file (2.11 kB). View file
 
tool_server/.venv/lib/python3.12/site-packages/dill/tests/__pycache__/test_nested.cpython-312.pyc ADDED
Binary file (6.29 kB). View file
 
tool_server/.venv/lib/python3.12/site-packages/dill/tests/__pycache__/test_objects.cpython-312.pyc ADDED
Binary file (2.68 kB). View file
 
tool_server/.venv/lib/python3.12/site-packages/dill/tests/test_module.py ADDED
@@ -0,0 +1,84 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 sys
10
+ import dill
11
+ import test_mixins as module
12
+ from importlib import reload
13
+ dill.settings['recurse'] = True
14
+
15
+ cached = (module.__cached__ if hasattr(module, "__cached__")
16
+ else module.__file__.split(".", 1)[0] + ".pyc")
17
+
18
+ module.a = 1234
19
+
20
+ pik_mod = dill.dumps(module)
21
+
22
+ module.a = 0
23
+
24
+ # remove module
25
+ del sys.modules[module.__name__]
26
+ del module
27
+
28
+ module = dill.loads(pik_mod)
29
+ def test_attributes():
30
+ #assert hasattr(module, "a") and module.a == 1234 #FIXME: -m dill.tests
31
+ assert module.double_add(1, 2, 3) == 2 * module.fx
32
+
33
+ # Restart, and test use_diff
34
+
35
+ reload(module)
36
+
37
+ try:
38
+ dill.use_diff()
39
+
40
+ module.a = 1234
41
+
42
+ pik_mod = dill.dumps(module)
43
+
44
+ module.a = 0
45
+
46
+ # remove module
47
+ del sys.modules[module.__name__]
48
+ del module
49
+
50
+ module = dill.loads(pik_mod)
51
+ def test_diff_attributes():
52
+ assert hasattr(module, "a") and module.a == 1234
53
+ assert module.double_add(1, 2, 3) == 2 * module.fx
54
+
55
+ except AttributeError:
56
+ def test_diff_attributes():
57
+ pass
58
+
59
+ # clean up
60
+ import os
61
+ if os.path.exists(cached):
62
+ os.remove(cached)
63
+ pycache = os.path.join(os.path.dirname(module.__file__), "__pycache__")
64
+ if os.path.exists(pycache) and not os.listdir(pycache):
65
+ os.removedirs(pycache)
66
+
67
+
68
+ # test when module is None
69
+ import math
70
+
71
+ def get_lambda(str, **kwarg):
72
+ return eval(str, kwarg, None)
73
+
74
+ obj = get_lambda('lambda x: math.exp(x)', math=math)
75
+
76
+ def test_module_is_none():
77
+ assert obj.__module__ is None
78
+ assert dill.copy(obj)(3) == obj(3)
79
+
80
+
81
+ if __name__ == '__main__':
82
+ test_attributes()
83
+ test_diff_attributes()
84
+ test_module_is_none()
tool_server/.venv/lib/python3.12/site-packages/dill/tests/test_moduledict.py ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ def f(func):
13
+ def w(*args):
14
+ return f(*args)
15
+ return w
16
+
17
+ @f
18
+ def f2(): pass
19
+
20
+ # check when __main__ and on import
21
+ def test_decorated():
22
+ assert dill.pickles(f2)
23
+
24
+
25
+ import doctest
26
+ import logging
27
+ logging.basicConfig(level=logging.DEBUG)
28
+
29
+ class SomeUnreferencedUnpicklableClass(object):
30
+ def __reduce__(self):
31
+ raise Exception
32
+
33
+ unpicklable = SomeUnreferencedUnpicklableClass()
34
+
35
+ # This works fine outside of Doctest:
36
+ def test_normal():
37
+ serialized = dill.dumps(lambda x: x)
38
+
39
+ # should not try to pickle unpicklable object in __globals__
40
+ def tests():
41
+ """
42
+ >>> serialized = dill.dumps(lambda x: x)
43
+ """
44
+ return
45
+
46
+ #print("\n\nRunning Doctest:")
47
+ def test_doctest():
48
+ doctest.testmod()
49
+
50
+
51
+ if __name__ == '__main__':
52
+ test_decorated()
53
+ test_normal()
54
+ test_doctest()
tool_server/.venv/lib/python3.12/site-packages/dill/tests/test_nested.py ADDED
@@ -0,0 +1,135 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ test dill's ability to handle nested functions
10
+ """
11
+
12
+ import os
13
+ import math
14
+
15
+ import dill as pickle
16
+ pickle.settings['recurse'] = True
17
+
18
+
19
+ # the nested function: pickle should fail here, but dill is ok.
20
+ def adder(augend):
21
+ zero = [0]
22
+
23
+ def inner(addend):
24
+ return addend + augend + zero[0]
25
+ return inner
26
+
27
+
28
+ # rewrite the nested function using a class: standard pickle should work here.
29
+ class cadder(object):
30
+ def __init__(self, augend):
31
+ self.augend = augend
32
+ self.zero = [0]
33
+
34
+ def __call__(self, addend):
35
+ return addend + self.augend + self.zero[0]
36
+
37
+
38
+ # rewrite again, but as an old-style class
39
+ class c2adder:
40
+ def __init__(self, augend):
41
+ self.augend = augend
42
+ self.zero = [0]
43
+
44
+ def __call__(self, addend):
45
+ return addend + self.augend + self.zero[0]
46
+
47
+
48
+ # some basic class stuff
49
+ class basic(object):
50
+ pass
51
+
52
+
53
+ class basic2:
54
+ pass
55
+
56
+
57
+ x = 5
58
+ y = 1
59
+
60
+
61
+ def test_basic():
62
+ a = [0, 1, 2]
63
+ pa = pickle.dumps(a)
64
+ pmath = pickle.dumps(math) #XXX: FAILS in pickle
65
+ pmap = pickle.dumps(map)
66
+ # ...
67
+ la = pickle.loads(pa)
68
+ lmath = pickle.loads(pmath)
69
+ lmap = pickle.loads(pmap)
70
+ assert list(map(math.sin, a)) == list(lmap(lmath.sin, la))
71
+
72
+
73
+ def test_basic_class():
74
+ pbasic2 = pickle.dumps(basic2)
75
+ _pbasic2 = pickle.loads(pbasic2)()
76
+ pbasic = pickle.dumps(basic)
77
+ _pbasic = pickle.loads(pbasic)()
78
+
79
+
80
+ def test_c2adder():
81
+ pc2adder = pickle.dumps(c2adder)
82
+ pc2add5 = pickle.loads(pc2adder)(x)
83
+ assert pc2add5(y) == x+y
84
+
85
+
86
+ def test_pickled_cadder():
87
+ pcadder = pickle.dumps(cadder)
88
+ pcadd5 = pickle.loads(pcadder)(x)
89
+ assert pcadd5(y) == x+y
90
+
91
+
92
+ def test_raw_adder_and_inner():
93
+ add5 = adder(x)
94
+ assert add5(y) == x+y
95
+
96
+
97
+ def test_pickled_adder():
98
+ padder = pickle.dumps(adder)
99
+ padd5 = pickle.loads(padder)(x)
100
+ assert padd5(y) == x+y
101
+
102
+
103
+ def test_pickled_inner():
104
+ add5 = adder(x)
105
+ pinner = pickle.dumps(add5) #XXX: FAILS in pickle
106
+ p5add = pickle.loads(pinner)
107
+ assert p5add(y) == x+y
108
+
109
+
110
+ def test_moduledict_where_not_main():
111
+ try:
112
+ from . import test_moduledict
113
+ except ImportError:
114
+ import test_moduledict
115
+ name = 'test_moduledict.py'
116
+ if os.path.exists(name) and os.path.exists(name+'c'):
117
+ os.remove(name+'c')
118
+
119
+ if os.path.exists(name) and hasattr(test_moduledict, "__cached__") \
120
+ and os.path.exists(test_moduledict.__cached__):
121
+ os.remove(getattr(test_moduledict, "__cached__"))
122
+
123
+ if os.path.exists("__pycache__") and not os.listdir("__pycache__"):
124
+ os.removedirs("__pycache__")
125
+
126
+
127
+ if __name__ == '__main__':
128
+ test_basic()
129
+ test_basic_class()
130
+ test_c2adder()
131
+ test_pickled_cadder()
132
+ test_raw_adder_and_inner()
133
+ test_pickled_adder()
134
+ test_pickled_inner()
135
+ test_moduledict_where_not_main()
tool_server/.venv/lib/python3.12/site-packages/dill/tests/test_objects.py ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ demonstrate dill's ability to pickle different python types
10
+ test pickling of all Python Standard Library objects (currently: CH 1-14 @ 2.7)
11
+ """
12
+
13
+ import dill as pickle
14
+ pickle.settings['recurse'] = True
15
+ #pickle.detect.trace(True)
16
+ #import pickle
17
+
18
+ # get all objects for testing
19
+ from dill import load_types, objects, extend
20
+ load_types(pickleable=True,unpickleable=False)
21
+
22
+ # uncomment the next two lines to test cloudpickle
23
+ #extend(False)
24
+ #import cloudpickle as pickle
25
+
26
+ # helper objects
27
+ class _class:
28
+ def _method(self):
29
+ pass
30
+
31
+ # objects that *fail* if imported
32
+ special = {}
33
+ special['LambdaType'] = _lambda = lambda x: lambda y: x
34
+ special['MethodType'] = _method = _class()._method
35
+ special['UnboundMethodType'] = _class._method
36
+ objects.update(special)
37
+
38
+ def pickles(name, exact=False, verbose=True):
39
+ """quick check if object pickles with dill"""
40
+ obj = objects[name]
41
+ try:
42
+ pik = pickle.loads(pickle.dumps(obj))
43
+ if exact:
44
+ try:
45
+ assert pik == obj
46
+ except AssertionError:
47
+ assert type(obj) == type(pik)
48
+ if verbose: print ("weak: %s %s" % (name, type(obj)))
49
+ else:
50
+ assert type(obj) == type(pik)
51
+ except Exception:
52
+ if verbose: print ("fails: %s %s" % (name, type(obj)))
53
+
54
+
55
+ def test_objects(verbose=True):
56
+ for member in objects.keys():
57
+ #pickles(member, exact=True, verbose=verbose)
58
+ pickles(member, exact=False, verbose=verbose)
59
+
60
+ if __name__ == '__main__':
61
+ import warnings
62
+ warnings.simplefilter('ignore')
63
+ test_objects(verbose=False)
tool_server/.venv/lib/python3.12/site-packages/dill/tests/test_properties.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
+ import sys
10
+
11
+ import dill
12
+ dill.settings['recurse'] = True
13
+
14
+
15
+ class Foo(object):
16
+ def __init__(self):
17
+ self._data = 1
18
+
19
+ def _get_data(self):
20
+ return self._data
21
+
22
+ def _set_data(self, x):
23
+ self._data = x
24
+
25
+ data = property(_get_data, _set_data)
26
+
27
+
28
+ def test_data_not_none():
29
+ FooS = dill.copy(Foo)
30
+ assert FooS.data.fget is not None
31
+ assert FooS.data.fset is not None
32
+ assert FooS.data.fdel is None
33
+
34
+
35
+ def test_data_unchanged():
36
+ FooS = dill.copy(Foo)
37
+ try:
38
+ res = FooS().data
39
+ except Exception:
40
+ e = sys.exc_info()[1]
41
+ raise AssertionError(str(e))
42
+ else:
43
+ assert res == 1
44
+
45
+
46
+ def test_data_changed():
47
+ FooS = dill.copy(Foo)
48
+ try:
49
+ f = FooS()
50
+ f.data = 1024
51
+ res = f.data
52
+ except Exception:
53
+ e = sys.exc_info()[1]
54
+ raise AssertionError(str(e))
55
+ else:
56
+ assert res == 1024
57
+
58
+
59
+ if __name__ == '__main__':
60
+ test_data_not_none()
61
+ test_data_unchanged()
62
+ test_data_changed()
tool_server/.venv/lib/python3.12/site-packages/dill/tests/test_pycapsule.py ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 PyCapsule object
10
+ """
11
+
12
+ import dill
13
+ import warnings
14
+
15
+ test_pycapsule = None
16
+
17
+ if dill._dill._testcapsule is not None:
18
+ import ctypes
19
+ def test_pycapsule():
20
+ name = ctypes.create_string_buffer(b'dill._testcapsule')
21
+ capsule = dill._dill._PyCapsule_New(
22
+ ctypes.cast(dill._dill._PyCapsule_New, ctypes.c_void_p),
23
+ name,
24
+ None
25
+ )
26
+ with warnings.catch_warnings():
27
+ warnings.simplefilter("ignore")
28
+ dill.copy(capsule)
29
+ dill._testcapsule = capsule
30
+ with warnings.catch_warnings():
31
+ warnings.simplefilter("ignore")
32
+ dill.copy(capsule)
33
+ dill._testcapsule = None
34
+ try:
35
+ with warnings.catch_warnings():
36
+ warnings.simplefilter("ignore", dill.PicklingWarning)
37
+ dill.copy(capsule)
38
+ except dill.UnpicklingError:
39
+ pass
40
+ else:
41
+ raise AssertionError("Expected a different error")
42
+
43
+ if __name__ == '__main__':
44
+ if test_pycapsule is not None:
45
+ test_pycapsule()
tool_server/.venv/lib/python3.12/site-packages/dill/tests/test_recursive.py ADDED
@@ -0,0 +1,177 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 dill
9
+ from functools import partial
10
+ import warnings
11
+
12
+
13
+ def copy(obj, byref=False, recurse=False):
14
+ if byref:
15
+ try:
16
+ return dill.copy(obj, byref=byref, recurse=recurse)
17
+ except Exception:
18
+ pass
19
+ else:
20
+ raise AssertionError('Copy of %s with byref=True should have given a warning!' % (obj,))
21
+
22
+ warnings.simplefilter('ignore')
23
+ val = dill.copy(obj, byref=byref, recurse=recurse)
24
+ warnings.simplefilter('error')
25
+ return val
26
+ else:
27
+ return dill.copy(obj, byref=byref, recurse=recurse)
28
+
29
+
30
+ class obj1(object):
31
+ def __init__(self):
32
+ super(obj1, self).__init__()
33
+
34
+ class obj2(object):
35
+ def __init__(self):
36
+ super(obj2, self).__init__()
37
+
38
+ class obj3(object):
39
+ super_ = super
40
+ def __init__(self):
41
+ obj3.super_(obj3, self).__init__()
42
+
43
+
44
+ def test_super():
45
+ assert copy(obj1(), byref=True)
46
+ assert copy(obj1(), byref=True, recurse=True)
47
+ assert copy(obj1(), recurse=True)
48
+ assert copy(obj1())
49
+
50
+ assert copy(obj2(), byref=True)
51
+ assert copy(obj2(), byref=True, recurse=True)
52
+ assert copy(obj2(), recurse=True)
53
+ assert copy(obj2())
54
+
55
+ assert copy(obj3(), byref=True)
56
+ assert copy(obj3(), byref=True, recurse=True)
57
+ assert copy(obj3(), recurse=True)
58
+ assert copy(obj3())
59
+
60
+
61
+ def get_trigger(model):
62
+ pass
63
+
64
+ class Machine(object):
65
+ def __init__(self):
66
+ self.child = Model()
67
+ self.trigger = partial(get_trigger, self)
68
+ self.child.trigger = partial(get_trigger, self.child)
69
+
70
+ class Model(object):
71
+ pass
72
+
73
+
74
+
75
+ def test_partial():
76
+ assert copy(Machine(), byref=True)
77
+ assert copy(Machine(), byref=True, recurse=True)
78
+ assert copy(Machine(), recurse=True)
79
+ assert copy(Machine())
80
+
81
+
82
+ class Machine2(object):
83
+ def __init__(self):
84
+ self.go = partial(self.member, self)
85
+ def member(self, model):
86
+ pass
87
+
88
+
89
+ class SubMachine(Machine2):
90
+ def __init__(self):
91
+ super(SubMachine, self).__init__()
92
+
93
+
94
+ def test_partials():
95
+ assert copy(SubMachine(), byref=True)
96
+ assert copy(SubMachine(), byref=True, recurse=True)
97
+ assert copy(SubMachine(), recurse=True)
98
+ assert copy(SubMachine())
99
+
100
+
101
+ class obj4(object):
102
+ def __init__(self):
103
+ super(obj4, self).__init__()
104
+ a = self
105
+ class obj5(object):
106
+ def __init__(self):
107
+ super(obj5, self).__init__()
108
+ self.a = a
109
+ self.b = obj5()
110
+
111
+
112
+ def test_circular_reference():
113
+ assert copy(obj4())
114
+ obj4_copy = dill.loads(dill.dumps(obj4()))
115
+ assert type(obj4_copy) is type(obj4_copy).__init__.__closure__[0].cell_contents
116
+ assert type(obj4_copy.b) is type(obj4_copy.b).__init__.__closure__[0].cell_contents
117
+
118
+
119
+ def f():
120
+ def g():
121
+ return g
122
+ return g
123
+
124
+
125
+ def test_function_cells():
126
+ assert copy(f())
127
+
128
+
129
+ def fib(n):
130
+ assert n >= 0
131
+ if n <= 1:
132
+ return n
133
+ else:
134
+ return fib(n-1) + fib(n-2)
135
+
136
+
137
+ def test_recursive_function():
138
+ global fib
139
+ fib2 = copy(fib, recurse=True)
140
+ fib3 = copy(fib)
141
+ fib4 = fib
142
+ del fib
143
+ assert fib2(5) == 5
144
+ for _fib in (fib3, fib4):
145
+ try:
146
+ _fib(5)
147
+ except Exception:
148
+ # This is expected to fail because fib no longer exists
149
+ pass
150
+ else:
151
+ raise AssertionError("Function fib shouldn't have been found")
152
+ fib = fib4
153
+
154
+
155
+ def collection_function_recursion():
156
+ d = {}
157
+ def g():
158
+ return d
159
+ d['g'] = g
160
+ return g
161
+
162
+
163
+ def test_collection_function_recursion():
164
+ g = copy(collection_function_recursion())
165
+ assert g()['g'] is g
166
+
167
+
168
+ if __name__ == '__main__':
169
+ with warnings.catch_warnings():
170
+ warnings.simplefilter('error')
171
+ test_super()
172
+ test_partial()
173
+ test_partials()
174
+ test_circular_reference()
175
+ test_function_cells()
176
+ test_recursive_function()
177
+ test_collection_function_recursion()
tool_server/.venv/lib/python3.12/site-packages/dill/tests/test_registered.py ADDED
@@ -0,0 +1,64 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python
2
+ #
3
+ # Author: Mike McKerns (mmckerns @caltech and @uqfoundation)
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
+ test pickling registered objects
9
+ """
10
+
11
+ import dill
12
+ from dill._objects import failures, registered, succeeds
13
+ import warnings
14
+ warnings.filterwarnings('ignore')
15
+
16
+ def check(d, ok=True):
17
+ res = []
18
+ for k,v in d.items():
19
+ try:
20
+ z = dill.copy(v)
21
+ if ok: res.append(k)
22
+ except:
23
+ if not ok: res.append(k)
24
+ return res
25
+
26
+ fails = check(failures)
27
+ try:
28
+ assert not bool(fails)
29
+ except AssertionError as e:
30
+ print("FAILS: %s" % fails)
31
+ raise e from None
32
+
33
+ register = check(registered, ok=False)
34
+ try:
35
+ assert not bool(register)
36
+ except AssertionError as e:
37
+ print("REGISTER: %s" % register)
38
+ raise e from None
39
+
40
+ success = check(succeeds, ok=False)
41
+ try:
42
+ assert not bool(success)
43
+ except AssertionError as e:
44
+ print("SUCCESS: %s" % success)
45
+ raise e from None
46
+
47
+ import builtins
48
+ import types
49
+ q = dill._dill._reverse_typemap
50
+ p = {k:v for k,v in q.items() if k not in vars(builtins) and k not in vars(types)}
51
+
52
+ diff = set(p.keys()).difference(registered.keys())
53
+ try:
54
+ assert not bool(diff)
55
+ except AssertionError as e:
56
+ print("DIFF: %s" % diff)
57
+ raise e from None
58
+
59
+ miss = set(registered.keys()).difference(p.keys())
60
+ try:
61
+ assert not bool(miss)
62
+ except AssertionError as e:
63
+ print("MISS: %s" % miss)
64
+ raise e from None
tool_server/.venv/lib/python3.12/site-packages/dill/tests/test_restricted.py ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python
2
+ #
3
+ # Author: Kirill Makhonin (@kirillmakhonin)
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
+
11
+ class RestrictedType:
12
+ def __bool__(*args, **kwargs):
13
+ raise Exception('Restricted function')
14
+
15
+ __eq__ = __lt__ = __le__ = __ne__ = __gt__ = __ge__ = __hash__ = __bool__
16
+
17
+ glob_obj = RestrictedType()
18
+
19
+ def restricted_func():
20
+ a = glob_obj
21
+
22
+ def test_function_with_restricted_object():
23
+ deserialized = dill.loads(dill.dumps(restricted_func, recurse=True))
24
+
25
+
26
+ if __name__ == '__main__':
27
+ test_function_with_restricted_object()
tool_server/.venv/lib/python3.12/site-packages/dill/tests/test_selected.py ADDED
@@ -0,0 +1,126 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ testing some selected object types
10
+ """
11
+
12
+ import dill
13
+ dill.settings['recurse'] = True
14
+
15
+ verbose = False
16
+
17
+ def test_dict_contents():
18
+ c = type.__dict__
19
+ for i,j in c.items():
20
+ #try:
21
+ ok = dill.pickles(j)
22
+ #except Exception:
23
+ # print ("FAIL: %s with %s" % (i, dill.detect.errors(j)))
24
+ if verbose: print ("%s: %s, %s" % (ok, type(j), j))
25
+ assert ok
26
+ if verbose: print ("")
27
+
28
+ def _g(x): yield x;
29
+
30
+ def _f():
31
+ try: raise
32
+ except Exception:
33
+ from sys import exc_info
34
+ e, er, tb = exc_info()
35
+ return er, tb
36
+
37
+ class _d(object):
38
+ def _method(self):
39
+ pass
40
+
41
+ from dill import objects
42
+ from dill import load_types
43
+ load_types(pickleable=True,unpickleable=False)
44
+ _newclass = objects['ClassObjectType']
45
+ # some clean-up #FIXME: should happen internal to dill
46
+ objects['TemporaryFileType'].close()
47
+ objects['TextWrapperType'].close()
48
+ if 'BufferedRandomType' in objects:
49
+ objects['BufferedRandomType'].close()
50
+ objects['BufferedReaderType'].close()
51
+ objects['BufferedWriterType'].close()
52
+ objects['FileType'].close()
53
+ del objects
54
+
55
+ # getset_descriptor for new-style classes (fails on '_method', if not __main__)
56
+ def test_class_descriptors():
57
+ d = _d.__dict__
58
+ for i in d.values():
59
+ ok = dill.pickles(i)
60
+ if verbose: print ("%s: %s, %s" % (ok, type(i), i))
61
+ assert ok
62
+ if verbose: print ("")
63
+ od = _newclass.__dict__
64
+ for i in od.values():
65
+ ok = dill.pickles(i)
66
+ if verbose: print ("%s: %s, %s" % (ok, type(i), i))
67
+ assert ok
68
+ if verbose: print ("")
69
+
70
+ # (__main__) class instance for new-style classes
71
+ def test_class():
72
+ o = _d()
73
+ oo = _newclass()
74
+ ok = dill.pickles(o)
75
+ if verbose: print ("%s: %s, %s" % (ok, type(o), o))
76
+ assert ok
77
+ ok = dill.pickles(oo)
78
+ if verbose: print ("%s: %s, %s" % (ok, type(oo), oo))
79
+ assert ok
80
+ if verbose: print ("")
81
+
82
+ # frames, generators, and tracebacks (all depend on frame)
83
+ def test_frame_related():
84
+ g = _g(1)
85
+ f = g.gi_frame
86
+ e,t = _f()
87
+ _is = lambda ok: ok
88
+ ok = dill.pickles(f)
89
+ if verbose: print ("%s: %s, %s" % (ok, type(f), f))
90
+ assert not ok
91
+ ok = dill.pickles(g)
92
+ if verbose: print ("%s: %s, %s" % (ok, type(g), g))
93
+ assert _is(not ok) #XXX: dill fails
94
+ ok = dill.pickles(t)
95
+ if verbose: print ("%s: %s, %s" % (ok, type(t), t))
96
+ assert not ok #XXX: dill fails
97
+ ok = dill.pickles(e)
98
+ if verbose: print ("%s: %s, %s" % (ok, type(e), e))
99
+ assert ok
100
+ if verbose: print ("")
101
+
102
+ def test_typing():
103
+ import typing
104
+ x = typing.Any
105
+ assert x == dill.copy(x)
106
+ x = typing.Dict[int, str]
107
+ assert x == dill.copy(x)
108
+ x = typing.List[int]
109
+ assert x == dill.copy(x)
110
+ x = typing.Tuple[int, str]
111
+ assert x == dill.copy(x)
112
+ x = typing.Tuple[int]
113
+ assert x == dill.copy(x)
114
+ x = typing.Tuple[()]
115
+ assert x == dill.copy(x)
116
+ x = typing.Tuple[()].copy_with(())
117
+ assert x == dill.copy(x)
118
+ return
119
+
120
+
121
+ if __name__ == '__main__':
122
+ test_frame_related()
123
+ test_dict_contents()
124
+ test_class()
125
+ test_class_descriptors()
126
+ test_typing()
tool_server/.venv/lib/python3.12/site-packages/dill/tests/test_session.py ADDED
@@ -0,0 +1,280 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 atexit
9
+ import os
10
+ import sys
11
+ import __main__
12
+ from contextlib import suppress
13
+ from io import BytesIO
14
+
15
+ import dill
16
+
17
+ session_file = os.path.join(os.path.dirname(__file__), 'session-refimported-%s.pkl')
18
+
19
+ ###################
20
+ # Child process #
21
+ ###################
22
+
23
+ def _error_line(error, obj, refimported):
24
+ import traceback
25
+ line = traceback.format_exc().splitlines()[-2].replace('[obj]', '['+repr(obj)+']')
26
+ return "while testing (with refimported=%s): %s" % (refimported, line.lstrip())
27
+
28
+ if __name__ == '__main__' and len(sys.argv) >= 3 and sys.argv[1] == '--child':
29
+ # Test session loading in a fresh interpreter session.
30
+ refimported = (sys.argv[2] == 'True')
31
+ dill.load_module(session_file % refimported, module='__main__')
32
+
33
+ def test_modules(refimported):
34
+ # FIXME: In this test setting with CPython 3.7, 'calendar' is not included
35
+ # in sys.modules, independent of the value of refimported. Tried to
36
+ # run garbage collection just before loading the session with no luck. It
37
+ # fails even when preceding them with 'import calendar'. Needed to run
38
+ # these kinds of tests in a supbrocess. Failing test sample:
39
+ # assert globals()['day_name'] is sys.modules['calendar'].__dict__['day_name']
40
+ try:
41
+ for obj in ('json', 'url', 'local_mod', 'sax', 'dom'):
42
+ assert globals()[obj].__name__ in sys.modules
43
+ assert 'calendar' in sys.modules and 'cmath' in sys.modules
44
+ import calendar, cmath
45
+
46
+ for obj in ('Calendar', 'isleap'):
47
+ assert globals()[obj] is sys.modules['calendar'].__dict__[obj]
48
+ assert __main__.day_name.__module__ == 'calendar'
49
+ if refimported:
50
+ assert __main__.day_name is calendar.day_name
51
+
52
+ assert __main__.complex_log is cmath.log
53
+
54
+ except AssertionError as error:
55
+ error.args = (_error_line(error, obj, refimported),)
56
+ raise
57
+
58
+ test_modules(refimported)
59
+ sys.exit()
60
+
61
+ ####################
62
+ # Parent process #
63
+ ####################
64
+
65
+ # Create various kinds of objects to test different internal logics.
66
+
67
+ ## Modules.
68
+ import json # top-level module
69
+ import urllib as url # top-level module under alias
70
+ from xml import sax # submodule
71
+ import xml.dom.minidom as dom # submodule under alias
72
+ import test_dictviews as local_mod # non-builtin top-level module
73
+
74
+ ## Imported objects.
75
+ from calendar import Calendar, isleap, day_name # class, function, other object
76
+ from cmath import log as complex_log # imported with alias
77
+
78
+ ## Local objects.
79
+ x = 17
80
+ empty = None
81
+ names = ['Alice', 'Bob', 'Carol']
82
+ def squared(x): return x**2
83
+ cubed = lambda x: x**3
84
+ class Person:
85
+ def __init__(self, name, age):
86
+ self.name = name
87
+ self.age = age
88
+ person = Person(names[0], x)
89
+ class CalendarSubclass(Calendar):
90
+ def weekdays(self):
91
+ return [day_name[i] for i in self.iterweekdays()]
92
+ cal = CalendarSubclass()
93
+ selfref = __main__
94
+
95
+ # Setup global namespace for session saving tests.
96
+ class TestNamespace:
97
+ test_globals = globals().copy()
98
+ def __init__(self, **extra):
99
+ self.extra = extra
100
+ def __enter__(self):
101
+ self.backup = globals().copy()
102
+ globals().clear()
103
+ globals().update(self.test_globals)
104
+ globals().update(self.extra)
105
+ return self
106
+ def __exit__(self, *exc_info):
107
+ globals().clear()
108
+ globals().update(self.backup)
109
+
110
+ def _clean_up_cache(module):
111
+ cached = module.__file__.split('.', 1)[0] + '.pyc'
112
+ cached = module.__cached__ if hasattr(module, '__cached__') else cached
113
+ pycache = os.path.join(os.path.dirname(module.__file__), '__pycache__')
114
+ for remove, file in [(os.remove, cached), (os.removedirs, pycache)]:
115
+ with suppress(OSError):
116
+ remove(file)
117
+
118
+ atexit.register(_clean_up_cache, local_mod)
119
+
120
+ def _test_objects(main, globals_copy, refimported):
121
+ try:
122
+ main_dict = __main__.__dict__
123
+ global Person, person, Calendar, CalendarSubclass, cal, selfref
124
+
125
+ for obj in ('json', 'url', 'local_mod', 'sax', 'dom'):
126
+ assert globals()[obj].__name__ == globals_copy[obj].__name__
127
+
128
+ for obj in ('x', 'empty', 'names'):
129
+ assert main_dict[obj] == globals_copy[obj]
130
+
131
+ for obj in ['squared', 'cubed']:
132
+ assert main_dict[obj].__globals__ is main_dict
133
+ assert main_dict[obj](3) == globals_copy[obj](3)
134
+
135
+ assert Person.__module__ == __main__.__name__
136
+ assert isinstance(person, Person)
137
+ assert person.age == globals_copy['person'].age
138
+
139
+ assert issubclass(CalendarSubclass, Calendar)
140
+ assert isinstance(cal, CalendarSubclass)
141
+ assert cal.weekdays() == globals_copy['cal'].weekdays()
142
+
143
+ assert selfref is __main__
144
+
145
+ except AssertionError as error:
146
+ error.args = (_error_line(error, obj, refimported),)
147
+ raise
148
+
149
+ def test_session_main(refimported):
150
+ """test dump/load_module() for __main__, both in this process and in a subprocess"""
151
+ extra_objects = {}
152
+ if refimported:
153
+ # Test unpickleable imported object in main.
154
+ from sys import flags
155
+ extra_objects['flags'] = flags
156
+
157
+ with TestNamespace(**extra_objects) as ns:
158
+ try:
159
+ # Test session loading in a new session.
160
+ dill.dump_module(session_file % refimported, refimported=refimported)
161
+ from dill.tests.__main__ import python, shell, sp
162
+ error = sp.call([python, __file__, '--child', str(refimported)], shell=shell)
163
+ if error: sys.exit(error)
164
+ finally:
165
+ with suppress(OSError):
166
+ os.remove(session_file % refimported)
167
+
168
+ # Test session loading in the same session.
169
+ session_buffer = BytesIO()
170
+ dill.dump_module(session_buffer, refimported=refimported)
171
+ session_buffer.seek(0)
172
+ dill.load_module(session_buffer, module='__main__')
173
+ ns.backup['_test_objects'](__main__, ns.backup, refimported)
174
+
175
+ def test_session_other():
176
+ """test dump/load_module() for a module other than __main__"""
177
+ import test_classdef as module
178
+ atexit.register(_clean_up_cache, module)
179
+ module.selfref = module
180
+ dict_objects = [obj for obj in module.__dict__.keys() if not obj.startswith('__')]
181
+
182
+ session_buffer = BytesIO()
183
+ dill.dump_module(session_buffer, module)
184
+
185
+ for obj in dict_objects:
186
+ del module.__dict__[obj]
187
+
188
+ session_buffer.seek(0)
189
+ dill.load_module(session_buffer, module)
190
+
191
+ assert all(obj in module.__dict__ for obj in dict_objects)
192
+ assert module.selfref is module
193
+
194
+ def test_runtime_module():
195
+ from types import ModuleType
196
+ modname = '__runtime__'
197
+ runtime = ModuleType(modname)
198
+ runtime.x = 42
199
+
200
+ mod = dill.session._stash_modules(runtime)
201
+ if mod is not runtime:
202
+ print("There are objects to save by referenece that shouldn't be:",
203
+ mod.__dill_imported, mod.__dill_imported_as, mod.__dill_imported_top_level,
204
+ file=sys.stderr)
205
+
206
+ # This is also for code coverage, tests the use case of dump_module(refimported=True)
207
+ # without imported objects in the namespace. It's a contrived example because
208
+ # even dill can't be in it. This should work after fixing #462.
209
+ session_buffer = BytesIO()
210
+ dill.dump_module(session_buffer, module=runtime, refimported=True)
211
+ session_dump = session_buffer.getvalue()
212
+
213
+ # Pass a new runtime created module with the same name.
214
+ runtime = ModuleType(modname) # empty
215
+ return_val = dill.load_module(BytesIO(session_dump), module=runtime)
216
+ assert return_val is None
217
+ assert runtime.__name__ == modname
218
+ assert runtime.x == 42
219
+ assert runtime not in sys.modules.values()
220
+
221
+ # Pass nothing as main. load_module() must create it.
222
+ session_buffer.seek(0)
223
+ runtime = dill.load_module(BytesIO(session_dump))
224
+ assert runtime.__name__ == modname
225
+ assert runtime.x == 42
226
+ assert runtime not in sys.modules.values()
227
+
228
+ def test_refimported_imported_as():
229
+ import collections
230
+ import concurrent.futures
231
+ import types
232
+ import typing
233
+ mod = sys.modules['__test__'] = types.ModuleType('__test__')
234
+ dill.executor = concurrent.futures.ThreadPoolExecutor(max_workers=1)
235
+ mod.Dict = collections.UserDict # select by type
236
+ mod.AsyncCM = typing.AsyncContextManager # select by __module__
237
+ mod.thread_exec = dill.executor # select by __module__ with regex
238
+
239
+ session_buffer = BytesIO()
240
+ dill.dump_module(session_buffer, mod, refimported=True)
241
+ session_buffer.seek(0)
242
+ mod = dill.load(session_buffer)
243
+ del sys.modules['__test__']
244
+
245
+ assert set(mod.__dill_imported_as) == {
246
+ ('collections', 'UserDict', 'Dict'),
247
+ ('typing', 'AsyncContextManager', 'AsyncCM'),
248
+ ('dill', 'executor', 'thread_exec'),
249
+ }
250
+
251
+ def test_load_module_asdict():
252
+ with TestNamespace():
253
+ session_buffer = BytesIO()
254
+ dill.dump_module(session_buffer)
255
+
256
+ global empty, names, x, y
257
+ x = y = 0 # change x and create y
258
+ del empty
259
+ globals_state = globals().copy()
260
+
261
+ session_buffer.seek(0)
262
+ main_vars = dill.load_module_asdict(session_buffer)
263
+
264
+ assert main_vars is not globals()
265
+ assert globals() == globals_state
266
+
267
+ assert main_vars['__name__'] == '__main__'
268
+ assert main_vars['names'] == names
269
+ assert main_vars['names'] is not names
270
+ assert main_vars['x'] != x
271
+ assert 'y' not in main_vars
272
+ assert 'empty' in main_vars
273
+
274
+ if __name__ == '__main__':
275
+ test_session_main(refimported=False)
276
+ test_session_main(refimported=True)
277
+ test_session_other()
278
+ test_runtime_module()
279
+ test_refimported_imported_as()
280
+ test_load_module_asdict()
tool_server/.venv/lib/python3.12/site-packages/dill/tests/test_source.py ADDED
@@ -0,0 +1,173 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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.source import getsource, getname, _wrap, getimport
10
+ from dill.source import importable
11
+ from dill._dill import IS_PYPY
12
+
13
+ import sys
14
+ PY310b = 0x30a00b1
15
+
16
+ f = lambda x: x**2
17
+ def g(x): return f(x) - x
18
+
19
+ def h(x):
20
+ def g(x): return x
21
+ return g(x) - x
22
+
23
+ class Foo(object):
24
+ def bar(self, x):
25
+ return x*x+x
26
+ _foo = Foo()
27
+
28
+ def add(x,y):
29
+ return x+y
30
+
31
+ # yes, same as 'f', but things are tricky when it comes to pointers
32
+ squared = lambda x:x**2
33
+
34
+ class Bar:
35
+ pass
36
+ _bar = Bar()
37
+
38
+ # inspect.getsourcelines # dill.source.getblocks
39
+ def test_getsource():
40
+ assert getsource(f) == 'f = lambda x: x**2\n'
41
+ assert getsource(g) == 'def g(x): return f(x) - x\n'
42
+ assert getsource(h) == 'def h(x):\n def g(x): return x\n return g(x) - x\n'
43
+ assert getname(f) == 'f'
44
+ assert getname(g) == 'g'
45
+ assert getname(h) == 'h'
46
+ assert _wrap(f)(4) == 16
47
+ assert _wrap(g)(4) == 12
48
+ assert _wrap(h)(4) == 0
49
+
50
+ assert getname(Foo) == 'Foo'
51
+ assert getname(Bar) == 'Bar'
52
+ assert getsource(Bar) == 'class Bar:\n pass\n'
53
+ assert getsource(Foo) == 'class Foo(object):\n def bar(self, x):\n return x*x+x\n'
54
+ #XXX: add getsource for _foo, _bar
55
+
56
+ # test itself
57
+ def test_itself():
58
+ assert getimport(getimport)=='from dill.source import getimport\n'
59
+
60
+ # builtin functions and objects
61
+ def test_builtin():
62
+ assert getimport(pow) == 'pow\n'
63
+ assert getimport(100) == '100\n'
64
+ assert getimport(True) == 'True\n'
65
+ assert getimport(pow, builtin=True) == 'from builtins import pow\n'
66
+ assert getimport(100, builtin=True) == '100\n'
67
+ assert getimport(True, builtin=True) == 'True\n'
68
+ # this is kinda BS... you can't import a None
69
+ assert getimport(None) == 'None\n'
70
+ assert getimport(None, builtin=True) == 'None\n'
71
+
72
+
73
+ # other imported functions
74
+ def test_imported():
75
+ from math import sin
76
+ assert getimport(sin) == 'from math import sin\n'
77
+
78
+ # interactively defined functions
79
+ def test_dynamic():
80
+ assert getimport(add) == 'from %s import add\n' % __name__
81
+ # interactive lambdas
82
+ assert getimport(squared) == 'from %s import squared\n' % __name__
83
+
84
+ # classes and class instances
85
+ def test_classes():
86
+ from io import BytesIO as StringIO
87
+ y = "from _io import BytesIO\n"
88
+ x = y if (IS_PYPY or sys.hexversion >= PY310b) else "from io import BytesIO\n"
89
+ s = StringIO()
90
+
91
+ assert getimport(StringIO) == x
92
+ assert getimport(s) == y
93
+ # interactively defined classes and class instances
94
+ assert getimport(Foo) == 'from %s import Foo\n' % __name__
95
+ assert getimport(_foo) == 'from %s import Foo\n' % __name__
96
+
97
+
98
+ # test importable
99
+ def test_importable():
100
+ assert importable(add, source=False) == 'from %s import add\n' % __name__
101
+ assert importable(squared, source=False) == 'from %s import squared\n' % __name__
102
+ assert importable(Foo, source=False) == 'from %s import Foo\n' % __name__
103
+ assert importable(Foo.bar, source=False) == 'from %s import bar\n' % __name__
104
+ assert importable(_foo.bar, source=False) == 'from %s import bar\n' % __name__
105
+ assert importable(None, source=False) == 'None\n'
106
+ assert importable(100, source=False) == '100\n'
107
+
108
+ assert importable(add, source=True) == 'def add(x,y):\n return x+y\n'
109
+ assert importable(squared, source=True) == 'squared = lambda x:x**2\n'
110
+ assert importable(None, source=True) == 'None\n'
111
+ assert importable(Bar, source=True) == 'class Bar:\n pass\n'
112
+ assert importable(Foo, source=True) == 'class Foo(object):\n def bar(self, x):\n return x*x+x\n'
113
+ assert importable(Foo.bar, source=True) == 'def bar(self, x):\n return x*x+x\n'
114
+ assert importable(Foo.bar, source=False) == 'from %s import bar\n' % __name__
115
+ assert importable(Foo.bar, alias='memo', source=False) == 'from %s import bar as memo\n' % __name__
116
+ assert importable(Foo, alias='memo', source=False) == 'from %s import Foo as memo\n' % __name__
117
+ assert importable(squared, alias='memo', source=False) == 'from %s import squared as memo\n' % __name__
118
+ assert importable(squared, alias='memo', source=True) == 'memo = squared = lambda x:x**2\n'
119
+ assert importable(add, alias='memo', source=True) == 'def add(x,y):\n return x+y\n\nmemo = add\n'
120
+ assert importable(None, alias='memo', source=True) == 'memo = None\n'
121
+ assert importable(100, alias='memo', source=True) == 'memo = 100\n'
122
+ assert importable(add, builtin=True, source=False) == 'from %s import add\n' % __name__
123
+ assert importable(squared, builtin=True, source=False) == 'from %s import squared\n' % __name__
124
+ assert importable(Foo, builtin=True, source=False) == 'from %s import Foo\n' % __name__
125
+ assert importable(Foo.bar, builtin=True, source=False) == 'from %s import bar\n' % __name__
126
+ assert importable(_foo.bar, builtin=True, source=False) == 'from %s import bar\n' % __name__
127
+ assert importable(None, builtin=True, source=False) == 'None\n'
128
+ assert importable(100, builtin=True, source=False) == '100\n'
129
+
130
+
131
+ def test_numpy():
132
+ try:
133
+ import numpy as np
134
+ y = np.array
135
+ x = y([1,2,3])
136
+ assert importable(x, source=False) == 'from numpy import array\narray([1, 2, 3])\n'
137
+ assert importable(y, source=False) == 'from %s import array\n' % y.__module__
138
+ assert importable(x, source=True) == 'from numpy import array\narray([1, 2, 3])\n'
139
+ assert importable(y, source=True) == 'from %s import array\n' % y.__module__
140
+ y = np.int64
141
+ x = y(0)
142
+ assert importable(x, source=False) == 'from numpy import int64\nint64(0)\n'
143
+ assert importable(y, source=False) == 'from %s import int64\n' % y.__module__
144
+ assert importable(x, source=True) == 'from numpy import int64\nint64(0)\n'
145
+ assert importable(y, source=True) == 'from %s import int64\n' % y.__module__
146
+ y = np.bool_
147
+ x = y(0)
148
+ import warnings
149
+ with warnings.catch_warnings():
150
+ warnings.filterwarnings('ignore', category=FutureWarning)
151
+ warnings.filterwarnings('ignore', category=DeprecationWarning)
152
+ if hasattr(np, 'bool'): b = 'bool_' if np.bool is bool else 'bool'
153
+ else: b = 'bool_'
154
+ assert importable(x, source=False) == 'from numpy import %s\n%s(False)\n' % (b,b)
155
+ assert importable(y, source=False) == 'from %s import %s\n' % (y.__module__,b)
156
+ assert importable(x, source=True) == 'from numpy import %s\n%s(False)\n' % (b,b)
157
+ assert importable(y, source=True) == 'from %s import %s\n' % (y.__module__,b)
158
+ except ImportError: pass
159
+
160
+ #NOTE: if before getimport(pow), will cause pow to throw AssertionError
161
+ def test_foo():
162
+ assert importable(_foo, source=True).startswith("import dill\nclass Foo(object):\n def bar(self, x):\n return x*x+x\ndill.loads(")
163
+
164
+ if __name__ == '__main__':
165
+ test_getsource()
166
+ test_itself()
167
+ test_builtin()
168
+ test_imported()
169
+ test_dynamic()
170
+ test_classes()
171
+ test_importable()
172
+ test_numpy()
173
+ test_foo()
tool_server/.venv/lib/python3.12/site-packages/dill/tests/test_sources.py ADDED
@@ -0,0 +1,190 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python
2
+ #
3
+ # Author: Mike McKerns (mmckerns @uqfoundation)
4
+ # Copyright (c) 2024-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
+ check that dill.source performs as expected with changes to locals in 3.13.0b1
9
+ see: https://github.com/python/cpython/issues/118888
10
+ """
11
+ # repeat functions from test_source.py
12
+ f = lambda x: x**2
13
+ def g(x): return f(x) - x
14
+
15
+ def h(x):
16
+ def g(x): return x
17
+ return g(x) - x
18
+
19
+ class Foo(object):
20
+ def bar(self, x):
21
+ return x*x+x
22
+ _foo = Foo()
23
+
24
+ def add(x,y):
25
+ return x+y
26
+
27
+ squared = lambda x:x**2
28
+
29
+ class Bar:
30
+ pass
31
+ _bar = Bar()
32
+
33
+ # repeat, but from test_source.py
34
+ import test_source as ts
35
+
36
+ # test objects created in other test modules
37
+ import test_mixins as tm
38
+
39
+ import dill.source as ds
40
+
41
+
42
+ def test_isfrommain():
43
+ assert ds.isfrommain(add) == True
44
+ assert ds.isfrommain(squared) == True
45
+ assert ds.isfrommain(Bar) == True
46
+ assert ds.isfrommain(_bar) == True
47
+ assert ds.isfrommain(ts.add) == False
48
+ assert ds.isfrommain(ts.squared) == False
49
+ assert ds.isfrommain(ts.Bar) == False
50
+ assert ds.isfrommain(ts._bar) == False
51
+ assert ds.isfrommain(tm.quad) == False
52
+ assert ds.isfrommain(tm.double_add) == False
53
+ assert ds.isfrommain(tm.quadratic) == False
54
+ assert ds.isdynamic(add) == False
55
+ assert ds.isdynamic(squared) == False
56
+ assert ds.isdynamic(ts.add) == False
57
+ assert ds.isdynamic(ts.squared) == False
58
+ assert ds.isdynamic(tm.double_add) == False
59
+ assert ds.isdynamic(tm.quadratic) == False
60
+
61
+
62
+ def test_matchlambda():
63
+ assert ds._matchlambda(f, 'f = lambda x: x**2\n')
64
+ assert ds._matchlambda(squared, 'squared = lambda x:x**2\n')
65
+ assert ds._matchlambda(ts.f, 'f = lambda x: x**2\n')
66
+ assert ds._matchlambda(ts.squared, 'squared = lambda x:x**2\n')
67
+
68
+
69
+ def test_findsource():
70
+ lines, lineno = ds.findsource(add)
71
+ assert lines[lineno] == 'def add(x,y):\n'
72
+ lines, lineno = ds.findsource(ts.add)
73
+ assert lines[lineno] == 'def add(x,y):\n'
74
+ lines, lineno = ds.findsource(squared)
75
+ assert lines[lineno] == 'squared = lambda x:x**2\n'
76
+ lines, lineno = ds.findsource(ts.squared)
77
+ assert lines[lineno] == 'squared = lambda x:x**2\n'
78
+ lines, lineno = ds.findsource(Bar)
79
+ assert lines[lineno] == 'class Bar:\n'
80
+ lines, lineno = ds.findsource(ts.Bar)
81
+ assert lines[lineno] == 'class Bar:\n'
82
+ lines, lineno = ds.findsource(_bar)
83
+ assert lines[lineno] == 'class Bar:\n'
84
+ lines, lineno = ds.findsource(ts._bar)
85
+ assert lines[lineno] == 'class Bar:\n'
86
+ lines, lineno = ds.findsource(tm.quad)
87
+ assert lines[lineno] == 'def quad(a=1, b=1, c=0):\n'
88
+ lines, lineno = ds.findsource(tm.double_add)
89
+ assert lines[lineno] == ' def func(*args, **kwds):\n'
90
+ lines, lineno = ds.findsource(tm.quadratic)
91
+ assert lines[lineno] == ' def dec(f):\n'
92
+
93
+
94
+ def test_getsourcelines():
95
+ assert ''.join(ds.getsourcelines(add)[0]) == 'def add(x,y):\n return x+y\n'
96
+ assert ''.join(ds.getsourcelines(ts.add)[0]) == 'def add(x,y):\n return x+y\n'
97
+ assert ''.join(ds.getsourcelines(squared)[0]) == 'squared = lambda x:x**2\n'
98
+ assert ''.join(ds.getsourcelines(ts.squared)[0]) == 'squared = lambda x:x**2\n'
99
+ assert ''.join(ds.getsourcelines(Bar)[0]) == 'class Bar:\n pass\n'
100
+ assert ''.join(ds.getsourcelines(ts.Bar)[0]) == 'class Bar:\n pass\n'
101
+ assert ''.join(ds.getsourcelines(_bar)[0]) == 'class Bar:\n pass\n' #XXX: ?
102
+ assert ''.join(ds.getsourcelines(ts._bar)[0]) == 'class Bar:\n pass\n' #XXX: ?
103
+ assert ''.join(ds.getsourcelines(tm.quad)[0]) == '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'
104
+ assert ''.join(ds.getsourcelines(tm.quadratic)[0]) == ' 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'
105
+ assert ''.join(ds.getsourcelines(tm.quadratic, lstrip=True)[0]) == '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'
106
+ assert ''.join(ds.getsourcelines(tm.quadratic, enclosing=True)[0]) == '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'
107
+ assert ''.join(ds.getsourcelines(tm.double_add)[0]) == ' def func(*args, **kwds):\n x = f(*args, **kwds)\n if inverted[0]: x = -x\n return a*x**2 + b*x + c\n'
108
+ assert ''.join(ds.getsourcelines(tm.double_add, enclosing=True)[0]) == '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'
109
+
110
+
111
+ def test_indent():
112
+ assert ds.outdent(''.join(ds.getsourcelines(tm.quadratic)[0])) == ''.join(ds.getsourcelines(tm.quadratic, lstrip=True)[0])
113
+ assert ds.indent(''.join(ds.getsourcelines(tm.quadratic, lstrip=True)[0]), 2) == ''.join(ds.getsourcelines(tm.quadratic)[0])
114
+
115
+
116
+ def test_dumpsource():
117
+ local = {}
118
+ exec(ds.dumpsource(add, alias='raw'), {}, local)
119
+ exec(ds.dumpsource(ts.add, alias='mod'), {}, local)
120
+ assert local['raw'](1,2) == local['mod'](1,2)
121
+ exec(ds.dumpsource(squared, alias='raw'), {}, local)
122
+ exec(ds.dumpsource(ts.squared, alias='mod'), {}, local)
123
+ assert local['raw'](3) == local['mod'](3)
124
+ assert ds._wrap(add)(1,2) == ds._wrap(ts.add)(1,2)
125
+ assert ds._wrap(squared)(3) == ds._wrap(ts.squared)(3)
126
+
127
+
128
+ def test_name():
129
+ assert ds._namespace(add) == ds.getname(add, fqn=True).split('.')
130
+ assert ds._namespace(ts.add) == ds.getname(ts.add, fqn=True).split('.')
131
+ assert ds._namespace(squared) == ds.getname(squared, fqn=True).split('.')
132
+ assert ds._namespace(ts.squared) == ds.getname(ts.squared, fqn=True).split('.')
133
+ assert ds._namespace(Bar) == ds.getname(Bar, fqn=True).split('.')
134
+ assert ds._namespace(ts.Bar) == ds.getname(ts.Bar, fqn=True).split('.')
135
+ assert ds._namespace(tm.quad) == ds.getname(tm.quad, fqn=True).split('.')
136
+ #XXX: the following also works, however behavior may be wrong for nested functions
137
+ #assert ds._namespace(tm.double_add) == ds.getname(tm.double_add, fqn=True).split('.')
138
+ #assert ds._namespace(tm.quadratic) == ds.getname(tm.quadratic, fqn=True).split('.')
139
+ assert ds.getname(add) == 'add'
140
+ assert ds.getname(ts.add) == 'add'
141
+ assert ds.getname(squared) == 'squared'
142
+ assert ds.getname(ts.squared) == 'squared'
143
+ assert ds.getname(Bar) == 'Bar'
144
+ assert ds.getname(ts.Bar) == 'Bar'
145
+ assert ds.getname(tm.quad) == 'quad'
146
+ assert ds.getname(tm.double_add) == 'func' #XXX: ?
147
+ assert ds.getname(tm.quadratic) == 'dec' #XXX: ?
148
+
149
+
150
+ def test_getimport():
151
+ local = {}
152
+ exec(ds.getimport(add, alias='raw'), {}, local)
153
+ exec(ds.getimport(ts.add, alias='mod'), {}, local)
154
+ assert local['raw'](1,2) == local['mod'](1,2)
155
+ exec(ds.getimport(squared, alias='raw'), {}, local)
156
+ exec(ds.getimport(ts.squared, alias='mod'), {}, local)
157
+ assert local['raw'](3) == local['mod'](3)
158
+ exec(ds.getimport(Bar, alias='raw'), {}, local)
159
+ exec(ds.getimport(ts.Bar, alias='mod'), {}, local)
160
+ assert ds.getname(local['raw']) == ds.getname(local['mod'])
161
+ exec(ds.getimport(tm.quad, alias='mod'), {}, local)
162
+ assert local['mod']()(sum)([1,2,3]) == tm.quad()(sum)([1,2,3])
163
+ #FIXME: wrong results for nested functions (e.g. tm.double_add, tm.quadratic)
164
+
165
+
166
+ def test_importable():
167
+ assert ds.importable(add, source=False) == ds.getimport(add)
168
+ assert ds.importable(add) == ds.getsource(add)
169
+ assert ds.importable(squared, source=False) == ds.getimport(squared)
170
+ assert ds.importable(squared) == ds.getsource(squared)
171
+ assert ds.importable(Bar, source=False) == ds.getimport(Bar)
172
+ assert ds.importable(Bar) == ds.getsource(Bar)
173
+ assert ds.importable(ts.add) == ds.getimport(ts.add)
174
+ assert ds.importable(ts.add, source=True) == ds.getsource(ts.add)
175
+ assert ds.importable(ts.squared) == ds.getimport(ts.squared)
176
+ assert ds.importable(ts.squared, source=True) == ds.getsource(ts.squared)
177
+ assert ds.importable(ts.Bar) == ds.getimport(ts.Bar)
178
+ assert ds.importable(ts.Bar, source=True) == ds.getsource(ts.Bar)
179
+
180
+
181
+ if __name__ == '__main__':
182
+ test_isfrommain()
183
+ test_matchlambda()
184
+ test_findsource()
185
+ test_getsourcelines()
186
+ test_indent()
187
+ test_dumpsource()
188
+ test_name()
189
+ test_getimport()
190
+ test_importable()
tool_server/.venv/lib/python3.12/site-packages/dill/tests/test_temp.py ADDED
@@ -0,0 +1,103 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 sys
10
+ from dill.temp import dump, dump_source, dumpIO, dumpIO_source
11
+ from dill.temp import load, load_source, loadIO, loadIO_source
12
+ WINDOWS = sys.platform[:3] == 'win'
13
+
14
+
15
+ f = lambda x: x**2
16
+ x = [1,2,3,4,5]
17
+
18
+ # source code to tempfile
19
+ def test_code_to_tempfile():
20
+ if not WINDOWS: #see: https://bugs.python.org/issue14243
21
+ pyfile = dump_source(f, alias='_f')
22
+ _f = load_source(pyfile)
23
+ assert _f(4) == f(4)
24
+
25
+ # source code to stream
26
+ def test_code_to_stream():
27
+ pyfile = dumpIO_source(f, alias='_f')
28
+ _f = loadIO_source(pyfile)
29
+ assert _f(4) == f(4)
30
+
31
+ # pickle to tempfile
32
+ def test_pickle_to_tempfile():
33
+ if not WINDOWS: #see: https://bugs.python.org/issue14243
34
+ dumpfile = dump(x)
35
+ _x = load(dumpfile)
36
+ assert _x == x
37
+
38
+ # pickle to stream
39
+ def test_pickle_to_stream():
40
+ dumpfile = dumpIO(x)
41
+ _x = loadIO(dumpfile)
42
+ assert _x == x
43
+
44
+ ### now testing the objects ###
45
+ f = lambda x: x**2
46
+ def g(x): return f(x) - x
47
+
48
+ def h(x):
49
+ def g(x): return x
50
+ return g(x) - x
51
+
52
+ class Foo(object):
53
+ def bar(self, x):
54
+ return x*x+x
55
+ _foo = Foo()
56
+
57
+ def add(x,y):
58
+ return x+y
59
+
60
+ # yes, same as 'f', but things are tricky when it comes to pointers
61
+ squared = lambda x:x**2
62
+
63
+ class Bar:
64
+ pass
65
+ _bar = Bar()
66
+
67
+
68
+ # test function-type objects that take 2 args
69
+ def test_two_arg_functions():
70
+ for obj in [add]:
71
+ pyfile = dumpIO_source(obj, alias='_obj')
72
+ _obj = loadIO_source(pyfile)
73
+ assert _obj(4,2) == obj(4,2)
74
+
75
+ # test function-type objects that take 1 arg
76
+ def test_one_arg_functions():
77
+ for obj in [g, h, squared]:
78
+ pyfile = dumpIO_source(obj, alias='_obj')
79
+ _obj = loadIO_source(pyfile)
80
+ assert _obj(4) == obj(4)
81
+
82
+ # test instance-type objects
83
+ #for obj in [_bar, _foo]:
84
+ # pyfile = dumpIO_source(obj, alias='_obj')
85
+ # _obj = loadIO_source(pyfile)
86
+ # assert type(_obj) == type(obj)
87
+
88
+ # test the rest of the objects
89
+ def test_the_rest():
90
+ for obj in [Bar, Foo, Foo.bar, _foo.bar]:
91
+ pyfile = dumpIO_source(obj, alias='_obj')
92
+ _obj = loadIO_source(pyfile)
93
+ assert _obj.__name__ == obj.__name__
94
+
95
+
96
+ if __name__ == '__main__':
97
+ test_code_to_tempfile()
98
+ test_code_to_stream()
99
+ test_pickle_to_tempfile()
100
+ test_pickle_to_stream()
101
+ test_two_arg_functions()
102
+ test_one_arg_functions()
103
+ test_the_rest()
tool_server/.venv/lib/python3.12/site-packages/dill/tests/test_threads.py ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python
2
+ #
3
+ # Author: Mike McKerns (mmckerns @caltech and @uqfoundation)
4
+ # Copyright (c) 2024-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
+
12
+ def test_new_thread():
13
+ import threading
14
+ t = threading.Thread()
15
+ t_ = dill.copy(t)
16
+ assert t.is_alive() == t_.is_alive()
17
+ for i in ['daemon','name','ident','native_id']:
18
+ if hasattr(t, i):
19
+ assert getattr(t, i) == getattr(t_, i)
20
+
21
+ def test_run_thread():
22
+ import threading
23
+ t = threading.Thread()
24
+ t.start()
25
+ t_ = dill.copy(t)
26
+ assert t.is_alive() == t_.is_alive()
27
+ for i in ['daemon','name','ident','native_id']:
28
+ if hasattr(t, i):
29
+ assert getattr(t, i) == getattr(t_, i)
30
+
31
+ def test_join_thread():
32
+ import threading
33
+ t = threading.Thread()
34
+ t.start()
35
+ t.join()
36
+ t_ = dill.copy(t)
37
+ assert t.is_alive() == t_.is_alive()
38
+ for i in ['daemon','name','ident','native_id']:
39
+ if hasattr(t, i):
40
+ assert getattr(t, i) == getattr(t_, i)
41
+
42
+
43
+ if __name__ == '__main__':
44
+ test_new_thread()
45
+ test_run_thread()
46
+ test_join_thread()