Add files using upload-large-folder tool
Browse filesThis view is limited to 50 files because it contains too many changes.
See raw diff
- llmeval-env/lib/python3.10/site-packages/attrs/__init__.py +65 -0
- llmeval-env/lib/python3.10/site-packages/attrs/__init__.pyi +67 -0
- llmeval-env/lib/python3.10/site-packages/attrs/converters.py +3 -0
- llmeval-env/lib/python3.10/site-packages/attrs/filters.py +3 -0
- llmeval-env/lib/python3.10/site-packages/attrs/py.typed +0 -0
- llmeval-env/lib/python3.10/site-packages/attrs/setters.py +3 -0
- llmeval-env/lib/python3.10/site-packages/attrs/validators.py +3 -0
- llmeval-env/lib/python3.10/site-packages/dill/__pycache__/__init__.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/dill/__pycache__/logger.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/dill/__pycache__/objtypes.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/dill/__pycache__/pointers.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/dill/__pycache__/settings.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/dill/__pycache__/source.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/dill/temp.py +252 -0
- llmeval-env/lib/python3.10/site-packages/dill/tests/__pycache__/__init__.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/dill/tests/__pycache__/__main__.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/dill/tests/__pycache__/test_abc.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/dill/tests/__pycache__/test_check.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/dill/tests/__pycache__/test_classdef.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/dill/tests/__pycache__/test_detect.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/dill/tests/__pycache__/test_dictviews.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/dill/tests/__pycache__/test_diff.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/dill/tests/__pycache__/test_extendpickle.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/dill/tests/__pycache__/test_file.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/dill/tests/__pycache__/test_functions.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/dill/tests/__pycache__/test_logger.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/dill/tests/__pycache__/test_mixins.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/dill/tests/__pycache__/test_module.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/dill/tests/__pycache__/test_nested.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/dill/tests/__pycache__/test_objects.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/dill/tests/__pycache__/test_properties.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/dill/tests/__pycache__/test_pycapsule.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/dill/tests/__pycache__/test_recursive.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/dill/tests/__pycache__/test_registered.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/dill/tests/__pycache__/test_restricted.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/dill/tests/__pycache__/test_selected.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/dill/tests/__pycache__/test_temp.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/dill/tests/__pycache__/test_weakref.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/dill/tests/test_check.py +62 -0
- llmeval-env/lib/python3.10/site-packages/dill/tests/test_classdef.py +340 -0
- llmeval-env/lib/python3.10/site-packages/dill/tests/test_detect.py +159 -0
- llmeval-env/lib/python3.10/site-packages/dill/tests/test_fglobals.py +55 -0
- llmeval-env/lib/python3.10/site-packages/dill/tests/test_file.py +500 -0
- llmeval-env/lib/python3.10/site-packages/dill/tests/test_pycapsule.py +45 -0
- llmeval-env/lib/python3.10/site-packages/dill/tests/test_recursive.py +177 -0
- llmeval-env/lib/python3.10/site-packages/dill/tests/test_temp.py +103 -0
- llmeval-env/lib/python3.10/site-packages/dill/tests/test_weakref.py +72 -0
- llmeval-env/lib/python3.10/site-packages/multidict/__init__.py +48 -0
- llmeval-env/lib/python3.10/site-packages/multidict/__init__.pyi +152 -0
- llmeval-env/lib/python3.10/site-packages/multidict/__pycache__/__init__.cpython-310.pyc +0 -0
llmeval-env/lib/python3.10/site-packages/attrs/__init__.py
ADDED
@@ -0,0 +1,65 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# SPDX-License-Identifier: MIT
|
2 |
+
|
3 |
+
from attr import (
|
4 |
+
NOTHING,
|
5 |
+
Attribute,
|
6 |
+
AttrsInstance,
|
7 |
+
Factory,
|
8 |
+
_make_getattr,
|
9 |
+
assoc,
|
10 |
+
cmp_using,
|
11 |
+
define,
|
12 |
+
evolve,
|
13 |
+
field,
|
14 |
+
fields,
|
15 |
+
fields_dict,
|
16 |
+
frozen,
|
17 |
+
has,
|
18 |
+
make_class,
|
19 |
+
mutable,
|
20 |
+
resolve_types,
|
21 |
+
validate,
|
22 |
+
)
|
23 |
+
from attr._next_gen import asdict, astuple
|
24 |
+
|
25 |
+
from . import converters, exceptions, filters, setters, validators
|
26 |
+
|
27 |
+
|
28 |
+
__all__ = [
|
29 |
+
"__author__",
|
30 |
+
"__copyright__",
|
31 |
+
"__description__",
|
32 |
+
"__doc__",
|
33 |
+
"__email__",
|
34 |
+
"__license__",
|
35 |
+
"__title__",
|
36 |
+
"__url__",
|
37 |
+
"__version__",
|
38 |
+
"__version_info__",
|
39 |
+
"asdict",
|
40 |
+
"assoc",
|
41 |
+
"astuple",
|
42 |
+
"Attribute",
|
43 |
+
"AttrsInstance",
|
44 |
+
"cmp_using",
|
45 |
+
"converters",
|
46 |
+
"define",
|
47 |
+
"evolve",
|
48 |
+
"exceptions",
|
49 |
+
"Factory",
|
50 |
+
"field",
|
51 |
+
"fields_dict",
|
52 |
+
"fields",
|
53 |
+
"filters",
|
54 |
+
"frozen",
|
55 |
+
"has",
|
56 |
+
"make_class",
|
57 |
+
"mutable",
|
58 |
+
"NOTHING",
|
59 |
+
"resolve_types",
|
60 |
+
"setters",
|
61 |
+
"validate",
|
62 |
+
"validators",
|
63 |
+
]
|
64 |
+
|
65 |
+
__getattr__ = _make_getattr(__name__)
|
llmeval-env/lib/python3.10/site-packages/attrs/__init__.pyi
ADDED
@@ -0,0 +1,67 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from typing import (
|
2 |
+
Any,
|
3 |
+
Callable,
|
4 |
+
Dict,
|
5 |
+
Mapping,
|
6 |
+
Optional,
|
7 |
+
Sequence,
|
8 |
+
Tuple,
|
9 |
+
Type,
|
10 |
+
)
|
11 |
+
|
12 |
+
# Because we need to type our own stuff, we have to make everything from
|
13 |
+
# attr explicitly public too.
|
14 |
+
from attr import __author__ as __author__
|
15 |
+
from attr import __copyright__ as __copyright__
|
16 |
+
from attr import __description__ as __description__
|
17 |
+
from attr import __email__ as __email__
|
18 |
+
from attr import __license__ as __license__
|
19 |
+
from attr import __title__ as __title__
|
20 |
+
from attr import __url__ as __url__
|
21 |
+
from attr import __version__ as __version__
|
22 |
+
from attr import __version_info__ as __version_info__
|
23 |
+
from attr import _FilterType
|
24 |
+
from attr import assoc as assoc
|
25 |
+
from attr import Attribute as Attribute
|
26 |
+
from attr import AttrsInstance as AttrsInstance
|
27 |
+
from attr import cmp_using as cmp_using
|
28 |
+
from attr import converters as converters
|
29 |
+
from attr import define as define
|
30 |
+
from attr import evolve as evolve
|
31 |
+
from attr import exceptions as exceptions
|
32 |
+
from attr import Factory as Factory
|
33 |
+
from attr import field as field
|
34 |
+
from attr import fields as fields
|
35 |
+
from attr import fields_dict as fields_dict
|
36 |
+
from attr import filters as filters
|
37 |
+
from attr import frozen as frozen
|
38 |
+
from attr import has as has
|
39 |
+
from attr import make_class as make_class
|
40 |
+
from attr import mutable as mutable
|
41 |
+
from attr import NOTHING as NOTHING
|
42 |
+
from attr import resolve_types as resolve_types
|
43 |
+
from attr import setters as setters
|
44 |
+
from attr import validate as validate
|
45 |
+
from attr import validators as validators
|
46 |
+
|
47 |
+
# TODO: see definition of attr.asdict/astuple
|
48 |
+
def asdict(
|
49 |
+
inst: AttrsInstance,
|
50 |
+
recurse: bool = ...,
|
51 |
+
filter: Optional[_FilterType[Any]] = ...,
|
52 |
+
dict_factory: Type[Mapping[Any, Any]] = ...,
|
53 |
+
retain_collection_types: bool = ...,
|
54 |
+
value_serializer: Optional[
|
55 |
+
Callable[[type, Attribute[Any], Any], Any]
|
56 |
+
] = ...,
|
57 |
+
tuple_keys: bool = ...,
|
58 |
+
) -> Dict[str, Any]: ...
|
59 |
+
|
60 |
+
# TODO: add support for returning NamedTuple from the mypy plugin
|
61 |
+
def astuple(
|
62 |
+
inst: AttrsInstance,
|
63 |
+
recurse: bool = ...,
|
64 |
+
filter: Optional[_FilterType[Any]] = ...,
|
65 |
+
tuple_factory: Type[Sequence[Any]] = ...,
|
66 |
+
retain_collection_types: bool = ...,
|
67 |
+
) -> Tuple[Any, ...]: ...
|
llmeval-env/lib/python3.10/site-packages/attrs/converters.py
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
# SPDX-License-Identifier: MIT
|
2 |
+
|
3 |
+
from attr.converters import * # noqa: F403
|
llmeval-env/lib/python3.10/site-packages/attrs/filters.py
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
# SPDX-License-Identifier: MIT
|
2 |
+
|
3 |
+
from attr.filters import * # noqa: F403
|
llmeval-env/lib/python3.10/site-packages/attrs/py.typed
ADDED
File without changes
|
llmeval-env/lib/python3.10/site-packages/attrs/setters.py
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
# SPDX-License-Identifier: MIT
|
2 |
+
|
3 |
+
from attr.setters import * # noqa: F403
|
llmeval-env/lib/python3.10/site-packages/attrs/validators.py
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
# SPDX-License-Identifier: MIT
|
2 |
+
|
3 |
+
from attr.validators import * # noqa: F403
|
llmeval-env/lib/python3.10/site-packages/dill/__pycache__/__init__.cpython-310.pyc
ADDED
Binary file (3.67 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/dill/__pycache__/logger.cpython-310.pyc
ADDED
Binary file (8.87 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/dill/__pycache__/objtypes.cpython-310.pyc
ADDED
Binary file (540 Bytes). View file
|
|
llmeval-env/lib/python3.10/site-packages/dill/__pycache__/pointers.cpython-310.pyc
ADDED
Binary file (3.43 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/dill/__pycache__/settings.cpython-310.pyc
ADDED
Binary file (356 Bytes). View file
|
|
llmeval-env/lib/python3.10/site-packages/dill/__pycache__/source.cpython-310.pyc
ADDED
Binary file (25.9 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/dill/temp.py
ADDED
@@ -0,0 +1,252 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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-2024 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 |
+
Methods for serialized objects (or source code) stored in temporary files
|
10 |
+
and file-like objects.
|
11 |
+
"""
|
12 |
+
#XXX: better instead to have functions write to any given file-like object ?
|
13 |
+
#XXX: currently, all file-like objects are created by the function...
|
14 |
+
|
15 |
+
__all__ = ['dump_source', 'dump', 'dumpIO_source', 'dumpIO',\
|
16 |
+
'load_source', 'load', 'loadIO_source', 'loadIO',\
|
17 |
+
'capture']
|
18 |
+
|
19 |
+
import contextlib
|
20 |
+
|
21 |
+
|
22 |
+
@contextlib.contextmanager
|
23 |
+
def capture(stream='stdout'):
|
24 |
+
"""builds a context that temporarily replaces the given stream name
|
25 |
+
|
26 |
+
>>> with capture('stdout') as out:
|
27 |
+
... print ("foo!")
|
28 |
+
...
|
29 |
+
>>> print (out.getvalue())
|
30 |
+
foo!
|
31 |
+
|
32 |
+
"""
|
33 |
+
import sys
|
34 |
+
from io import StringIO
|
35 |
+
orig = getattr(sys, stream)
|
36 |
+
setattr(sys, stream, StringIO())
|
37 |
+
try:
|
38 |
+
yield getattr(sys, stream)
|
39 |
+
finally:
|
40 |
+
setattr(sys, stream, orig)
|
41 |
+
|
42 |
+
|
43 |
+
def b(x): # deal with b'foo' versus 'foo'
|
44 |
+
import codecs
|
45 |
+
return codecs.latin_1_encode(x)[0]
|
46 |
+
|
47 |
+
def load_source(file, **kwds):
|
48 |
+
"""load an object that was stored with dill.temp.dump_source
|
49 |
+
|
50 |
+
file: filehandle
|
51 |
+
alias: string name of stored object
|
52 |
+
mode: mode to open the file, one of: {'r', 'rb'}
|
53 |
+
|
54 |
+
>>> f = lambda x: x**2
|
55 |
+
>>> pyfile = dill.temp.dump_source(f, alias='_f')
|
56 |
+
>>> _f = dill.temp.load_source(pyfile)
|
57 |
+
>>> _f(4)
|
58 |
+
16
|
59 |
+
"""
|
60 |
+
alias = kwds.pop('alias', None)
|
61 |
+
mode = kwds.pop('mode', 'r')
|
62 |
+
fname = getattr(file, 'name', file) # fname=file.name or fname=file (if str)
|
63 |
+
source = open(fname, mode=mode, **kwds).read()
|
64 |
+
if not alias:
|
65 |
+
tag = source.strip().splitlines()[-1].split()
|
66 |
+
if tag[0] != '#NAME:':
|
67 |
+
stub = source.splitlines()[0]
|
68 |
+
raise IOError("unknown name for code: %s" % stub)
|
69 |
+
alias = tag[-1]
|
70 |
+
local = {}
|
71 |
+
exec(source, local)
|
72 |
+
_ = eval("%s" % alias, local)
|
73 |
+
return _
|
74 |
+
|
75 |
+
def dump_source(object, **kwds):
|
76 |
+
"""write object source to a NamedTemporaryFile (instead of dill.dump)
|
77 |
+
Loads with "import" or "dill.temp.load_source". Returns the filehandle.
|
78 |
+
|
79 |
+
>>> f = lambda x: x**2
|
80 |
+
>>> pyfile = dill.temp.dump_source(f, alias='_f')
|
81 |
+
>>> _f = dill.temp.load_source(pyfile)
|
82 |
+
>>> _f(4)
|
83 |
+
16
|
84 |
+
|
85 |
+
>>> f = lambda x: x**2
|
86 |
+
>>> pyfile = dill.temp.dump_source(f, dir='.')
|
87 |
+
>>> modulename = os.path.basename(pyfile.name).split('.py')[0]
|
88 |
+
>>> exec('from %s import f as _f' % modulename)
|
89 |
+
>>> _f(4)
|
90 |
+
16
|
91 |
+
|
92 |
+
Optional kwds:
|
93 |
+
If 'alias' is specified, the object will be renamed to the given string.
|
94 |
+
|
95 |
+
If 'prefix' is specified, the file name will begin with that prefix,
|
96 |
+
otherwise a default prefix is used.
|
97 |
+
|
98 |
+
If 'dir' is specified, the file will be created in that directory,
|
99 |
+
otherwise a default directory is used.
|
100 |
+
|
101 |
+
If 'text' is specified and true, the file is opened in text
|
102 |
+
mode. Else (the default) the file is opened in binary mode. On
|
103 |
+
some operating systems, this makes no difference.
|
104 |
+
|
105 |
+
NOTE: Keep the return value for as long as you want your file to exist !
|
106 |
+
""" #XXX: write a "load_source"?
|
107 |
+
from .source import importable, getname
|
108 |
+
import tempfile
|
109 |
+
kwds.setdefault('delete', True)
|
110 |
+
kwds.pop('suffix', '') # this is *always* '.py'
|
111 |
+
alias = kwds.pop('alias', '') #XXX: include an alias so a name is known
|
112 |
+
name = str(alias) or getname(object)
|
113 |
+
name = "\n#NAME: %s\n" % name
|
114 |
+
#XXX: assumes kwds['dir'] is writable and on $PYTHONPATH
|
115 |
+
file = tempfile.NamedTemporaryFile(suffix='.py', **kwds)
|
116 |
+
file.write(b(''.join([importable(object, alias=alias),name])))
|
117 |
+
file.flush()
|
118 |
+
return file
|
119 |
+
|
120 |
+
def load(file, **kwds):
|
121 |
+
"""load an object that was stored with dill.temp.dump
|
122 |
+
|
123 |
+
file: filehandle
|
124 |
+
mode: mode to open the file, one of: {'r', 'rb'}
|
125 |
+
|
126 |
+
>>> dumpfile = dill.temp.dump([1, 2, 3, 4, 5])
|
127 |
+
>>> dill.temp.load(dumpfile)
|
128 |
+
[1, 2, 3, 4, 5]
|
129 |
+
"""
|
130 |
+
import dill as pickle
|
131 |
+
mode = kwds.pop('mode', 'rb')
|
132 |
+
name = getattr(file, 'name', file) # name=file.name or name=file (if str)
|
133 |
+
return pickle.load(open(name, mode=mode, **kwds))
|
134 |
+
|
135 |
+
def dump(object, **kwds):
|
136 |
+
"""dill.dump of object to a NamedTemporaryFile.
|
137 |
+
Loads with "dill.temp.load". Returns the filehandle.
|
138 |
+
|
139 |
+
>>> dumpfile = dill.temp.dump([1, 2, 3, 4, 5])
|
140 |
+
>>> dill.temp.load(dumpfile)
|
141 |
+
[1, 2, 3, 4, 5]
|
142 |
+
|
143 |
+
Optional kwds:
|
144 |
+
If 'suffix' is specified, the file name will end with that suffix,
|
145 |
+
otherwise there will be no suffix.
|
146 |
+
|
147 |
+
If 'prefix' is specified, the file name will begin with that prefix,
|
148 |
+
otherwise a default prefix is used.
|
149 |
+
|
150 |
+
If 'dir' is specified, the file will be created in that directory,
|
151 |
+
otherwise a default directory is used.
|
152 |
+
|
153 |
+
If 'text' is specified and true, the file is opened in text
|
154 |
+
mode. Else (the default) the file is opened in binary mode. On
|
155 |
+
some operating systems, this makes no difference.
|
156 |
+
|
157 |
+
NOTE: Keep the return value for as long as you want your file to exist !
|
158 |
+
"""
|
159 |
+
import dill as pickle
|
160 |
+
import tempfile
|
161 |
+
kwds.setdefault('delete', True)
|
162 |
+
file = tempfile.NamedTemporaryFile(**kwds)
|
163 |
+
pickle.dump(object, file)
|
164 |
+
file.flush()
|
165 |
+
return file
|
166 |
+
|
167 |
+
def loadIO(buffer, **kwds):
|
168 |
+
"""load an object that was stored with dill.temp.dumpIO
|
169 |
+
|
170 |
+
buffer: buffer object
|
171 |
+
|
172 |
+
>>> dumpfile = dill.temp.dumpIO([1, 2, 3, 4, 5])
|
173 |
+
>>> dill.temp.loadIO(dumpfile)
|
174 |
+
[1, 2, 3, 4, 5]
|
175 |
+
"""
|
176 |
+
import dill as pickle
|
177 |
+
from io import BytesIO as StringIO
|
178 |
+
value = getattr(buffer, 'getvalue', buffer) # value or buffer.getvalue
|
179 |
+
if value != buffer: value = value() # buffer.getvalue()
|
180 |
+
return pickle.load(StringIO(value))
|
181 |
+
|
182 |
+
def dumpIO(object, **kwds):
|
183 |
+
"""dill.dump of object to a buffer.
|
184 |
+
Loads with "dill.temp.loadIO". Returns the buffer object.
|
185 |
+
|
186 |
+
>>> dumpfile = dill.temp.dumpIO([1, 2, 3, 4, 5])
|
187 |
+
>>> dill.temp.loadIO(dumpfile)
|
188 |
+
[1, 2, 3, 4, 5]
|
189 |
+
"""
|
190 |
+
import dill as pickle
|
191 |
+
from io import BytesIO as StringIO
|
192 |
+
file = StringIO()
|
193 |
+
pickle.dump(object, file)
|
194 |
+
file.flush()
|
195 |
+
return file
|
196 |
+
|
197 |
+
def loadIO_source(buffer, **kwds):
|
198 |
+
"""load an object that was stored with dill.temp.dumpIO_source
|
199 |
+
|
200 |
+
buffer: buffer object
|
201 |
+
alias: string name of stored object
|
202 |
+
|
203 |
+
>>> f = lambda x:x**2
|
204 |
+
>>> pyfile = dill.temp.dumpIO_source(f, alias='_f')
|
205 |
+
>>> _f = dill.temp.loadIO_source(pyfile)
|
206 |
+
>>> _f(4)
|
207 |
+
16
|
208 |
+
"""
|
209 |
+
alias = kwds.pop('alias', None)
|
210 |
+
source = getattr(buffer, 'getvalue', buffer) # source or buffer.getvalue
|
211 |
+
if source != buffer: source = source() # buffer.getvalue()
|
212 |
+
source = source.decode() # buffer to string
|
213 |
+
if not alias:
|
214 |
+
tag = source.strip().splitlines()[-1].split()
|
215 |
+
if tag[0] != '#NAME:':
|
216 |
+
stub = source.splitlines()[0]
|
217 |
+
raise IOError("unknown name for code: %s" % stub)
|
218 |
+
alias = tag[-1]
|
219 |
+
local = {}
|
220 |
+
exec(source, local)
|
221 |
+
_ = eval("%s" % alias, local)
|
222 |
+
return _
|
223 |
+
|
224 |
+
def dumpIO_source(object, **kwds):
|
225 |
+
"""write object source to a buffer (instead of dill.dump)
|
226 |
+
Loads by with dill.temp.loadIO_source. Returns the buffer object.
|
227 |
+
|
228 |
+
>>> f = lambda x:x**2
|
229 |
+
>>> pyfile = dill.temp.dumpIO_source(f, alias='_f')
|
230 |
+
>>> _f = dill.temp.loadIO_source(pyfile)
|
231 |
+
>>> _f(4)
|
232 |
+
16
|
233 |
+
|
234 |
+
Optional kwds:
|
235 |
+
If 'alias' is specified, the object will be renamed to the given string.
|
236 |
+
"""
|
237 |
+
from .source import importable, getname
|
238 |
+
from io import BytesIO as StringIO
|
239 |
+
alias = kwds.pop('alias', '') #XXX: include an alias so a name is known
|
240 |
+
name = str(alias) or getname(object)
|
241 |
+
name = "\n#NAME: %s\n" % name
|
242 |
+
#XXX: assumes kwds['dir'] is writable and on $PYTHONPATH
|
243 |
+
file = StringIO()
|
244 |
+
file.write(b(''.join([importable(object, alias=alias),name])))
|
245 |
+
file.flush()
|
246 |
+
return file
|
247 |
+
|
248 |
+
|
249 |
+
del contextlib
|
250 |
+
|
251 |
+
|
252 |
+
# EOF
|
llmeval-env/lib/python3.10/site-packages/dill/tests/__pycache__/__init__.cpython-310.pyc
ADDED
Binary file (386 Bytes). View file
|
|
llmeval-env/lib/python3.10/site-packages/dill/tests/__pycache__/__main__.cpython-310.pyc
ADDED
Binary file (763 Bytes). View file
|
|
llmeval-env/lib/python3.10/site-packages/dill/tests/__pycache__/test_abc.cpython-310.pyc
ADDED
Binary file (5.26 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/dill/tests/__pycache__/test_check.cpython-310.pyc
ADDED
Binary file (1.49 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/dill/tests/__pycache__/test_classdef.cpython-310.pyc
ADDED
Binary file (11.6 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/dill/tests/__pycache__/test_detect.cpython-310.pyc
ADDED
Binary file (5.11 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/dill/tests/__pycache__/test_dictviews.cpython-310.pyc
ADDED
Binary file (1.24 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/dill/tests/__pycache__/test_diff.cpython-310.pyc
ADDED
Binary file (1.54 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/dill/tests/__pycache__/test_extendpickle.cpython-310.pyc
ADDED
Binary file (1.29 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/dill/tests/__pycache__/test_file.cpython-310.pyc
ADDED
Binary file (7.08 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/dill/tests/__pycache__/test_functions.cpython-310.pyc
ADDED
Binary file (4.56 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/dill/tests/__pycache__/test_logger.cpython-310.pyc
ADDED
Binary file (1.96 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/dill/tests/__pycache__/test_mixins.cpython-310.pyc
ADDED
Binary file (4.7 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/dill/tests/__pycache__/test_module.cpython-310.pyc
ADDED
Binary file (1.75 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/dill/tests/__pycache__/test_nested.cpython-310.pyc
ADDED
Binary file (3.62 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/dill/tests/__pycache__/test_objects.cpython-310.pyc
ADDED
Binary file (1.9 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/dill/tests/__pycache__/test_properties.cpython-310.pyc
ADDED
Binary file (1.6 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/dill/tests/__pycache__/test_pycapsule.cpython-310.pyc
ADDED
Binary file (1.06 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/dill/tests/__pycache__/test_recursive.cpython-310.pyc
ADDED
Binary file (5.66 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/dill/tests/__pycache__/test_registered.cpython-310.pyc
ADDED
Binary file (1.51 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/dill/tests/__pycache__/test_restricted.cpython-310.pyc
ADDED
Binary file (988 Bytes). View file
|
|
llmeval-env/lib/python3.10/site-packages/dill/tests/__pycache__/test_selected.cpython-310.pyc
ADDED
Binary file (3.22 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/dill/tests/__pycache__/test_temp.cpython-310.pyc
ADDED
Binary file (3.13 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/dill/tests/__pycache__/test_weakref.cpython-310.pyc
ADDED
Binary file (1.75 kB). View file
|
|
llmeval-env/lib/python3.10/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-2024 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()
|
llmeval-env/lib/python3.10/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-2024 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()
|
llmeval-env/lib/python3.10/site-packages/dill/tests/test_detect.py
ADDED
@@ -0,0 +1,159 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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-2024 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 |
+
assert len(s) is len(a) # TypeError (and possibly PicklingError)
|
33 |
+
n = 2
|
34 |
+
assert len(a) is n if 'PicklingError' in a.keys() else n-1
|
35 |
+
|
36 |
+
def test_parent():
|
37 |
+
x = [4,5,6,7]
|
38 |
+
listiter = iter(x)
|
39 |
+
obj = parent(listiter, list)
|
40 |
+
assert obj is x
|
41 |
+
|
42 |
+
if IS_PYPY: assert parent(obj, int) is None
|
43 |
+
else: assert parent(obj, int) is x[-1] # python oddly? finds last int
|
44 |
+
assert at(id(at)) is at
|
45 |
+
|
46 |
+
a, b, c = 1, 2, 3
|
47 |
+
|
48 |
+
def squared(x):
|
49 |
+
return a+x**2
|
50 |
+
|
51 |
+
def foo(x):
|
52 |
+
def bar(y):
|
53 |
+
return squared(x)+y
|
54 |
+
return bar
|
55 |
+
|
56 |
+
class _class:
|
57 |
+
def _method(self):
|
58 |
+
pass
|
59 |
+
def ok(self):
|
60 |
+
return True
|
61 |
+
|
62 |
+
def test_globals():
|
63 |
+
def f():
|
64 |
+
a
|
65 |
+
def g():
|
66 |
+
b
|
67 |
+
def h():
|
68 |
+
c
|
69 |
+
assert globalvars(f) == dict(a=1, b=2, c=3)
|
70 |
+
|
71 |
+
res = globalvars(foo, recurse=True)
|
72 |
+
assert set(res) == set(['squared', 'a'])
|
73 |
+
res = globalvars(foo, recurse=False)
|
74 |
+
assert res == {}
|
75 |
+
zap = foo(2)
|
76 |
+
res = globalvars(zap, recurse=True)
|
77 |
+
assert set(res) == set(['squared', 'a'])
|
78 |
+
res = globalvars(zap, recurse=False)
|
79 |
+
assert set(res) == set(['squared'])
|
80 |
+
del zap
|
81 |
+
res = globalvars(squared)
|
82 |
+
assert set(res) == set(['a'])
|
83 |
+
# FIXME: should find referenced __builtins__
|
84 |
+
#res = globalvars(_class, recurse=True)
|
85 |
+
#assert set(res) == set(['True'])
|
86 |
+
#res = globalvars(_class, recurse=False)
|
87 |
+
#assert res == {}
|
88 |
+
#res = globalvars(_class.ok, recurse=True)
|
89 |
+
#assert set(res) == set(['True'])
|
90 |
+
#res = globalvars(_class.ok, recurse=False)
|
91 |
+
#assert set(res) == set(['True'])
|
92 |
+
|
93 |
+
|
94 |
+
#98 dill ignores __getstate__ in interactive lambdas
|
95 |
+
bar = [0]
|
96 |
+
|
97 |
+
class Foo(object):
|
98 |
+
def __init__(self):
|
99 |
+
pass
|
100 |
+
def __getstate__(self):
|
101 |
+
bar[0] = bar[0]+1
|
102 |
+
return {}
|
103 |
+
def __setstate__(self, data):
|
104 |
+
pass
|
105 |
+
|
106 |
+
f = Foo()
|
107 |
+
|
108 |
+
def test_getstate():
|
109 |
+
from dill import dumps, loads
|
110 |
+
dumps(f)
|
111 |
+
b = bar[0]
|
112 |
+
dumps(lambda: f, recurse=False) # doesn't call __getstate__
|
113 |
+
assert bar[0] == b
|
114 |
+
dumps(lambda: f, recurse=True) # calls __getstate__
|
115 |
+
assert bar[0] == b + 1
|
116 |
+
|
117 |
+
#97 serialize lambdas in test files
|
118 |
+
def test_deleted():
|
119 |
+
global sin
|
120 |
+
from dill import dumps, loads
|
121 |
+
from math import sin, pi
|
122 |
+
|
123 |
+
def sinc(x):
|
124 |
+
return sin(x)/x
|
125 |
+
|
126 |
+
settings['recurse'] = True
|
127 |
+
_sinc = dumps(sinc)
|
128 |
+
sin = globals().pop('sin')
|
129 |
+
sin = 1
|
130 |
+
del sin
|
131 |
+
sinc_ = loads(_sinc) # no NameError... pickling preserves 'sin'
|
132 |
+
res = sinc_(1)
|
133 |
+
from math import sin
|
134 |
+
assert sinc(1) == res
|
135 |
+
|
136 |
+
|
137 |
+
def test_lambdify():
|
138 |
+
try:
|
139 |
+
from sympy import symbols, lambdify
|
140 |
+
except ImportError:
|
141 |
+
return
|
142 |
+
settings['recurse'] = True
|
143 |
+
x = symbols("x")
|
144 |
+
y = x**2
|
145 |
+
f = lambdify([x], y)
|
146 |
+
z = min
|
147 |
+
d = globals()
|
148 |
+
globalvars(f, recurse=True, builtin=True)
|
149 |
+
assert z is min
|
150 |
+
assert d is globals()
|
151 |
+
|
152 |
+
|
153 |
+
if __name__ == '__main__':
|
154 |
+
test_bad_things()
|
155 |
+
test_parent()
|
156 |
+
test_globals()
|
157 |
+
test_getstate()
|
158 |
+
test_deleted()
|
159 |
+
test_lambdify()
|
llmeval-env/lib/python3.10/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-2024 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()
|
llmeval-env/lib/python3.10/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-2024 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()
|
llmeval-env/lib/python3.10/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 ([email protected])
|
5 |
+
# Copyright (c) 2022-2024 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()
|
llmeval-env/lib/python3.10/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-2024 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()
|
llmeval-env/lib/python3.10/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-2024 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()
|
llmeval-env/lib/python3.10/site-packages/dill/tests/test_weakref.py
ADDED
@@ -0,0 +1,72 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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-2024 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 |
+
import weakref
|
12 |
+
|
13 |
+
class _class:
|
14 |
+
def _method(self):
|
15 |
+
pass
|
16 |
+
|
17 |
+
class _callable_class:
|
18 |
+
def __call__(self):
|
19 |
+
pass
|
20 |
+
|
21 |
+
def _function():
|
22 |
+
pass
|
23 |
+
|
24 |
+
|
25 |
+
def test_weakref():
|
26 |
+
o = _class()
|
27 |
+
oc = _callable_class()
|
28 |
+
f = _function
|
29 |
+
x = _class
|
30 |
+
|
31 |
+
# ReferenceType
|
32 |
+
r = weakref.ref(o)
|
33 |
+
d_r = weakref.ref(_class())
|
34 |
+
fr = weakref.ref(f)
|
35 |
+
xr = weakref.ref(x)
|
36 |
+
|
37 |
+
# ProxyType
|
38 |
+
p = weakref.proxy(o)
|
39 |
+
d_p = weakref.proxy(_class())
|
40 |
+
|
41 |
+
# CallableProxyType
|
42 |
+
cp = weakref.proxy(oc)
|
43 |
+
d_cp = weakref.proxy(_callable_class())
|
44 |
+
fp = weakref.proxy(f)
|
45 |
+
xp = weakref.proxy(x)
|
46 |
+
|
47 |
+
objlist = [r,d_r,fr,xr, p,d_p, cp,d_cp,fp,xp]
|
48 |
+
#dill.detect.trace(True)
|
49 |
+
|
50 |
+
for obj in objlist:
|
51 |
+
res = dill.detect.errors(obj)
|
52 |
+
if res:
|
53 |
+
print ("%r:\n %s" % (obj, res))
|
54 |
+
# else:
|
55 |
+
# print ("PASS: %s" % obj)
|
56 |
+
assert not res
|
57 |
+
|
58 |
+
def test_dictproxy():
|
59 |
+
from dill._dill import DictProxyType
|
60 |
+
try:
|
61 |
+
m = DictProxyType({"foo": "bar"})
|
62 |
+
except Exception:
|
63 |
+
m = type.__dict__
|
64 |
+
mp = dill.copy(m)
|
65 |
+
assert mp.items() == m.items()
|
66 |
+
|
67 |
+
|
68 |
+
if __name__ == '__main__':
|
69 |
+
test_weakref()
|
70 |
+
from dill._dill import IS_PYPY
|
71 |
+
if not IS_PYPY:
|
72 |
+
test_dictproxy()
|
llmeval-env/lib/python3.10/site-packages/multidict/__init__.py
ADDED
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""Multidict implementation.
|
2 |
+
|
3 |
+
HTTP Headers and URL query string require specific data structure:
|
4 |
+
multidict. It behaves mostly like a dict but it can have
|
5 |
+
several values for the same key.
|
6 |
+
"""
|
7 |
+
|
8 |
+
from ._abc import MultiMapping, MutableMultiMapping
|
9 |
+
from ._compat import USE_EXTENSIONS
|
10 |
+
|
11 |
+
__all__ = (
|
12 |
+
"MultiMapping",
|
13 |
+
"MutableMultiMapping",
|
14 |
+
"MultiDictProxy",
|
15 |
+
"CIMultiDictProxy",
|
16 |
+
"MultiDict",
|
17 |
+
"CIMultiDict",
|
18 |
+
"upstr",
|
19 |
+
"istr",
|
20 |
+
"getversion",
|
21 |
+
)
|
22 |
+
|
23 |
+
__version__ = "6.0.5"
|
24 |
+
|
25 |
+
|
26 |
+
try:
|
27 |
+
if not USE_EXTENSIONS:
|
28 |
+
raise ImportError
|
29 |
+
from ._multidict import (
|
30 |
+
CIMultiDict,
|
31 |
+
CIMultiDictProxy,
|
32 |
+
MultiDict,
|
33 |
+
MultiDictProxy,
|
34 |
+
getversion,
|
35 |
+
istr,
|
36 |
+
)
|
37 |
+
except ImportError: # pragma: no cover
|
38 |
+
from ._multidict_py import (
|
39 |
+
CIMultiDict,
|
40 |
+
CIMultiDictProxy,
|
41 |
+
MultiDict,
|
42 |
+
MultiDictProxy,
|
43 |
+
getversion,
|
44 |
+
istr,
|
45 |
+
)
|
46 |
+
|
47 |
+
|
48 |
+
upstr = istr
|
llmeval-env/lib/python3.10/site-packages/multidict/__init__.pyi
ADDED
@@ -0,0 +1,152 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import abc
|
2 |
+
from typing import (
|
3 |
+
Generic,
|
4 |
+
Iterable,
|
5 |
+
Iterator,
|
6 |
+
Mapping,
|
7 |
+
MutableMapping,
|
8 |
+
TypeVar,
|
9 |
+
overload,
|
10 |
+
)
|
11 |
+
|
12 |
+
class istr(str): ...
|
13 |
+
|
14 |
+
upstr = istr
|
15 |
+
|
16 |
+
_S = str | istr
|
17 |
+
|
18 |
+
_T = TypeVar("_T")
|
19 |
+
|
20 |
+
_T_co = TypeVar("_T_co", covariant=True)
|
21 |
+
|
22 |
+
_D = TypeVar("_D")
|
23 |
+
|
24 |
+
class MultiMapping(Mapping[_S, _T_co]):
|
25 |
+
@overload
|
26 |
+
@abc.abstractmethod
|
27 |
+
def getall(self, key: _S) -> list[_T_co]: ...
|
28 |
+
@overload
|
29 |
+
@abc.abstractmethod
|
30 |
+
def getall(self, key: _S, default: _D) -> list[_T_co] | _D: ...
|
31 |
+
@overload
|
32 |
+
@abc.abstractmethod
|
33 |
+
def getone(self, key: _S) -> _T_co: ...
|
34 |
+
@overload
|
35 |
+
@abc.abstractmethod
|
36 |
+
def getone(self, key: _S, default: _D) -> _T_co | _D: ...
|
37 |
+
|
38 |
+
_Arg = (
|
39 |
+
Mapping[str, _T]
|
40 |
+
| Mapping[istr, _T]
|
41 |
+
| dict[str, _T]
|
42 |
+
| dict[istr, _T]
|
43 |
+
| MultiMapping[_T]
|
44 |
+
| Iterable[tuple[str, _T]]
|
45 |
+
| Iterable[tuple[istr, _T]]
|
46 |
+
)
|
47 |
+
|
48 |
+
class MutableMultiMapping(MultiMapping[_T], MutableMapping[_S, _T], Generic[_T]):
|
49 |
+
@abc.abstractmethod
|
50 |
+
def add(self, key: _S, value: _T) -> None: ...
|
51 |
+
@abc.abstractmethod
|
52 |
+
def extend(self, arg: _Arg[_T] = ..., **kwargs: _T) -> None: ...
|
53 |
+
@overload
|
54 |
+
@abc.abstractmethod
|
55 |
+
def popone(self, key: _S) -> _T: ...
|
56 |
+
@overload
|
57 |
+
@abc.abstractmethod
|
58 |
+
def popone(self, key: _S, default: _D) -> _T | _D: ...
|
59 |
+
@overload
|
60 |
+
@abc.abstractmethod
|
61 |
+
def popall(self, key: _S) -> list[_T]: ...
|
62 |
+
@overload
|
63 |
+
@abc.abstractmethod
|
64 |
+
def popall(self, key: _S, default: _D) -> list[_T] | _D: ...
|
65 |
+
|
66 |
+
class MultiDict(MutableMultiMapping[_T], Generic[_T]):
|
67 |
+
def __init__(self, arg: _Arg[_T] = ..., **kwargs: _T) -> None: ...
|
68 |
+
def copy(self) -> MultiDict[_T]: ...
|
69 |
+
def __getitem__(self, k: _S) -> _T: ...
|
70 |
+
def __setitem__(self, k: _S, v: _T) -> None: ...
|
71 |
+
def __delitem__(self, v: _S) -> None: ...
|
72 |
+
def __iter__(self) -> Iterator[_S]: ...
|
73 |
+
def __len__(self) -> int: ...
|
74 |
+
@overload
|
75 |
+
def getall(self, key: _S) -> list[_T]: ...
|
76 |
+
@overload
|
77 |
+
def getall(self, key: _S, default: _D) -> list[_T] | _D: ...
|
78 |
+
@overload
|
79 |
+
def getone(self, key: _S) -> _T: ...
|
80 |
+
@overload
|
81 |
+
def getone(self, key: _S, default: _D) -> _T | _D: ...
|
82 |
+
def add(self, key: _S, value: _T) -> None: ...
|
83 |
+
def extend(self, arg: _Arg[_T] = ..., **kwargs: _T) -> None: ...
|
84 |
+
@overload
|
85 |
+
def popone(self, key: _S) -> _T: ...
|
86 |
+
@overload
|
87 |
+
def popone(self, key: _S, default: _D) -> _T | _D: ...
|
88 |
+
@overload
|
89 |
+
def popall(self, key: _S) -> list[_T]: ...
|
90 |
+
@overload
|
91 |
+
def popall(self, key: _S, default: _D) -> list[_T] | _D: ...
|
92 |
+
|
93 |
+
class CIMultiDict(MutableMultiMapping[_T], Generic[_T]):
|
94 |
+
def __init__(self, arg: _Arg[_T] = ..., **kwargs: _T) -> None: ...
|
95 |
+
def copy(self) -> CIMultiDict[_T]: ...
|
96 |
+
def __getitem__(self, k: _S) -> _T: ...
|
97 |
+
def __setitem__(self, k: _S, v: _T) -> None: ...
|
98 |
+
def __delitem__(self, v: _S) -> None: ...
|
99 |
+
def __iter__(self) -> Iterator[_S]: ...
|
100 |
+
def __len__(self) -> int: ...
|
101 |
+
@overload
|
102 |
+
def getall(self, key: _S) -> list[_T]: ...
|
103 |
+
@overload
|
104 |
+
def getall(self, key: _S, default: _D) -> list[_T] | _D: ...
|
105 |
+
@overload
|
106 |
+
def getone(self, key: _S) -> _T: ...
|
107 |
+
@overload
|
108 |
+
def getone(self, key: _S, default: _D) -> _T | _D: ...
|
109 |
+
def add(self, key: _S, value: _T) -> None: ...
|
110 |
+
def extend(self, arg: _Arg[_T] = ..., **kwargs: _T) -> None: ...
|
111 |
+
@overload
|
112 |
+
def popone(self, key: _S) -> _T: ...
|
113 |
+
@overload
|
114 |
+
def popone(self, key: _S, default: _D) -> _T | _D: ...
|
115 |
+
@overload
|
116 |
+
def popall(self, key: _S) -> list[_T]: ...
|
117 |
+
@overload
|
118 |
+
def popall(self, key: _S, default: _D) -> list[_T] | _D: ...
|
119 |
+
|
120 |
+
class MultiDictProxy(MultiMapping[_T], Generic[_T]):
|
121 |
+
def __init__(self, arg: MultiMapping[_T] | MutableMultiMapping[_T]) -> None: ...
|
122 |
+
def copy(self) -> MultiDict[_T]: ...
|
123 |
+
def __getitem__(self, k: _S) -> _T: ...
|
124 |
+
def __iter__(self) -> Iterator[_S]: ...
|
125 |
+
def __len__(self) -> int: ...
|
126 |
+
@overload
|
127 |
+
def getall(self, key: _S) -> list[_T]: ...
|
128 |
+
@overload
|
129 |
+
def getall(self, key: _S, default: _D) -> list[_T] | _D: ...
|
130 |
+
@overload
|
131 |
+
def getone(self, key: _S) -> _T: ...
|
132 |
+
@overload
|
133 |
+
def getone(self, key: _S, default: _D) -> _T | _D: ...
|
134 |
+
|
135 |
+
class CIMultiDictProxy(MultiMapping[_T], Generic[_T]):
|
136 |
+
def __init__(self, arg: MultiMapping[_T] | MutableMultiMapping[_T]) -> None: ...
|
137 |
+
def __getitem__(self, k: _S) -> _T: ...
|
138 |
+
def __iter__(self) -> Iterator[_S]: ...
|
139 |
+
def __len__(self) -> int: ...
|
140 |
+
@overload
|
141 |
+
def getall(self, key: _S) -> list[_T]: ...
|
142 |
+
@overload
|
143 |
+
def getall(self, key: _S, default: _D) -> list[_T] | _D: ...
|
144 |
+
@overload
|
145 |
+
def getone(self, key: _S) -> _T: ...
|
146 |
+
@overload
|
147 |
+
def getone(self, key: _S, default: _D) -> _T | _D: ...
|
148 |
+
def copy(self) -> CIMultiDict[_T]: ...
|
149 |
+
|
150 |
+
def getversion(
|
151 |
+
md: MultiDict[_T] | CIMultiDict[_T] | MultiDictProxy[_T] | CIMultiDictProxy[_T],
|
152 |
+
) -> int: ...
|
llmeval-env/lib/python3.10/site-packages/multidict/__pycache__/__init__.cpython-310.pyc
ADDED
Binary file (865 Bytes). View file
|
|