• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

zopefoundation / zope.hookable / 16098872535

17 Feb 2025 07:53AM UTC coverage: 100.0%. Remained the same
16098872535

push

github

web-flow
Update supported Python versions. (#43)

* Drop support for Python 3.8.
* Add preliminary support for Python 3.14.

51 of 51 branches covered (100.0%)

Branch coverage included in aggregate %.

173 of 173 relevant lines covered (100.0%)

6.99 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

100.0
/src/zope/hookable/__init__.py
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
7✔
15
"""
16
import os
7✔
17
import platform
7✔
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')
7✔
25
_PURE_PYTHON = os.environ.get('PURE_PYTHON') == '1'
7✔
26

27

28
class _py_hookable:
7✔
29
    __slots__ = ('_original', '_implementation')
7✔
30

31
    def __init__(self, *args, **kw):
7✔
32
        if not args and 'implementation' in kw:
7✔
33
            args = (kw.pop('implementation'),)
7✔
34
        if kw:
7✔
35
            raise TypeError('Unknown keyword arguments')
7✔
36
        if len(args) != 1:
7✔
37
            raise TypeError('Exactly one argument required')
7✔
38
        self._original = self._implementation = args[0]
7✔
39

40
    @property
7✔
41
    def original(self):
7✔
42
        return self._original
7✔
43

44
    @property
7✔
45
    def implementation(self):
7✔
46
        return self._implementation
7✔
47

48
    @property
7✔
49
    def __doc__(self):
7✔
50
        return self._original.__doc__
7✔
51

52
    @property
7✔
53
    def __dict__(self):
7✔
54
        return getattr(self._original, '__dict__', {})
7✔
55

56
    @property
7✔
57
    def __bases__(self):
7✔
58
        return getattr(self._original, '__bases__', ())
7✔
59

60
    def sethook(self, new_callable):
7✔
61
        old, self._implementation = self._implementation, new_callable
7✔
62
        return old
7✔
63

64
    def reset(self):
7✔
65
        self._implementation = self._original
7✔
66

67
    def __call__(self, *args, **kw):
7✔
68
        return self._implementation(*args, **kw)
7✔
69

70

71
try:
7✔
72
    from zope.hookable._zope_hookable import hookable as _c_hookable
7✔
73
except ModuleNotFoundError:  # pragma: no cover
74
    _c_hookable = None
75

76
if _PYPY_OR_JAVA or _PURE_PYTHON or _c_hookable is None:
7✔
77
    hookable = _py_hookable
7✔
78
else:  # pragma: no cover
79
    hookable = _c_hookable
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc