OXIESEC PANEL
- Current Dir:
/
/
snap
/
core20
/
2599
/
usr
/
lib
/
python3
/
dist-packages
/
pyrsistent
Server IP: 139.59.38.164
Upload:
Create Dir:
Name
Size
Modified
Perms
📁
..
-
05/26/2025 10:13:33 PM
rwxr-xr-x
📄
__init__.py
1.44 KB
07/07/2018 01:53:48 PM
rw-r--r--
📄
__init__.pyi
7.08 KB
05/11/2019 04:41:48 AM
rw-r--r--
📁
__pycache__
-
05/26/2025 10:13:33 PM
rwxr-xr-x
📄
_checked_types.py
17.93 KB
10/27/2019 08:31:27 PM
rw-r--r--
📄
_compat.py
521 bytes
10/14/2018 10:06:35 AM
rw-r--r--
📄
_field_common.py
11.18 KB
10/27/2019 08:31:27 PM
rw-r--r--
📄
_helpers.py
2.42 KB
07/07/2018 01:53:48 PM
rw-r--r--
📄
_immutable.py
3.48 KB
07/08/2018 07:16:39 AM
rw-r--r--
📄
_pbag.py
6.6 KB
10/14/2018 10:06:35 AM
rw-r--r--
📄
_pclass.py
9.49 KB
05/12/2019 12:07:03 PM
rw-r--r--
📄
_pdeque.py
11.9 KB
10/14/2018 10:06:35 AM
rw-r--r--
📄
_plist.py
8.09 KB
10/14/2018 10:06:35 AM
rw-r--r--
📄
_pmap.py
14.3 KB
10/27/2019 08:31:23 PM
rw-r--r--
📄
_precord.py
6.85 KB
05/12/2019 12:07:03 PM
rw-r--r--
📄
_pset.py
5.58 KB
10/14/2018 10:06:35 AM
rw-r--r--
📄
_pvector.py
22.18 KB
07/04/2019 08:05:29 PM
rw-r--r--
📄
_toolz.py
3.35 KB
07/07/2018 01:53:48 PM
rw-r--r--
📄
_transformations.py
3.82 KB
05/11/2019 06:24:44 AM
rw-r--r--
📄
py.typed
0 bytes
11/20/2018 09:52:04 PM
rw-r--r--
📄
typing.py
1.69 KB
04/25/2019 07:49:19 PM
rw-r--r--
📄
typing.pyi
10.14 KB
07/04/2019 08:22:31 PM
rw-r--r--
Editing: _transformations.py
Close
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 _EMPTY_SENTINEL = object() 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): 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, _EMPTY_SENTINEL))] 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): from pyrsistent._pmap import pmap 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: is_empty = False if v is _EMPTY_SENTINEL: # Allow expansion of structure but make sure to cover the case # when an empty pmap is added as leaf node. See #154. is_empty = True v = pmap() result = _do_to_path(v, path, command) if result is not v or is_empty: e[k] = result return e.persistent()