/usr/lib/python2.7/dist-packages/cement/core/interface.py is in python-cement 2.10.0-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 | """
Cement core interface module.
"""
from ..core import exc, backend
DEFAULT_META = ['interface', 'label', 'config_defaults', 'config_section']
def list():
"""
DEPRECATION WARNING: This function is deprecated as of Cement 2.9
in favor of the `CementApp.handler.list_types()` function, and will be
removed in future versions of Cement.
Return a list of defined interfaces (handler types).
:returns: List of defined interfaces
:rtype: ``list``
"""
# FIXME: Can't print a deprecation warning here because we don't have
# access to the app... and this is too deep to use minimal logger... ;\
return backend.__handlers__.keys()
class Interface(object):
"""
An interface definition class. All Interfaces should subclass from
here. Note that this is not an implementation and should never be
used directly.
"""
def __init__(self):
raise exc.InterfaceError("Interfaces can not be used directly.")
class Attribute(object):
"""
An interface attribute definition.
:param description: The description of the attribute.
"""
def __init__(self, description):
self.description = description
def __repr__(self):
return "<interface.Attribute - '%s'>" % self.description
def validate(interface, obj, members=[], meta=DEFAULT_META):
"""
A wrapper to validate interfaces.
:param interface: The interface class to validate against
:param obj: The object to validate.
:param members: The object members that must exist.
:param meta: The meta object members that must exist.
:raises: cement.core.exc.InterfaceError
"""
invalid = []
if hasattr(obj, '_meta') and interface != obj._meta.interface:
raise exc.InterfaceError("%s does not implement %s." %
(obj, interface))
for member in members:
if not hasattr(obj, member):
invalid.append(member)
if not hasattr(obj, '_meta'):
invalid.append("_meta")
else:
for member in meta:
if not hasattr(obj._meta, member):
invalid.append("_meta.%s" % member)
if invalid:
raise exc.InterfaceError("Invalid or missing: %s in %s" %
(invalid, obj))
|