$90 GRAYBYTE WORDPRESS FILE MANAGER $67

SERVER : in-mum-web1330.main-hosting.eu #1 SMP Mon Feb 10 22:45:17 UTC 2025
SERVER IP : 147.79.69.231 | ADMIN IP 216.73.216.215
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//_transformations.py
import re
import six
try:
    from inspect import Parameter, signature
except ImportError:
    signature = None
    try:
        from inspect import getfullargspec as getargspec
    except ImportError:
        from inspect import getargspec


def inc(x):
    """ Add one to the current value """
    return x + 1


def dec(x):
    """ Subtract one from the current value """
    return x - 1


def discard(evolver, key):
    """ Discard the element and returns a structure without the discarded elements """
    try:
        del evolver[key]
    except KeyError:
        pass


# Matchers
def rex(expr):
    """ Regular expression matcher to use together with transform functions """
    r = re.compile(expr)
    return lambda key: isinstance(key, six.string_types) and r.match(key)


def ny(_):
    """ Matcher that matches any value """
    return True

# Support functions
def _chunks(l, n):
    for i in range(0, len(l), n):
        yield l[i:i + n]


def transform(structure, transformations):
    r = structure
    for path, command in _chunks(transformations, 2):
        r = _do_to_path(r, path, command)
    return r


def _do_to_path(structure, path, command):
    if not path:
        return command(structure) if callable(command) else command

    kvs = _get_keys_and_values(structure, path[0])
    return _update_structure(structure, kvs, path[1:], command)


def _items(structure):
    try:
        return structure.items()
    except AttributeError:
        # Support wider range of structures by adding a transform_items() or similar?
        return list(enumerate(structure))


def _get(structure, key, default):
    try:
        if hasattr(structure, '__getitem__'):
            return structure[key]

        return getattr(structure, key)

    except (IndexError, KeyError):
        return default


def _get_keys_and_values(structure, key_spec):
    from pyrsistent._pmap import pmap
    if callable(key_spec):
        # Support predicates as callable objects in the path
        arity = _get_arity(key_spec)
        if arity == 1:
            # Unary predicates are called with the "key" of the path
            # - eg a key in a mapping, an index in a sequence.
            return [(k, v) for k, v in _items(structure) if key_spec(k)]
        elif arity == 2:
            # Binary predicates are called with the key and the corresponding
            # value.
            return [(k, v) for k, v in _items(structure) if key_spec(k, v)]
        else:
            # Other arities are an error.
            raise ValueError(
                "callable in transform path must take 1 or 2 arguments"
            )

    # Non-callables are used as-is as a key.
    return [(key_spec, _get(structure, key_spec, pmap()))]


if signature is None:
    def _get_arity(f):
        argspec = getargspec(f)
        return len(argspec.args) - len(argspec.defaults or ())
else:
    def _get_arity(f):
        return sum(
            1
            for p
            in signature(f).parameters.values()
            if p.default is Parameter.empty
            and p.kind in (Parameter.POSITIONAL_ONLY, Parameter.POSITIONAL_OR_KEYWORD)
        )

def _update_structure(structure, kvs, path, command):
    e = structure.evolver()
    if not path and command is discard:
        # Do this in reverse to avoid index problems with vectors. See #92.
        for k, v in reversed(kvs):
            discard(e, k)
    else:
        for k, v in kvs:
            result = _do_to_path(v, path, command)
            if result is not v:
                e[k] = result

    return e.persistent()

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