retracesoftware-utils 0.1.25__cp311-cp311-macosx_11_0_arm64.whl → 0.2.6__cp311-cp311-macosx_11_0_arm64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- retracesoftware_utils-0.2.6.data/purelib/retracesoftware/utils.py +162 -0
- retracesoftware_utils-0.2.6.dist-info/METADATA +17 -0
- retracesoftware_utils-0.2.6.dist-info/RECORD +5 -0
- retracesoftware_utils-0.2.6.dist-info/WHEEL +4 -0
- retracesoftware_utils.cpython-311-darwin.so +0 -0
- retracesoftware_utils-0.1.25.data/purelib/retracesoftware/utils.py +0 -19
- retracesoftware_utils-0.1.25.dist-info/METADATA +0 -5
- retracesoftware_utils-0.1.25.dist-info/RECORD +0 -5
- retracesoftware_utils-0.1.25.dist-info/WHEEL +0 -6
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import retracesoftware_utils as _utils
|
|
2
|
+
from retracesoftware_utils import *
|
|
3
|
+
import weakref
|
|
4
|
+
import threading
|
|
5
|
+
from collections import UserDict
|
|
6
|
+
from typing import Callable, Any
|
|
7
|
+
from contextlib import contextmanager
|
|
8
|
+
|
|
9
|
+
def typeflags(cls):
|
|
10
|
+
|
|
11
|
+
bits = _utils.type_flags(cls)
|
|
12
|
+
|
|
13
|
+
result = set()
|
|
14
|
+
|
|
15
|
+
for name,value in _utils.TypeFlags.items():
|
|
16
|
+
if (value & bits) != 0:
|
|
17
|
+
result.add(name)
|
|
18
|
+
|
|
19
|
+
return result
|
|
20
|
+
|
|
21
|
+
def is_method_descriptor(obj):
|
|
22
|
+
return 'Py_TPFLAGS_METHOD_DESCRIPTOR' in typeflags(type(obj))
|
|
23
|
+
|
|
24
|
+
def flags(cls : type):
|
|
25
|
+
f = _utils.type_flags(cls)
|
|
26
|
+
|
|
27
|
+
s = set()
|
|
28
|
+
|
|
29
|
+
for name,value in _utils.TypeFlags.items():
|
|
30
|
+
if (f & value) != 0:
|
|
31
|
+
s.add(name)
|
|
32
|
+
f = f & ~value
|
|
33
|
+
|
|
34
|
+
if f != 0:
|
|
35
|
+
s.add(f)
|
|
36
|
+
|
|
37
|
+
return s
|
|
38
|
+
|
|
39
|
+
class WithoutFlags:
|
|
40
|
+
|
|
41
|
+
def __init__(self, cls , *flags):
|
|
42
|
+
self.cls = cls
|
|
43
|
+
self.flags = flags
|
|
44
|
+
|
|
45
|
+
def __enter__(self):
|
|
46
|
+
self.saved = utils.type_flags(self.cls)
|
|
47
|
+
flags = self.saved
|
|
48
|
+
|
|
49
|
+
for flag in self.flags:
|
|
50
|
+
flags = flags & ~_utils.TypeFlags[flag]
|
|
51
|
+
|
|
52
|
+
_utils.set_type_flags(self.cls, flags)
|
|
53
|
+
return self.cls
|
|
54
|
+
|
|
55
|
+
def __exit__(self, *args):
|
|
56
|
+
_utils.set_type_flags(self.cls, self.saved)
|
|
57
|
+
|
|
58
|
+
class WithFlags:
|
|
59
|
+
|
|
60
|
+
def __init__(self, cls , *flags):
|
|
61
|
+
self.cls = cls
|
|
62
|
+
self.flags = flags
|
|
63
|
+
|
|
64
|
+
def __enter__(self):
|
|
65
|
+
self.saved = _utils.type_flags(self.cls)
|
|
66
|
+
flags = self.saved
|
|
67
|
+
|
|
68
|
+
for flag in self.flags:
|
|
69
|
+
flags |= _utils.TypeFlags[flag]
|
|
70
|
+
|
|
71
|
+
_utils.set_type_flags(self.cls, flags)
|
|
72
|
+
return self.cls
|
|
73
|
+
|
|
74
|
+
def __exit__(self, *args):
|
|
75
|
+
_utils.set_type_flags(self.cls, self.saved)
|
|
76
|
+
|
|
77
|
+
def wrap_func_with_overrides(func, **overrides):
|
|
78
|
+
"""
|
|
79
|
+
Return a new function identical to `func` but with selected global names
|
|
80
|
+
overridden by keyword arguments.
|
|
81
|
+
|
|
82
|
+
Example:
|
|
83
|
+
new_func = wrap_func_with_overrides(old_func, exec=my_exec, print=my_print)
|
|
84
|
+
"""
|
|
85
|
+
|
|
86
|
+
import builtins as _builtins
|
|
87
|
+
import types
|
|
88
|
+
|
|
89
|
+
# Unwrap bound method if needed
|
|
90
|
+
orig = getattr(func, "__func__", func)
|
|
91
|
+
|
|
92
|
+
# Clone globals so we don't mutate the original module dict
|
|
93
|
+
g = dict(orig.__globals__)
|
|
94
|
+
g.setdefault("__builtins__", _builtins.__dict__)
|
|
95
|
+
g.update(overrides)
|
|
96
|
+
|
|
97
|
+
# Recreate the function
|
|
98
|
+
return types.FunctionType(
|
|
99
|
+
orig.__code__, g, orig.__name__, orig.__defaults__, orig.__closure__
|
|
100
|
+
)
|
|
101
|
+
|
|
102
|
+
def update(obj, name, f, *args, **kwargs):
|
|
103
|
+
value = getattr(obj, name)
|
|
104
|
+
setattr(obj, name, f(value, *args, **kwargs))
|
|
105
|
+
|
|
106
|
+
from typing import Dict, Any
|
|
107
|
+
|
|
108
|
+
class InterceptDict(dict):
|
|
109
|
+
def __init__(self, backing: Dict, on_set: Callable[[str, Any], Any]):
|
|
110
|
+
"""
|
|
111
|
+
A dictionary-like class that wraps an existing dictionary and calls a callback
|
|
112
|
+
to potentially modify values before they are added or updated.
|
|
113
|
+
|
|
114
|
+
Args:
|
|
115
|
+
underlying_dict: The existing dictionary to wrap and modify directly.
|
|
116
|
+
on_set: Function that takes (key, value) and returns the value to store.
|
|
117
|
+
*args: Iterable of key-value pairs to update the underlying dict.
|
|
118
|
+
**kwargs: Keyword arguments to update the underlying dict.
|
|
119
|
+
"""
|
|
120
|
+
super().__init__()
|
|
121
|
+
self.backing = backing
|
|
122
|
+
self.on_set = on_set
|
|
123
|
+
self.move_from_backing()
|
|
124
|
+
# self.fallback = initial
|
|
125
|
+
|
|
126
|
+
# store the dict version on the backing object
|
|
127
|
+
|
|
128
|
+
# Process additional items through the callback
|
|
129
|
+
# updates = dict(*args, **kwargs)
|
|
130
|
+
# for key, value in updates.items():
|
|
131
|
+
# modified_value = self.on_set(key, value)
|
|
132
|
+
# self._dict[key] = modified_value
|
|
133
|
+
|
|
134
|
+
def move_from_backing(self):
|
|
135
|
+
for key,value in self.backing.items():
|
|
136
|
+
super().__setitem__(key, self.on_set(key, value))
|
|
137
|
+
self.backing.clear()
|
|
138
|
+
|
|
139
|
+
def __getitem__(self, key):
|
|
140
|
+
self.move_from_backing()
|
|
141
|
+
return super().__getitem__(key)
|
|
142
|
+
|
|
143
|
+
def __setitem__(self, key: str, value: Any) -> None:
|
|
144
|
+
"""Set an item in the underlying dict, modifying the value via callback."""
|
|
145
|
+
self.move_from_backing()
|
|
146
|
+
super().__setitem__(key, self.on_set(key, value))
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
# def update(self, *args, **kwargs) -> None:
|
|
150
|
+
# """Update the underlying dict, processing values through the callback."""
|
|
151
|
+
# updates = dict(*args, **kwargs)
|
|
152
|
+
# for key, value in updates.items():
|
|
153
|
+
# self._dict[key] = self.on_set(key, value)
|
|
154
|
+
|
|
155
|
+
def map_values(f, m):
|
|
156
|
+
return {k: f(v) for k,v in m.items()}
|
|
157
|
+
|
|
158
|
+
@contextmanager
|
|
159
|
+
def on_set(dict, on_set):
|
|
160
|
+
_utils.intercept_dict_set(dict, on_set)
|
|
161
|
+
yield
|
|
162
|
+
_utils.intercept_dict_set(dict, None)
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: retracesoftware_utils
|
|
3
|
+
Version: 0.2.6
|
|
4
|
+
Keywords: functional,programming,c-extension,utilities,performance
|
|
5
|
+
Author-Email: Retrace Software <info@retracesoftware.com>
|
|
6
|
+
Maintainer-Email: Retrace Software <info@retracesoftware.com>
|
|
7
|
+
License: Apache-2.0
|
|
8
|
+
Classifier: Development Status :: 4 - Beta
|
|
9
|
+
Classifier: Intended Audience :: Developers
|
|
10
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
11
|
+
Classifier: Operating System :: OS Independent
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
14
|
+
Classifier: Programming Language :: Python :: Implementation :: CPython
|
|
15
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
16
|
+
Requires-Dist: retracesoftware.functional~=0.3.5
|
|
17
|
+
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
retracesoftware_utils.cpython-311-darwin.so,sha256=ON41vzeFsLSHp2mHZcZ1mYU-hf_JVBmjXemm0qG75cI,217368
|
|
2
|
+
retracesoftware_utils-0.2.6.data/purelib/retracesoftware/utils.py,sha256=oEvg-rvTXwum-rLKQ626ihr3A4XILdi-H3gGjnTTh9A,4641
|
|
3
|
+
retracesoftware_utils-0.2.6.dist-info/RECORD,,
|
|
4
|
+
retracesoftware_utils-0.2.6.dist-info/WHEEL,sha256=l2MAqKUavsDG6heQe7SYU4Wh2xM6nweWZlhq0Wt7Ao4,93
|
|
5
|
+
retracesoftware_utils-0.2.6.dist-info/METADATA,sha256=wFhSapOQL3txmNJUdzN9Q2BdAm-W802YaCCP7q6BFHo,763
|
|
Binary file
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import retracesoftware_utils as _utils
|
|
2
|
-
from retracesoftware_utils import *
|
|
3
|
-
import weakref
|
|
4
|
-
import threading
|
|
5
|
-
|
|
6
|
-
def typeflags(cls):
|
|
7
|
-
|
|
8
|
-
bits = _utils.type_flags(cls)
|
|
9
|
-
|
|
10
|
-
result = set()
|
|
11
|
-
|
|
12
|
-
for name,value in _utils.TypeFlags.items():
|
|
13
|
-
if (value & bits) != 0:
|
|
14
|
-
result.add(name)
|
|
15
|
-
|
|
16
|
-
return result
|
|
17
|
-
|
|
18
|
-
def is_method_descriptor(obj):
|
|
19
|
-
return 'Py_TPFLAGS_METHOD_DESCRIPTOR' in typeflags(type(obj))
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
retracesoftware_utils.cpython-311-darwin.so,sha256=DpIwiakhQv8ko6Y6TEhDae-q_ND5PEfIuK481uuKyvw,209688
|
|
2
|
-
retracesoftware_utils-0.1.25.dist-info/RECORD,,
|
|
3
|
-
retracesoftware_utils-0.1.25.dist-info/WHEEL,sha256=G_dfdI4VdFFEoV4o13vwbe2p3zT46AbukmXzkfYuyPI,122
|
|
4
|
-
retracesoftware_utils-0.1.25.dist-info/METADATA,sha256=3i7gYzKDYQW4V_yGdoqOvEBpycy_sMLqjV0Se5caDro,87
|
|
5
|
-
retracesoftware_utils-0.1.25.data/purelib/retracesoftware/utils.py,sha256=X_qz9-DI3dUBK_Pi7ed4vUVrBT9_mUA2cw9eJ8KiLd4,415
|