$56 GRAYBYTE WORDPRESS FILE MANAGER $76

SERVER : vnpttt-amd7f72-h1.vietnix.vn #1 SMP Fri May 24 12:42:50 UTC 2024
SERVER IP : 103.200.23.149 | ADMIN IP 216.73.216.22
OPTIONS : CRL = ON | WGT = ON | SDO = OFF | PKEX = OFF
DEACTIVATED : NONE

/opt/cloudlinux/venv/lib/python3.11/site-packages/pyrsistent/

HOME
Current File : /opt/cloudlinux/venv/lib/python3.11/site-packages/pyrsistent//_helpers.py
from functools import wraps
from pyrsistent._pmap import PMap, pmap
from pyrsistent._pset import PSet, pset
from pyrsistent._pvector import PVector, pvector

def freeze(o, strict=True):
    """
    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.

    If strict == True (default):

    - freeze is called on elements of pvectors
    - freeze is called on values of pmaps

    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 or (strict and isinstance(o, PMap)):
        return pmap({k: freeze(v, strict) for k, v in o.items()})
    if typ is list or (strict and isinstance(o, PVector)):
        curried_freeze = lambda x: freeze(x, strict)
        return pvector(map(curried_freeze, o))
    if typ is tuple:
        curried_freeze = lambda x: freeze(x, strict)
        return tuple(map(curried_freeze, o))
    if typ is set:
        # impossible to have anything that needs freezing inside a set or pset
        return pset(o)
    return o


def thaw(o, strict=True):
    """
    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.

    If strict == True (the default):

    - thaw is called on elements of lists
    - thaw is called on values in dicts

    >>> from pyrsistent import s, m, v
    >>> thaw(s(1, 2))
    {1, 2}
    >>> thaw(v(1, m(a=3)))
    [1, {'a': 3}]
    >>> thaw((1, v()))
    (1, [])
    """
    typ = type(o)
    if isinstance(o, PVector) or (strict and typ is list):
        curried_thaw = lambda x: thaw(x, strict)
        return list(map(curried_thaw, o))
    if isinstance(o, PMap) or (strict and typ is dict):
        return {k: thaw(v, strict) for k, v in o.items()}
    if typ is tuple:
        curried_thaw = lambda x: thaw(x, strict)
        return tuple(map(curried_thaw, o))
    if isinstance(o, PSet):
        # impossible to thaw inside psets or sets
        return set(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
..
--
17 Dec 2025 3.08 AM
root / root
0755
__pycache__
--
14 Aug 2025 9.25 PM
root / root
0755
__init__.py
1.444 KB
17 Apr 2025 8.10 PM
root / root
0644
__init__.pyi
7.02 KB
17 Apr 2025 8.10 PM
root / root
0644
_checked_types.py
17.941 KB
17 Apr 2025 8.10 PM
root / root
0644
_field_common.py
11.683 KB
17 Apr 2025 8.10 PM
root / root
0644
_helpers.py
3.156 KB
17 Apr 2025 8.10 PM
root / root
0644
_immutable.py
3.21 KB
17 Apr 2025 8.10 PM
root / root
0644
_pbag.py
6.572 KB
17 Apr 2025 8.10 PM
root / root
0644
_pclass.py
9.475 KB
17 Apr 2025 8.10 PM
root / root
0644
_pdeque.py
11.917 KB
17 Apr 2025 8.10 PM
root / root
0644
_plist.py
8.099 KB
17 Apr 2025 8.10 PM
root / root
0644
_pmap.py
18.341 KB
17 Apr 2025 8.10 PM
root / root
0644
_precord.py
6.867 KB
17 Apr 2025 8.10 PM
root / root
0644
_pset.py
5.56 KB
17 Apr 2025 8.10 PM
root / root
0644
_pvector.py
22.162 KB
17 Apr 2025 8.10 PM
root / root
0644
_toolz.py
3.345 KB
17 Apr 2025 8.10 PM
root / root
0644
_transformations.py
3.711 KB
17 Apr 2025 8.10 PM
root / root
0644
py.typed
0 KB
17 Apr 2025 8.10 PM
root / root
0644
typing.py
1.726 KB
17 Apr 2025 8.10 PM
root / root
0644
typing.pyi
10.172 KB
17 Apr 2025 8.10 PM
root / root
0644

GRAYBYTE WORDPRESS FILE MANAGER @ 2026 CONTACT ME
Static GIF