$68 GRAYBYTE WORDPRESS FILE MANAGER $49

SERVER : in-mum-web1330.main-hosting.eu #1 SMP Mon Feb 10 22:45:17 UTC 2025
SERVER IP : 147.79.69.210 | ADMIN IP 216.73.216.143
OPTIONS : CRL = ON | WGT = ON | SDO = OFF | PKEX = OFF
DEACTIVATED : NONE

/opt/alt/python37/lib64/python3.7/site-packages/pyrsistent/

HOME
Current File : /opt/alt/python37/lib64/python3.7/site-packages/pyrsistent//_helpers.py
from functools import wraps
import six
from pyrsistent._pmap import PMap, pmap
from pyrsistent._pset import PSet, pset
from pyrsistent._pvector import PVector, pvector


def freeze(o):
    """
    Recursively convert simple Python containers into pyrsistent versions
    of those containers.

    - list is converted to pvector, recursively
    - dict is converted to pmap, recursively on values (but not keys)
    - set is converted to pset, but not recursively
    - tuple is converted to tuple, recursively.

    Sets and dict keys are not recursively frozen because they do not contain
    mutable data by convention. The main exception to this rule is that
    dict keys and set elements are often instances of mutable objects that
    support hash-by-id, which this function can't convert anyway.

    >>> freeze(set([1, 2]))
    pset([1, 2])
    >>> freeze([1, {'a': 3}])
    pvector([1, pmap({'a': 3})])
    >>> freeze((1, []))
    (1, pvector([]))
    """
    typ = type(o)
    if typ is dict:
        return pmap(dict((k, freeze(v)) for k, v in six.iteritems(o)))
    if typ is list:
        return pvector(map(freeze, o))
    if typ is tuple:
        return tuple(map(freeze, o))
    if typ is set:
        return pset(o)
    return o


def thaw(o):
    """
    Recursively convert pyrsistent containers into simple Python containers.

    - pvector is converted to list, recursively
    - pmap is converted to dict, recursively on values (but not keys)
    - pset is converted to set, but not recursively
    - tuple is converted to tuple, recursively.

    >>> from pyrsistent import s, m, v
    >>> thaw(s(1, 2))
    set([1, 2])
    >>> thaw(v(1, m(a=3)))
    [1, {'a': 3}]
    >>> thaw((1, v()))
    (1, [])
    """
    if isinstance(o, PVector):
        return list(map(thaw, o))
    if isinstance(o, PMap):
        return dict((k, thaw(v)) for k, v in o.iteritems())
    if isinstance(o, PSet):
        return set(o)
    if type(o) is tuple:
        return tuple(map(thaw, o))
    return o


def mutant(fn):
    """
    Convenience decorator to isolate mutation to within the decorated function (with respect
    to the input arguments).

    All arguments to the decorated function will be frozen so that they are guaranteed not to change.
    The return value is also frozen.
    """
    @wraps(fn)
    def inner_f(*args, **kwargs):
        return freeze(fn(*[freeze(e) for e in args], **dict(freeze(item) for item in kwargs.items())))

    return inner_f

Current_dir [ NOT WRITEABLE ] Document_root [ WRITEABLE ]


[ Back ]
NAME
SIZE
LAST TOUCH
USER
CAN-I?
FUNCTIONS
..
--
28 Feb 2025 12.45 AM
root / 996
0755
__pycache__
--
25 Jan 2024 4.25 PM
root / 996
0755
__init__.py
1.444 KB
7 Jul 2018 1.53 PM
root / 996
0644
__init__.pyi
4.928 KB
19 Dec 2018 9.07 PM
root / 996
0644
_checked_types.py
17.883 KB
14 Oct 2018 10.06 AM
root / 996
0644
_compat.py
0.509 KB
14 Oct 2018 10.06 AM
root / 996
0644
_field_common.py
10.551 KB
14 Oct 2018 10.06 AM
root / 996
0644
_helpers.py
2.417 KB
7 Jul 2018 1.53 PM
root / 996
0644
_immutable.py
3.476 KB
8 Jul 2018 7.16 AM
root / 996
0644
_pbag.py
6.596 KB
14 Oct 2018 10.06 AM
root / 996
0644
_pclass.py
9.178 KB
17 Nov 2018 5.52 AM
root / 996
0644
_pdeque.py
11.898 KB
14 Oct 2018 10.06 AM
root / 996
0644
_plist.py
8.088 KB
14 Oct 2018 10.06 AM
root / 996
0644
_pmap.py
14.3 KB
14 Oct 2018 10.06 AM
root / 996
0644
_precord.py
6.42 KB
17 Nov 2018 5.52 AM
root / 996
0644
_pset.py
5.584 KB
14 Oct 2018 10.06 AM
root / 996
0644
_pvector.py
22.198 KB
14 Oct 2018 10.06 AM
root / 996
0644
_toolz.py
3.347 KB
7 Jul 2018 1.53 PM
root / 996
0644
_transformations.py
3.499 KB
7 Jul 2018 1.53 PM
root / 996
0644
py.typed
0 KB
20 Nov 2018 9.52 PM
root / 996
0644
typing.py
1.382 KB
17 Nov 2018 5.52 AM
root / 996
0644
typing.pyi
6.865 KB
20 Nov 2018 9.52 PM
root / 996
0644

GRAYBYTE WORDPRESS FILE MANAGER @ 2026 CONTACT ME
Static GIF