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

zopefoundation / zope.component / 6272867936

22 Sep 2023 10:01AM UTC coverage: 99.707% (-0.02%) from 99.727%
6272867936

Pull #72

github

dhavlik
Integrate .readthedocs.yaml.
Pull Request #72: Integrate .readthedocs.yaml.

460 of 475 branches covered (0.0%)

Branch coverage included in aggregate %.

4646 of 4646 relevant lines covered (100.0%)

1.0 hits per line

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

100.0
/src/zope/component/globalregistry.py
1
##############################################################################
2
#
3
# Copyright (c) 2006 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
"""Global components support
1✔
15
"""
16
from zope.interface.adapter import AdapterRegistry
1✔
17
from zope.interface.registry import Components
1✔
18

19
from zope.component.interfaces import inherits_arch_docs
1✔
20
from zope.component.interfaces import inherits_reg_docs
1✔
21

22

23
def GAR(components, registryName):
1✔
24
    return getattr(components, registryName)
1✔
25

26

27
class GlobalAdapterRegistry(AdapterRegistry):
1✔
28
    """A global adapter registry
29

30
    This adapter registry's main purpose is to be picklable in combination
31
    with a site manager."""
32

33
    def __init__(self, parent, name):
1✔
34
        self.__parent__ = parent
1✔
35
        self.__name__ = name
1✔
36
        super().__init__()
1✔
37

38
    def __reduce__(self):
1✔
39
        return GAR, (self.__parent__, self.__name__)
1✔
40

41

42
class BaseGlobalComponents(Components):
1✔
43

44
    def _init_registries(self):
1✔
45
        self.adapters = GlobalAdapterRegistry(self, 'adapters')
1✔
46
        self.utilities = GlobalAdapterRegistry(self, 'utilities')
1✔
47

48
    def __reduce__(self):
1✔
49
        # Global site managers are pickled as global objects
50
        return self.__name__
1✔
51

52

53
base = BaseGlobalComponents('base')
1✔
54

55
try:
1✔
56
    from zope.testing.cleanup import addCleanUp
1✔
57
except ImportError:  # pragma: no cover
58
    pass
59
else:
60
    addCleanUp(lambda: base.__init__('base'))
1✔
61
    del addCleanUp
1✔
62

63
globalSiteManager = base
1✔
64

65

66
@inherits_arch_docs
1✔
67
def getGlobalSiteManager():
1✔
68
    return globalSiteManager
1✔
69

70
# The following APIs provide global registration support for Python code.
71
# We eventually want to deprecate these in favor of using the global
72
# component registry directly.
73

74

75
@inherits_reg_docs
1✔
76
def provideUtility(component, provides=None, name=''):
1✔
77
    base.registerUtility(component, provides, name, event=False)
1✔
78

79

80
@inherits_reg_docs
1✔
81
def provideAdapter(factory, adapts=None, provides=None, name=''):
1✔
82
    base.registerAdapter(factory, adapts, provides, name, event=False)
1✔
83

84

85
@inherits_reg_docs
1✔
86
def provideSubscriptionAdapter(factory, adapts=None, provides=None):
1✔
87
    base.registerSubscriptionAdapter(factory, adapts, provides, event=False)
1✔
88

89

90
@inherits_reg_docs
1✔
91
def provideHandler(factory, adapts=None):
1✔
92
    base.registerHandler(factory, adapts, event=False)
1✔
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