-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathinterfaces.py
More file actions
55 lines (40 loc) · 1.64 KB
/
interfaces.py
File metadata and controls
55 lines (40 loc) · 1.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
##############################################################################
#
# Copyright (c) 2006-2007 Zope Foundation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""Grok interfaces
"""
from zope.dottedname.resolve import resolve
from zope.interface import Attribute
from zope.interface import Interface
def api(name):
try:
return True, resolve(name)
except ModuleNotFoundError:
return False, Interface
HAVE_ROLE, IRole = api('zope.securitypolicy.interfaces.IRole')
class IBaseClasses(Interface):
Permission = Attribute("Base class for permissions.")
if HAVE_ROLE:
Role = Attribute("Base class for roles.")
class IDirectives(Interface):
def require(permission):
"""Protect a view class or an XMLRPC method with ``permission``.
``permission`` must already be defined, e.g. using
grok.Permission.
grok.require can be used as a class-level directive or as a
method decorator."""
def permissions(permissions):
"""Specify the permissions that comprise a role.
"""
class IGrokcoreSecurityAPI(IBaseClasses, IDirectives):
Public = Attribute("Permission identifier to denote public access.")