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

zopefoundation / zope.component / 15267835484

27 May 2025 06:07AM UTC coverage: 99.774%. Remained the same
15267835484

Pull #76

github

web-flow
Trigger CI
Pull Request #76: Add preliminary support for Python 3.14

241 of 252 branches covered (95.63%)

Branch coverage included in aggregate %.

4615 of 4615 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/factory.py
1
##############################################################################
2
#
3
# Copyright (c) 2001, 2002 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
"""Factory object
15
"""
16
from zope.interface import implementedBy
1✔
17
from zope.interface import implementer
1✔
18
from zope.interface.declarations import Implements
1✔
19

20
from zope.component.interfaces import IFactory
1✔
21

22

23
@implementer(IFactory)
1✔
24
class Factory:
1✔
25
    """Generic factory implementation.
26

27
    The purpose of this implementation is to provide a quick way of creating
28
    factories for classes, functions and other objects.
29
    """
30

31
    def __init__(self, callable, title='', description='', interfaces=None):
1✔
32
        self._callable = callable
1✔
33
        self.title = title
1✔
34
        self.description = description
1✔
35
        self._interfaces = interfaces
1✔
36

37
    def __call__(self, *args, **kw):
1✔
38
        return self._callable(*args, **kw)
1✔
39

40
    def getInterfaces(self):
1✔
41
        if self._interfaces is not None:
1✔
42
            spec = Implements(*self._interfaces)
1✔
43
            spec.__name__ = getattr(self._callable, '__name__', '[callable]')
1✔
44
            return spec
1✔
45
        return implementedBy(self._callable)
1✔
46

47
    def __repr__(self):  # pragma: no cover
48
        return f'<{self.__class__.__name__} for {self._callable!r}>'
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