zope.hookable 6.0__cp310-cp310-win_amd64.whl → 8.0__cp310-cp310-win_amd64.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.

Potentially problematic release.


This version of zope.hookable might be problematic. Click here for more details.

zope/hookable/__init__.py CHANGED
@@ -1,75 +1,79 @@
1
- ##############################################################################
2
- #
3
- # Copyright (c) 2003 Zope Foundation and Contributors.
4
- # All Rights Reserved.
5
- #
6
- # This software is subject to the provisions of the Zope Public License,
7
- # Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
8
- # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
9
- # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
10
- # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
11
- # FOR A PARTICULAR PURPOSE.
12
- #
13
- ##############################################################################
14
- """Hookable object support
15
- """
16
- import os
17
- import platform
18
-
19
-
20
- _PYPY = platform.python_implementation() in ('PyPy', 'Jython')
21
- _PURE_PYTHON = os.environ.get('PURE_PYTHON', _PYPY)
22
-
23
-
24
- class _py_hookable:
25
- __slots__ = ('_original', '_implementation')
26
-
27
- def __init__(self, *args, **kw):
28
- if not args and 'implementation' in kw:
29
- args = (kw.pop('implementation'),)
30
- if kw:
31
- raise TypeError('Unknown keyword arguments')
32
- if len(args) != 1:
33
- raise TypeError('Exactly one argument required')
34
- self._original = self._implementation = args[0]
35
-
36
- @property
37
- def original(self):
38
- return self._original
39
-
40
- @property
41
- def implementation(self):
42
- return self._implementation
43
-
44
- @property
45
- def __doc__(self):
46
- return self._original.__doc__
47
-
48
- @property
49
- def __dict__(self):
50
- return getattr(self._original, '__dict__', {})
51
-
52
- @property
53
- def __bases__(self):
54
- return getattr(self._original, '__bases__', ())
55
-
56
- def sethook(self, new_callable):
57
- old, self._implementation = self._implementation, new_callable
58
- return old
59
-
60
- def reset(self):
61
- self._implementation = self._original
62
-
63
- def __call__(self, *args, **kw):
64
- return self._implementation(*args, **kw)
65
-
66
-
67
- try:
68
- from zope.hookable._zope_hookable import hookable as _c_hookable
69
- except ImportError: # pragma: no cover
70
- _c_hookable = None
71
-
72
- if _PURE_PYTHON or _c_hookable is None:
73
- hookable = _py_hookable
74
- else: # pragma: no cover
75
- hookable = _c_hookable
1
+ ##############################################################################
2
+ #
3
+ # Copyright (c) 2003 Zope Foundation and Contributors.
4
+ # All Rights Reserved.
5
+ #
6
+ # This software is subject to the provisions of the Zope Public License,
7
+ # Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
8
+ # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
9
+ # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
10
+ # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
11
+ # FOR A PARTICULAR PURPOSE.
12
+ #
13
+ ##############################################################################
14
+ """Hookable object support
15
+ """
16
+ import os
17
+ import platform
18
+
19
+
20
+ # Keep these two flags separate: we want the `_PURE_PYTHON` one
21
+ # to represent that the flag is explicitly set to '1' in the environment,
22
+ # since our 'tox.ini' sets it to '0' for its environments which expect
23
+ # to test the C extension.
24
+ _PYPY_OR_JAVA = platform.python_implementation() in ('PyPy', 'Jython')
25
+ _PURE_PYTHON = os.environ.get('PURE_PYTHON') == '1'
26
+
27
+
28
+ class _py_hookable:
29
+ __slots__ = ('_original', '_implementation')
30
+
31
+ def __init__(self, *args, **kw):
32
+ if not args and 'implementation' in kw:
33
+ args = (kw.pop('implementation'),)
34
+ if kw:
35
+ raise TypeError('Unknown keyword arguments')
36
+ if len(args) != 1:
37
+ raise TypeError('Exactly one argument required')
38
+ self._original = self._implementation = args[0]
39
+
40
+ @property
41
+ def original(self):
42
+ return self._original
43
+
44
+ @property
45
+ def implementation(self):
46
+ return self._implementation
47
+
48
+ @property
49
+ def __doc__(self):
50
+ return self._original.__doc__
51
+
52
+ @property
53
+ def __dict__(self):
54
+ return getattr(self._original, '__dict__', {})
55
+
56
+ @property
57
+ def __bases__(self):
58
+ return getattr(self._original, '__bases__', ())
59
+
60
+ def sethook(self, new_callable):
61
+ old, self._implementation = self._implementation, new_callable
62
+ return old
63
+
64
+ def reset(self):
65
+ self._implementation = self._original
66
+
67
+ def __call__(self, *args, **kw):
68
+ return self._implementation(*args, **kw)
69
+
70
+
71
+ try:
72
+ from zope.hookable._zope_hookable import hookable as _c_hookable
73
+ except ModuleNotFoundError: # pragma: no cover
74
+ _c_hookable = None
75
+
76
+ if _PYPY_OR_JAVA or _PURE_PYTHON or _c_hookable is None:
77
+ hookable = _py_hookable
78
+ else: # pragma: no cover
79
+ hookable = _c_hookable