/usr/lib/python2.7/dist-packages/kiwi/component.py is in python-kiwi 1.9.22-4.
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 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 | #
# Kiwi: a Framework and Enhanced Widgets for Python
#
# Copyright (C) 2006 Async Open Source
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
# USA
#
# Author(s): Johan Dahlin <jdahlin@async.com.br>
# Ali Afshar <aafshar@gmail.com>
import sys
from kiwi import ValueUnset
try:
from zope.interface import implements, Attribute, Interface
# pyflakes
implements, Attribute, Interface
except ImportError:
class Interface(object):
def providedBy(cls, impl):
candidates = (impl,) + impl.__class__.__bases__
for candidate in candidates:
for iface in getattr(candidate, '__interfaces__', []):
if issubclass(iface, cls):
return True
return False
providedBy = classmethod(providedBy)
class Attribute(object):
def __init__(self, __name__, __doc__=''):
self.__name__=__name__
self.__doc__=__doc__
def implements(iface):
frame = sys._getframe(1)
try:
frame.f_locals.setdefault('__interfaces__', []).append(iface)
finally:
del frame
class AlreadyImplementedError(Exception):
"""Called when a utility already exists."""
class _UtilityHandler(object):
def __init__(self):
self._utilities = {}
# FIXME: How to replace a utility properly
def provide(self, iface, obj, replace=False):
if not issubclass(iface, Interface):
raise TypeError(
"iface must be an Interface subclass and not %r" % iface)
if not replace:
if iface in self._utilities:
raise AlreadyImplementedError("%s is already implemented" % iface)
self._utilities[iface] = obj
def get(self, iface, default):
if not issubclass(iface, Interface):
raise TypeError(
"iface must be an Interface subclass and not %r" % iface)
if not iface in self._utilities:
if default is ValueUnset:
raise NotImplementedError("No utility provided for %r" % iface)
else:
return default
return self._utilities[iface]
def remove(self, iface):
if not issubclass(iface, Interface):
raise TypeError(
"iface must be an Interface subclass and not %r" % iface)
if not iface in self._utilities:
raise NotImplementedError("No utility provided for %r" % iface)
return self._utilities.pop(iface)
def clean(self):
self._utilities = {}
def provide_utility(iface, utility, replace=False):
"""
Set the utility for the named interface. If the utility is already
set, an {AlreadyImplementedError} is raised.
@param iface: interface to set the utility for.
@param utility: utility providing the interface.
"""
utilities.provide(iface, utility, replace)
def get_utility(iface, default=ValueUnset):
"""
Get the utility for the named interface. If the utility is not
available (has not been set) a {NotImplementedError} is raised unless
default is set.
@param iface: an interface
@param default: optional, if set return if a utility is not found
@returns: the utility
"""
return utilities.get(iface, default)
def remove_utility(iface):
"""
Remove the utility provided for an interface
If the utility is not available (has not been set)
{NotImplementedError} is raised.
@param iface: the interface
@returns: the removed utility
"""
return utilities.remove(iface)
utilities = _UtilityHandler()
|