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

zopefoundation / zope.app.publisher / 16399746590

25 Jun 2025 07:15AM UTC coverage: 98.992%. Remained the same
16399746590

push

github

web-flow
Update Python version support. (#20)

* Drop support for Python 3.8.

39 of 44 branches covered (88.64%)

Branch coverage included in aggregate %.

452 of 452 relevant lines covered (100.0%)

1.0 hits per line

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

98.63
/src/zope/app/publisher/xmlrpc/metaconfigure.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
"""XMLRPC configuration code"""
15
from zope.component.interface import provideInterface
1✔
16
from zope.component.zcml import handler
1✔
17
from zope.configuration.exceptions import ConfigurationError
1✔
18
from zope.interface import Interface
1✔
19
from zope.publisher.interfaces.xmlrpc import IXMLRPCRequest
1✔
20
from zope.security.checker import Checker
1✔
21
from zope.security.checker import CheckerPublic
1✔
22
from zope.security.checker import getCheckerForInstancesOf
1✔
23

24
from zope.app.publisher.xmlrpc import MethodPublisher
1✔
25

26

27
def view(_context, for_=None, interface=None, methods=None,
1✔
28
         class_=None, permission=None, name=None):
29

30
    interface = interface or []
1✔
31
    methods = methods or []
1✔
32

33
    # If there were special permission settings provided, then use them
34
    if permission == 'zope.Public':
1✔
35
        permission = CheckerPublic
1✔
36

37
    require = {}
1✔
38
    for attr_name in methods:
1✔
39
        require[attr_name] = permission
1✔
40

41
    if interface:
1✔
42
        for iface in interface:
1✔
43
            for field_name in iface:
1✔
44
                require[field_name] = permission
1✔
45
            _context.action(
1✔
46
                discriminator=None,
47
                callable=provideInterface,
48
                args=('', for_)
49
            )
50

51
    # Make sure that the class inherits MethodPublisher, so that the views
52
    # have a location
53
    if class_ is None:
1✔
54
        class_ = original_class = MethodPublisher
1✔
55
    else:
56
        original_class = class_
1✔
57
        class_ = type(class_.__name__, (class_, MethodPublisher), {})
1✔
58

59
    if name:
1✔
60
        # Register a single view
61

62
        if permission:
1✔
63
            checker = Checker(require)
1✔
64

65
            def proxyView(context, request, class_=class_, checker=checker):
1✔
66
                view = class_(context, request)
1✔
67
                # We need this in case the resource gets unwrapped and
68
                # needs to be rewrapped
69
                view.__Security_checker__ = checker
1✔
70
                return view
1✔
71

72
            class_ = proxyView
1✔
73
            class_.factory = original_class
1✔
74
        else:
75
            # No permission was defined, so we defer to the checker
76
            # of the original class
77
            def proxyView(context, request, class_=class_):
1✔
78
                view = class_(context, request)
1✔
79
                view.__Security_checker__ = getCheckerForInstancesOf(
1✔
80
                    original_class)
81
                return view
1✔
82
            class_ = proxyView
1✔
83
            class_.factory = original_class
1✔
84

85
        # Register the new view.
86
        _context.action(
1✔
87
            discriminator=('view', for_, name, IXMLRPCRequest),
88
            callable=handler,
89
            args=('registerAdapter',
90
                  class_, (for_, IXMLRPCRequest), Interface, name,
91
                  _context.info)
92
        )
93
    else:
94
        if permission:
1✔
95
            checker = Checker({'__call__': permission})
1✔
96
        else:
97
            raise ConfigurationError(
1✔
98
                "XML/RPC view has neither a name nor a permission. "
99
                "You have to specify at least one of the two.")
100

101
        for name in require:
1✔
102
            # create a new callable class with a security checker;
103
            cdict = {'__Security_checker__': checker,
1✔
104
                     '__call__': getattr(class_, name)}
105
            new_class = type(class_.__name__, (class_,), cdict)
1✔
106
            _context.action(
1✔
107
                discriminator=('view', for_, name, IXMLRPCRequest),
108
                callable=handler,
109
                args=('registerAdapter',
110
                      new_class, (for_, IXMLRPCRequest), Interface, name,
111
                      _context.info)
112
            )
113

114
    # Register the used interfaces with the site manager
115
    if for_ is not None:
1!
116
        _context.action(
1✔
117
            discriminator=None,
118
            callable=provideInterface,
119
            args=('', for_)
120
        )
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