interfaces.py 52 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593
  1. ##############################################################################
  2. #
  3. # Copyright (c) 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. """Interface Package Interfaces
  15. """
  16. __docformat__ = 'restructuredtext'
  17. from zope.interface.interface import Attribute
  18. from zope.interface.interface import Interface
  19. from zope.interface.declarations import implementer
  20. __all__ = [
  21. 'ComponentLookupError',
  22. 'IAdapterRegistration',
  23. 'IAdapterRegistry',
  24. 'IAttribute',
  25. 'IComponentLookup',
  26. 'IComponentRegistry',
  27. 'IComponents',
  28. 'IDeclaration',
  29. 'IElement',
  30. 'IHandlerRegistration',
  31. 'IInterface',
  32. 'IInterfaceDeclaration',
  33. 'IMethod',
  34. 'Invalid',
  35. 'IObjectEvent',
  36. 'IRegistered',
  37. 'IRegistration',
  38. 'IRegistrationEvent',
  39. 'ISpecification',
  40. 'ISubscriptionAdapterRegistration',
  41. 'IUnregistered',
  42. 'IUtilityRegistration',
  43. 'ObjectEvent',
  44. 'Registered',
  45. 'Unregistered',
  46. ]
  47. # pylint:disable=inherit-non-class,no-method-argument,no-self-argument
  48. # pylint:disable=unexpected-special-method-signature
  49. # pylint:disable=too-many-lines
  50. class IElement(Interface):
  51. """
  52. Objects that have basic documentation and tagged values.
  53. Known derivatives include :class:`IAttribute` and its derivative
  54. :class:`IMethod`; these have no notion of inheritance.
  55. :class:`IInterface` is also a derivative, and it does have a
  56. notion of inheritance, expressed through its ``__bases__`` and
  57. ordered in its ``__iro__`` (both defined by
  58. :class:`ISpecification`).
  59. """
  60. # pylint:disable=arguments-differ
  61. # Note that defining __doc__ as an Attribute hides the docstring
  62. # from introspection. When changing it, also change it in the Sphinx
  63. # ReST files.
  64. __name__ = Attribute('__name__', 'The object name')
  65. __doc__ = Attribute('__doc__', 'The object doc string')
  66. ###
  67. # Tagged values.
  68. #
  69. # Direct values are established in this instance. Others may be
  70. # inherited. Although ``IElement`` itself doesn't have a notion of
  71. # inheritance, ``IInterface`` *does*. It might have been better to
  72. # make ``IInterface`` define new methods
  73. # ``getIndirectTaggedValue``, etc, to include inheritance instead
  74. # of overriding ``getTaggedValue`` to do that, but that ship has sailed.
  75. # So to keep things nice and symmetric, we define the ``Direct`` methods here.
  76. ###
  77. def getTaggedValue(tag):
  78. """Returns the value associated with *tag*.
  79. Raise a `KeyError` if the tag isn't set.
  80. If the object has a notion of inheritance, this searches
  81. through the inheritance hierarchy and returns the nearest result.
  82. If there is no such notion, this looks only at this object.
  83. .. versionchanged:: 4.7.0
  84. This method should respect inheritance if present.
  85. """
  86. def queryTaggedValue(tag, default=None):
  87. """
  88. As for `getTaggedValue`, but instead of raising a `KeyError`, returns *default*.
  89. .. versionchanged:: 4.7.0
  90. This method should respect inheritance if present.
  91. """
  92. def getTaggedValueTags():
  93. """
  94. Returns a collection of all tags in no particular order.
  95. If the object has a notion of inheritance, this
  96. includes all the inherited tagged values. If there is
  97. no such notion, this looks only at this object.
  98. .. versionchanged:: 4.7.0
  99. This method should respect inheritance if present.
  100. """
  101. def setTaggedValue(tag, value):
  102. """
  103. Associates *value* with *key* directly in this object.
  104. """
  105. def getDirectTaggedValue(tag):
  106. """
  107. As for `getTaggedValue`, but never includes inheritance.
  108. .. versionadded:: 5.0.0
  109. """
  110. def queryDirectTaggedValue(tag, default=None):
  111. """
  112. As for `queryTaggedValue`, but never includes inheritance.
  113. .. versionadded:: 5.0.0
  114. """
  115. def getDirectTaggedValueTags():
  116. """
  117. As for `getTaggedValueTags`, but includes only tags directly
  118. set on this object.
  119. .. versionadded:: 5.0.0
  120. """
  121. class IAttribute(IElement):
  122. """Attribute descriptors"""
  123. interface = Attribute('interface',
  124. 'Stores the interface instance in which the '
  125. 'attribute is located.')
  126. class IMethod(IAttribute):
  127. """Method attributes"""
  128. def getSignatureInfo():
  129. """Returns the signature information.
  130. This method returns a dictionary with the following string keys:
  131. - positional
  132. A sequence of the names of positional arguments.
  133. - required
  134. A sequence of the names of required arguments.
  135. - optional
  136. A dictionary mapping argument names to their default values.
  137. - varargs
  138. The name of the varargs argument (or None).
  139. - kwargs
  140. The name of the kwargs argument (or None).
  141. """
  142. def getSignatureString():
  143. """Return a signature string suitable for inclusion in documentation.
  144. This method returns the function signature string. For example, if you
  145. have ``def func(a, b, c=1, d='f')``, then the signature string is ``"(a, b,
  146. c=1, d='f')"``.
  147. """
  148. class ISpecification(Interface):
  149. """Object Behavioral specifications"""
  150. # pylint:disable=arguments-differ
  151. def providedBy(object): # pylint:disable=redefined-builtin
  152. """Test whether the interface is implemented by the object
  153. Return true of the object asserts that it implements the
  154. interface, including asserting that it implements an extended
  155. interface.
  156. """
  157. def implementedBy(class_):
  158. """Test whether the interface is implemented by instances of the class
  159. Return true of the class asserts that its instances implement the
  160. interface, including asserting that they implement an extended
  161. interface.
  162. """
  163. def isOrExtends(other):
  164. """Test whether the specification is or extends another
  165. """
  166. def extends(other, strict=True):
  167. """Test whether a specification extends another
  168. The specification extends other if it has other as a base
  169. interface or if one of it's bases extends other.
  170. If strict is false, then the specification extends itself.
  171. """
  172. def weakref(callback=None):
  173. """Return a weakref to the specification
  174. This method is, regrettably, needed to allow weakrefs to be
  175. computed to security-proxied specifications. While the
  176. zope.interface package does not require zope.security or
  177. zope.proxy, it has to be able to coexist with it.
  178. """
  179. __bases__ = Attribute("""Base specifications
  180. A tuple of specifications from which this specification is
  181. directly derived.
  182. """)
  183. __sro__ = Attribute("""Specification-resolution order
  184. A tuple of the specification and all of it's ancestor
  185. specifications from most specific to least specific. The specification
  186. itself is the first element.
  187. (This is similar to the method-resolution order for new-style classes.)
  188. """)
  189. __iro__ = Attribute("""Interface-resolution order
  190. A tuple of the specification's ancestor interfaces from
  191. most specific to least specific. The specification itself is
  192. included if it is an interface.
  193. (This is similar to the method-resolution order for new-style classes.)
  194. """)
  195. def get(name, default=None):
  196. """Look up the description for a name
  197. If the named attribute is not defined, the default is
  198. returned.
  199. """
  200. class IInterface(ISpecification, IElement):
  201. """Interface objects
  202. Interface objects describe the behavior of an object by containing
  203. useful information about the object. This information includes:
  204. - Prose documentation about the object. In Python terms, this
  205. is called the "doc string" of the interface. In this element,
  206. you describe how the object works in prose language and any
  207. other useful information about the object.
  208. - Descriptions of attributes. Attribute descriptions include
  209. the name of the attribute and prose documentation describing
  210. the attributes usage.
  211. - Descriptions of methods. Method descriptions can include:
  212. - Prose "doc string" documentation about the method and its
  213. usage.
  214. - A description of the methods arguments; how many arguments
  215. are expected, optional arguments and their default values,
  216. the position or arguments in the signature, whether the
  217. method accepts arbitrary arguments and whether the method
  218. accepts arbitrary keyword arguments.
  219. - Optional tagged data. Interface objects (and their attributes and
  220. methods) can have optional, application specific tagged data
  221. associated with them. Examples uses for this are examples,
  222. security assertions, pre/post conditions, and other possible
  223. information you may want to associate with an Interface or its
  224. attributes.
  225. Not all of this information is mandatory. For example, you may
  226. only want the methods of your interface to have prose
  227. documentation and not describe the arguments of the method in
  228. exact detail. Interface objects are flexible and let you give or
  229. take any of these components.
  230. Interfaces are created with the Python class statement using
  231. either `zope.interface.Interface` or another interface, as in::
  232. from zope.interface import Interface
  233. class IMyInterface(Interface):
  234. '''Interface documentation'''
  235. def meth(arg1, arg2):
  236. '''Documentation for meth'''
  237. # Note that there is no self argument
  238. class IMySubInterface(IMyInterface):
  239. '''Interface documentation'''
  240. def meth2():
  241. '''Documentation for meth2'''
  242. You use interfaces in two ways:
  243. - You assert that your object implement the interfaces.
  244. There are several ways that you can declare that an object
  245. provides an interface:
  246. 1. Call `zope.interface.implementer` on your class definition.
  247. 2. Call `zope.interface.directlyProvides` on your object.
  248. 3. Call `zope.interface.classImplements` to declare that instances
  249. of a class implement an interface.
  250. For example::
  251. from zope.interface import classImplements
  252. classImplements(some_class, some_interface)
  253. This approach is useful when it is not an option to modify
  254. the class source. Note that this doesn't affect what the
  255. class itself implements, but only what its instances
  256. implement.
  257. - You query interface meta-data. See the IInterface methods and
  258. attributes for details.
  259. """
  260. # pylint:disable=arguments-differ
  261. def names(all=False): # pylint:disable=redefined-builtin
  262. """Get the interface attribute names
  263. Return a collection of the names of the attributes, including
  264. methods, included in the interface definition.
  265. Normally, only directly defined attributes are included. If
  266. a true positional or keyword argument is given, then
  267. attributes defined by base classes will be included.
  268. """
  269. def namesAndDescriptions(all=False): # pylint:disable=redefined-builtin
  270. """Get the interface attribute names and descriptions
  271. Return a collection of the names and descriptions of the
  272. attributes, including methods, as name-value pairs, included
  273. in the interface definition.
  274. Normally, only directly defined attributes are included. If
  275. a true positional or keyword argument is given, then
  276. attributes defined by base classes will be included.
  277. """
  278. def __getitem__(name):
  279. """Get the description for a name
  280. If the named attribute is not defined, a `KeyError` is raised.
  281. """
  282. def direct(name):
  283. """Get the description for the name if it was defined by the interface
  284. If the interface doesn't define the name, returns None.
  285. """
  286. def validateInvariants(obj, errors=None):
  287. """Validate invariants
  288. Validate object to defined invariants. If errors is None,
  289. raises first Invalid error; if errors is a list, appends all errors
  290. to list, then raises Invalid with the errors as the first element
  291. of the "args" tuple."""
  292. def __contains__(name):
  293. """Test whether the name is defined by the interface"""
  294. def __iter__():
  295. """Return an iterator over the names defined by the interface
  296. The names iterated include all of the names defined by the
  297. interface directly and indirectly by base interfaces.
  298. """
  299. __module__ = Attribute("""The name of the module defining the interface""")
  300. class IDeclaration(ISpecification):
  301. """Interface declaration
  302. Declarations are used to express the interfaces implemented by
  303. classes or provided by objects.
  304. """
  305. def __contains__(interface):
  306. """Test whether an interface is in the specification
  307. Return true if the given interface is one of the interfaces in
  308. the specification and false otherwise.
  309. """
  310. def __iter__():
  311. """Return an iterator for the interfaces in the specification
  312. """
  313. def flattened():
  314. """Return an iterator of all included and extended interfaces
  315. An iterator is returned for all interfaces either included in
  316. or extended by interfaces included in the specifications
  317. without duplicates. The interfaces are in "interface
  318. resolution order". The interface resolution order is such that
  319. base interfaces are listed after interfaces that extend them
  320. and, otherwise, interfaces are included in the order that they
  321. were defined in the specification.
  322. """
  323. def __sub__(interfaces):
  324. """Create an interface specification with some interfaces excluded
  325. The argument can be an interface or an interface
  326. specifications. The interface or interfaces given in a
  327. specification are subtracted from the interface specification.
  328. Removing an interface that is not in the specification does
  329. not raise an error. Doing so has no effect.
  330. Removing an interface also removes sub-interfaces of the interface.
  331. """
  332. def __add__(interfaces):
  333. """Create an interface specification with some interfaces added
  334. The argument can be an interface or an interface
  335. specifications. The interface or interfaces given in a
  336. specification are added to the interface specification.
  337. Adding an interface that is already in the specification does
  338. not raise an error. Doing so has no effect.
  339. """
  340. def __nonzero__():
  341. """Return a true value of the interface specification is non-empty
  342. """
  343. class IInterfaceDeclaration(Interface):
  344. """
  345. Declare and check the interfaces of objects.
  346. The functions defined in this interface are used to declare the
  347. interfaces that objects provide and to query the interfaces that
  348. have been declared.
  349. Interfaces can be declared for objects in two ways:
  350. - Interfaces are declared for instances of the object's class
  351. - Interfaces are declared for the object directly.
  352. The interfaces declared for an object are, therefore, the union of
  353. interfaces declared for the object directly and the interfaces
  354. declared for instances of the object's class.
  355. Note that we say that a class implements the interfaces provided
  356. by it's instances. An instance can also provide interfaces
  357. directly. The interfaces provided by an object are the union of
  358. the interfaces provided directly and the interfaces implemented by
  359. the class.
  360. This interface is implemented by :mod:`zope.interface`.
  361. """
  362. # pylint:disable=arguments-differ
  363. ###
  364. # Defining interfaces
  365. ###
  366. Interface = Attribute("The base class used to create new interfaces")
  367. def taggedValue(key, value):
  368. """
  369. Attach a tagged value to an interface while defining the interface.
  370. This is a way of executing :meth:`IElement.setTaggedValue` from
  371. the definition of the interface. For example::
  372. class IFoo(Interface):
  373. taggedValue('key', 'value')
  374. .. seealso:: `zope.interface.taggedValue`
  375. """
  376. def invariant(checker_function):
  377. """
  378. Attach an invariant checker function to an interface while defining it.
  379. Invariants can later be validated against particular implementations by
  380. calling :meth:`IInterface.validateInvariants`.
  381. For example::
  382. def check_range(ob):
  383. if ob.max < ob.min:
  384. raise ValueError("max value is less than min value")
  385. class IRange(Interface):
  386. min = Attribute("The min value")
  387. max = Attribute("The max value")
  388. invariant(check_range)
  389. .. seealso:: `zope.interface.invariant`
  390. """
  391. def interfacemethod(method):
  392. """
  393. A decorator that transforms a method specification into an
  394. implementation method.
  395. This is used to override methods of ``Interface`` or provide new methods.
  396. Definitions using this decorator will not appear in :meth:`IInterface.names()`.
  397. It is possible to have an implementation method and a method specification
  398. of the same name.
  399. For example::
  400. class IRange(Interface):
  401. @interfacemethod
  402. def __adapt__(self, obj):
  403. if isinstance(obj, range):
  404. # Return the builtin ``range`` as-is
  405. return obj
  406. return super(type(IRange), self).__adapt__(obj)
  407. You can use ``super`` to call the parent class functionality. Note that
  408. the zero-argument version (``super().__adapt__``) works on Python 3.6 and above, but
  409. prior to that the two-argument version must be used, and the class must be explicitly
  410. passed as the first argument.
  411. .. versionadded:: 5.1.0
  412. .. seealso:: `zope.interface.interfacemethod`
  413. """
  414. ###
  415. # Querying interfaces
  416. ###
  417. def providedBy(ob):
  418. """
  419. Return the interfaces provided by an object.
  420. This is the union of the interfaces directly provided by an
  421. object and interfaces implemented by it's class.
  422. The value returned is an `IDeclaration`.
  423. .. seealso:: `zope.interface.providedBy`
  424. """
  425. def implementedBy(class_):
  426. """
  427. Return the interfaces implemented for a class's instances.
  428. The value returned is an `IDeclaration`.
  429. .. seealso:: `zope.interface.implementedBy`
  430. """
  431. ###
  432. # Declaring interfaces
  433. ###
  434. def classImplements(class_, *interfaces):
  435. """
  436. Declare additional interfaces implemented for instances of a class.
  437. The arguments after the class are one or more interfaces or
  438. interface specifications (`IDeclaration` objects).
  439. The interfaces given (including the interfaces in the
  440. specifications) are added to any interfaces previously
  441. declared.
  442. Consider the following example::
  443. class C(A, B):
  444. ...
  445. classImplements(C, I1, I2)
  446. Instances of ``C`` provide ``I1``, ``I2``, and whatever interfaces
  447. instances of ``A`` and ``B`` provide. This is equivalent to::
  448. @implementer(I1, I2)
  449. class C(A, B):
  450. pass
  451. .. seealso:: `zope.interface.classImplements`
  452. .. seealso:: `zope.interface.implementer`
  453. """
  454. def classImplementsFirst(cls, interface):
  455. """
  456. See :func:`zope.interface.classImplementsFirst`.
  457. """
  458. def implementer(*interfaces):
  459. """
  460. Create a decorator for declaring interfaces implemented by a
  461. factory.
  462. A callable is returned that makes an implements declaration on
  463. objects passed to it.
  464. .. seealso:: :meth:`classImplements`
  465. """
  466. def classImplementsOnly(class_, *interfaces):
  467. """
  468. Declare the only interfaces implemented by instances of a class.
  469. The arguments after the class are one or more interfaces or
  470. interface specifications (`IDeclaration` objects).
  471. The interfaces given (including the interfaces in the
  472. specifications) replace any previous declarations.
  473. Consider the following example::
  474. class C(A, B):
  475. ...
  476. classImplements(C, IA, IB. IC)
  477. classImplementsOnly(C. I1, I2)
  478. Instances of ``C`` provide only ``I1``, ``I2``, and regardless of
  479. whatever interfaces instances of ``A`` and ``B`` implement.
  480. .. seealso:: `zope.interface.classImplementsOnly`
  481. """
  482. def implementer_only(*interfaces):
  483. """
  484. Create a decorator for declaring the only interfaces implemented.
  485. A callable is returned that makes an implements declaration on
  486. objects passed to it.
  487. .. seealso:: `zope.interface.implementer_only`
  488. """
  489. def directlyProvidedBy(object): # pylint:disable=redefined-builtin
  490. """
  491. Return the interfaces directly provided by the given object.
  492. The value returned is an `IDeclaration`.
  493. .. seealso:: `zope.interface.directlyProvidedBy`
  494. """
  495. def directlyProvides(object, *interfaces): # pylint:disable=redefined-builtin
  496. """
  497. Declare interfaces declared directly for an object.
  498. The arguments after the object are one or more interfaces or
  499. interface specifications (`IDeclaration` objects).
  500. .. caution::
  501. The interfaces given (including the interfaces in the
  502. specifications) *replace* interfaces previously
  503. declared for the object. See :meth:`alsoProvides` to add
  504. additional interfaces.
  505. Consider the following example::
  506. class C(A, B):
  507. ...
  508. ob = C()
  509. directlyProvides(ob, I1, I2)
  510. The object, ``ob`` provides ``I1``, ``I2``, and whatever interfaces
  511. instances have been declared for instances of ``C``.
  512. To remove directly provided interfaces, use `directlyProvidedBy` and
  513. subtract the unwanted interfaces. For example::
  514. directlyProvides(ob, directlyProvidedBy(ob)-I2)
  515. removes I2 from the interfaces directly provided by
  516. ``ob``. The object, ``ob`` no longer directly provides ``I2``,
  517. although it might still provide ``I2`` if it's class
  518. implements ``I2``.
  519. To add directly provided interfaces, use `directlyProvidedBy` and
  520. include additional interfaces. For example::
  521. directlyProvides(ob, directlyProvidedBy(ob), I2)
  522. adds I2 to the interfaces directly provided by ob.
  523. .. seealso:: `zope.interface.directlyProvides`
  524. """
  525. def alsoProvides(object, *interfaces): # pylint:disable=redefined-builtin
  526. """
  527. Declare additional interfaces directly for an object.
  528. For example::
  529. alsoProvides(ob, I1)
  530. is equivalent to::
  531. directlyProvides(ob, directlyProvidedBy(ob), I1)
  532. .. seealso:: `zope.interface.alsoProvides`
  533. """
  534. def noLongerProvides(object, interface): # pylint:disable=redefined-builtin
  535. """
  536. Remove an interface from the list of an object's directly provided
  537. interfaces.
  538. For example::
  539. noLongerProvides(ob, I1)
  540. is equivalent to::
  541. directlyProvides(ob, directlyProvidedBy(ob) - I1)
  542. with the exception that if ``I1`` is an interface that is
  543. provided by ``ob`` through the class's implementation,
  544. `ValueError` is raised.
  545. .. seealso:: `zope.interface.noLongerProvides`
  546. """
  547. def implements(*interfaces):
  548. """
  549. Declare interfaces implemented by instances of a class.
  550. .. deprecated:: 5.0
  551. This only works for Python 2. The `implementer` decorator
  552. is preferred for all versions.
  553. This function is called in a class definition (Python 2.x only).
  554. The arguments are one or more interfaces or interface
  555. specifications (`IDeclaration` objects).
  556. The interfaces given (including the interfaces in the
  557. specifications) are added to any interfaces previously
  558. declared.
  559. Previous declarations include declarations for base classes
  560. unless implementsOnly was used.
  561. This function is provided for convenience. It provides a more
  562. convenient way to call `classImplements`. For example::
  563. implements(I1)
  564. is equivalent to calling::
  565. classImplements(C, I1)
  566. after the class has been created.
  567. Consider the following example (Python 2.x only)::
  568. class C(A, B):
  569. implements(I1, I2)
  570. Instances of ``C`` implement ``I1``, ``I2``, and whatever interfaces
  571. instances of ``A`` and ``B`` implement.
  572. """
  573. def implementsOnly(*interfaces):
  574. """
  575. Declare the only interfaces implemented by instances of a class.
  576. .. deprecated:: 5.0
  577. This only works for Python 2. The `implementer_only` decorator
  578. is preferred for all versions.
  579. This function is called in a class definition (Python 2.x only).
  580. The arguments are one or more interfaces or interface
  581. specifications (`IDeclaration` objects).
  582. Previous declarations including declarations for base classes
  583. are overridden.
  584. This function is provided for convenience. It provides a more
  585. convenient way to call `classImplementsOnly`. For example::
  586. implementsOnly(I1)
  587. is equivalent to calling::
  588. classImplementsOnly(I1)
  589. after the class has been created.
  590. Consider the following example (Python 2.x only)::
  591. class C(A, B):
  592. implementsOnly(I1, I2)
  593. Instances of ``C`` implement ``I1``, ``I2``, regardless of what
  594. instances of ``A`` and ``B`` implement.
  595. """
  596. def classProvides(*interfaces):
  597. """
  598. Declare interfaces provided directly by a class.
  599. .. deprecated:: 5.0
  600. This only works for Python 2. The `provider` decorator
  601. is preferred for all versions.
  602. This function is called in a class definition.
  603. The arguments are one or more interfaces or interface
  604. specifications (`IDeclaration` objects).
  605. The given interfaces (including the interfaces in the
  606. specifications) are used to create the class's direct-object
  607. interface specification. An error will be raised if the module
  608. class has an direct interface specification. In other words, it is
  609. an error to call this function more than once in a class
  610. definition.
  611. Note that the given interfaces have nothing to do with the
  612. interfaces implemented by instances of the class.
  613. This function is provided for convenience. It provides a more
  614. convenient way to call `directlyProvides` for a class. For example::
  615. classProvides(I1)
  616. is equivalent to calling::
  617. directlyProvides(theclass, I1)
  618. after the class has been created.
  619. """
  620. def provider(*interfaces):
  621. """
  622. A class decorator version of `classProvides`.
  623. .. seealso:: `zope.interface.provider`
  624. """
  625. def moduleProvides(*interfaces):
  626. """
  627. Declare interfaces provided by a module.
  628. This function is used in a module definition.
  629. The arguments are one or more interfaces or interface
  630. specifications (`IDeclaration` objects).
  631. The given interfaces (including the interfaces in the
  632. specifications) are used to create the module's direct-object
  633. interface specification. An error will be raised if the module
  634. already has an interface specification. In other words, it is
  635. an error to call this function more than once in a module
  636. definition.
  637. This function is provided for convenience. It provides a more
  638. convenient way to call `directlyProvides` for a module. For example::
  639. moduleImplements(I1)
  640. is equivalent to::
  641. directlyProvides(sys.modules[__name__], I1)
  642. .. seealso:: `zope.interface.moduleProvides`
  643. """
  644. def Declaration(*interfaces):
  645. """
  646. Create an interface specification.
  647. The arguments are one or more interfaces or interface
  648. specifications (`IDeclaration` objects).
  649. A new interface specification (`IDeclaration`) with the given
  650. interfaces is returned.
  651. .. seealso:: `zope.interface.Declaration`
  652. """
  653. class IAdapterRegistry(Interface):
  654. """Provide an interface-based registry for adapters
  655. This registry registers objects that are in some sense "from" a
  656. sequence of specification to an interface and a name.
  657. No specific semantics are assumed for the registered objects,
  658. however, the most common application will be to register factories
  659. that adapt objects providing required specifications to a provided
  660. interface.
  661. """
  662. def register(required, provided, name, value):
  663. """Register a value
  664. A value is registered for a *sequence* of required specifications, a
  665. provided interface, and a name, which must be text.
  666. """
  667. def registered(required, provided, name=u''):
  668. """Return the component registered for the given interfaces and name
  669. name must be text.
  670. Unlike the lookup method, this methods won't retrieve
  671. components registered for more specific required interfaces or
  672. less specific provided interfaces.
  673. If no component was registered exactly for the given
  674. interfaces and name, then None is returned.
  675. """
  676. def lookup(required, provided, name='', default=None):
  677. """Lookup a value
  678. A value is looked up based on a *sequence* of required
  679. specifications, a provided interface, and a name, which must be
  680. text.
  681. """
  682. def queryMultiAdapter(objects, provided, name=u'', default=None):
  683. """Adapt a sequence of objects to a named, provided, interface
  684. """
  685. def lookup1(required, provided, name=u'', default=None):
  686. """Lookup a value using a single required interface
  687. A value is looked up based on a single required
  688. specifications, a provided interface, and a name, which must be
  689. text.
  690. """
  691. def queryAdapter(object, provided, name=u'', default=None): # pylint:disable=redefined-builtin
  692. """Adapt an object using a registered adapter factory.
  693. """
  694. def adapter_hook(provided, object, name=u'', default=None): # pylint:disable=redefined-builtin
  695. """Adapt an object using a registered adapter factory.
  696. name must be text.
  697. """
  698. def lookupAll(required, provided):
  699. """Find all adapters from the required to the provided interfaces
  700. An iterable object is returned that provides name-value two-tuples.
  701. """
  702. def names(required, provided): # pylint:disable=arguments-differ
  703. """Return the names for which there are registered objects
  704. """
  705. def subscribe(required, provided, subscriber): # pylint:disable=arguments-differ
  706. """Register a subscriber
  707. A subscriber is registered for a *sequence* of required
  708. specifications, a provided interface, and a name.
  709. Multiple subscribers may be registered for the same (or
  710. equivalent) interfaces.
  711. .. versionchanged:: 5.1.1
  712. Correct the method signature to remove the ``name`` parameter.
  713. Subscribers have no names.
  714. """
  715. def subscribed(required, provided, subscriber):
  716. """
  717. Check whether the object *subscriber* is registered directly
  718. with this object via a previous call to
  719. ``subscribe(required, provided, subscriber)``.
  720. If the *subscriber*, or one equal to it, has been subscribed,
  721. for the given *required* sequence and *provided* interface,
  722. return that object. (This does not guarantee whether the *subscriber*
  723. itself is returned, or an object equal to it.)
  724. If it has not, return ``None``.
  725. Unlike :meth:`subscriptions`, this method won't retrieve
  726. components registered for more specific required interfaces or
  727. less specific provided interfaces.
  728. .. versionadded:: 5.3.0
  729. """
  730. def subscriptions(required, provided):
  731. """
  732. Get a sequence of subscribers.
  733. Subscribers for a sequence of *required* interfaces, and a *provided*
  734. interface are returned. This takes into account subscribers
  735. registered with this object, as well as those registered with
  736. base adapter registries in the resolution order, and interfaces that
  737. extend *provided*.
  738. .. versionchanged:: 5.1.1
  739. Correct the method signature to remove the ``name`` parameter.
  740. Subscribers have no names.
  741. """
  742. def subscribers(objects, provided):
  743. """
  744. Get a sequence of subscription **adapters**.
  745. This is like :meth:`subscriptions`, but calls the returned
  746. subscribers with *objects* (and optionally returns the results
  747. of those calls), instead of returning the subscribers directly.
  748. :param objects: A sequence of objects; they will be used to
  749. determine the *required* argument to :meth:`subscriptions`.
  750. :param provided: A single interface, or ``None``, to pass
  751. as the *provided* parameter to :meth:`subscriptions`.
  752. If an interface is given, the results of calling each returned
  753. subscriber with the the *objects* are collected and returned
  754. from this method; each result should be an object implementing
  755. the *provided* interface. If ``None``, the resulting subscribers
  756. are still called, but the results are ignored.
  757. :return: A sequence of the results of calling the subscribers
  758. if *provided* is not ``None``. If there are no registered
  759. subscribers, or *provided* is ``None``, this will be an empty
  760. sequence.
  761. .. versionchanged:: 5.1.1
  762. Correct the method signature to remove the ``name`` parameter.
  763. Subscribers have no names.
  764. """
  765. # begin formerly in zope.component
  766. class ComponentLookupError(LookupError):
  767. """A component could not be found."""
  768. class Invalid(Exception):
  769. """A component doesn't satisfy a promise."""
  770. class IObjectEvent(Interface):
  771. """An event related to an object.
  772. The object that generated this event is not necessarily the object
  773. referred to by location.
  774. """
  775. object = Attribute("The subject of the event.")
  776. @implementer(IObjectEvent)
  777. class ObjectEvent(object):
  778. def __init__(self, object): # pylint:disable=redefined-builtin
  779. self.object = object
  780. class IComponentLookup(Interface):
  781. """Component Manager for a Site
  782. This object manages the components registered at a particular site. The
  783. definition of a site is intentionally vague.
  784. """
  785. adapters = Attribute(
  786. "Adapter Registry to manage all registered adapters.")
  787. utilities = Attribute(
  788. "Adapter Registry to manage all registered utilities.")
  789. def queryAdapter(object, interface, name=u'', default=None): # pylint:disable=redefined-builtin
  790. """Look for a named adapter to an interface for an object
  791. If a matching adapter cannot be found, returns the default.
  792. """
  793. def getAdapter(object, interface, name=u''): # pylint:disable=redefined-builtin
  794. """Look for a named adapter to an interface for an object
  795. If a matching adapter cannot be found, a `ComponentLookupError`
  796. is raised.
  797. """
  798. def queryMultiAdapter(objects, interface, name=u'', default=None):
  799. """Look for a multi-adapter to an interface for multiple objects
  800. If a matching adapter cannot be found, returns the default.
  801. """
  802. def getMultiAdapter(objects, interface, name=u''):
  803. """Look for a multi-adapter to an interface for multiple objects
  804. If a matching adapter cannot be found, a `ComponentLookupError`
  805. is raised.
  806. """
  807. def getAdapters(objects, provided):
  808. """Look for all matching adapters to a provided interface for objects
  809. Return an iterable of name-adapter pairs for adapters that
  810. provide the given interface.
  811. """
  812. def subscribers(objects, provided):
  813. """Get subscribers
  814. Subscribers are returned that provide the provided interface
  815. and that depend on and are computed from the sequence of
  816. required objects.
  817. """
  818. def handle(*objects):
  819. """Call handlers for the given objects
  820. Handlers registered for the given objects are called.
  821. """
  822. def queryUtility(interface, name='', default=None):
  823. """Look up a utility that provides an interface.
  824. If one is not found, returns default.
  825. """
  826. def getUtilitiesFor(interface):
  827. """Look up the registered utilities that provide an interface.
  828. Returns an iterable of name-utility pairs.
  829. """
  830. def getAllUtilitiesRegisteredFor(interface):
  831. """Return all registered utilities for an interface
  832. This includes overridden utilities.
  833. An iterable of utility instances is returned. No names are
  834. returned.
  835. """
  836. class IRegistration(Interface):
  837. """A registration-information object
  838. """
  839. registry = Attribute("The registry having the registration")
  840. name = Attribute("The registration name")
  841. info = Attribute("""Information about the registration
  842. This is information deemed useful to people browsing the
  843. configuration of a system. It could, for example, include
  844. commentary or information about the source of the configuration.
  845. """)
  846. class IUtilityRegistration(IRegistration):
  847. """Information about the registration of a utility
  848. """
  849. factory = Attribute("The factory used to create the utility. Optional.")
  850. component = Attribute("The object registered")
  851. provided = Attribute("The interface provided by the component")
  852. class _IBaseAdapterRegistration(IRegistration):
  853. """Information about the registration of an adapter
  854. """
  855. factory = Attribute("The factory used to create adapters")
  856. required = Attribute("""The adapted interfaces
  857. This is a sequence of interfaces adapters by the registered
  858. factory. The factory will be caled with a sequence of objects, as
  859. positional arguments, that provide these interfaces.
  860. """)
  861. provided = Attribute("""The interface provided by the adapters.
  862. This interface is implemented by the factory
  863. """)
  864. class IAdapterRegistration(_IBaseAdapterRegistration):
  865. """Information about the registration of an adapter
  866. """
  867. class ISubscriptionAdapterRegistration(_IBaseAdapterRegistration):
  868. """Information about the registration of a subscription adapter
  869. """
  870. class IHandlerRegistration(IRegistration):
  871. handler = Attribute("An object called used to handle an event")
  872. required = Attribute("""The handled interfaces
  873. This is a sequence of interfaces handled by the registered
  874. handler. The handler will be caled with a sequence of objects, as
  875. positional arguments, that provide these interfaces.
  876. """)
  877. class IRegistrationEvent(IObjectEvent):
  878. """An event that involves a registration"""
  879. @implementer(IRegistrationEvent)
  880. class RegistrationEvent(ObjectEvent):
  881. """There has been a change in a registration
  882. """
  883. def __repr__(self):
  884. return "%s event:\n%r" % (self.__class__.__name__, self.object)
  885. class IRegistered(IRegistrationEvent):
  886. """A component or factory was registered
  887. """
  888. @implementer(IRegistered)
  889. class Registered(RegistrationEvent):
  890. pass
  891. class IUnregistered(IRegistrationEvent):
  892. """A component or factory was unregistered
  893. """
  894. @implementer(IUnregistered)
  895. class Unregistered(RegistrationEvent):
  896. """A component or factory was unregistered
  897. """
  898. class IComponentRegistry(Interface):
  899. """Register components
  900. """
  901. def registerUtility(component=None, provided=None, name=u'',
  902. info=u'', factory=None):
  903. """Register a utility
  904. :param factory:
  905. Factory for the component to be registered.
  906. :param component:
  907. The registered component
  908. :param provided:
  909. This is the interface provided by the utility. If the
  910. component provides a single interface, then this
  911. argument is optional and the component-implemented
  912. interface will be used.
  913. :param name:
  914. The utility name.
  915. :param info:
  916. An object that can be converted to a string to provide
  917. information about the registration.
  918. Only one of *component* and *factory* can be used.
  919. A `IRegistered` event is generated with an `IUtilityRegistration`.
  920. """
  921. def unregisterUtility(component=None, provided=None, name=u'',
  922. factory=None):
  923. """Unregister a utility
  924. :returns:
  925. A boolean is returned indicating whether the registry was
  926. changed. If the given *component* is None and there is no
  927. component registered, or if the given *component* is not
  928. None and is not registered, then the function returns
  929. False, otherwise it returns True.
  930. :param factory:
  931. Factory for the component to be unregistered.
  932. :param component:
  933. The registered component The given component can be
  934. None, in which case any component registered to provide
  935. the given provided interface with the given name is
  936. unregistered.
  937. :param provided:
  938. This is the interface provided by the utility. If the
  939. component is not None and provides a single interface,
  940. then this argument is optional and the
  941. component-implemented interface will be used.
  942. :param name:
  943. The utility name.
  944. Only one of *component* and *factory* can be used.
  945. An `IUnregistered` event is generated with an `IUtilityRegistration`.
  946. """
  947. def registeredUtilities():
  948. """Return an iterable of `IUtilityRegistration` instances.
  949. These registrations describe the current utility registrations
  950. in the object.
  951. """
  952. def registerAdapter(factory, required=None, provided=None, name=u'',
  953. info=u''):
  954. """Register an adapter factory
  955. :param factory:
  956. The object used to compute the adapter
  957. :param required:
  958. This is a sequence of specifications for objects to be
  959. adapted. If omitted, then the value of the factory's
  960. ``__component_adapts__`` attribute will be used. The
  961. ``__component_adapts__`` attribute is
  962. normally set in class definitions using
  963. the `.adapter`
  964. decorator. If the factory doesn't have a
  965. ``__component_adapts__`` adapts attribute, then this
  966. argument is required.
  967. :param provided:
  968. This is the interface provided by the adapter and
  969. implemented by the factory. If the factory
  970. implements a single interface, then this argument is
  971. optional and the factory-implemented interface will be
  972. used.
  973. :param name:
  974. The adapter name.
  975. :param info:
  976. An object that can be converted to a string to provide
  977. information about the registration.
  978. A `IRegistered` event is generated with an `IAdapterRegistration`.
  979. """
  980. def unregisterAdapter(factory=None, required=None,
  981. provided=None, name=u''):
  982. """Unregister an adapter factory
  983. :returns:
  984. A boolean is returned indicating whether the registry was
  985. changed. If the given component is None and there is no
  986. component registered, or if the given component is not
  987. None and is not registered, then the function returns
  988. False, otherwise it returns True.
  989. :param factory:
  990. This is the object used to compute the adapter. The
  991. factory can be None, in which case any factory
  992. registered to implement the given provided interface
  993. for the given required specifications with the given
  994. name is unregistered.
  995. :param required:
  996. This is a sequence of specifications for objects to be
  997. adapted. If the factory is not None and the required
  998. arguments is omitted, then the value of the factory's
  999. __component_adapts__ attribute will be used. The
  1000. __component_adapts__ attribute attribute is normally
  1001. set in class definitions using adapts function, or for
  1002. callables using the adapter decorator. If the factory
  1003. is None or doesn't have a __component_adapts__ adapts
  1004. attribute, then this argument is required.
  1005. :param provided:
  1006. This is the interface provided by the adapter and
  1007. implemented by the factory. If the factory is not
  1008. None and implements a single interface, then this
  1009. argument is optional and the factory-implemented
  1010. interface will be used.
  1011. :param name:
  1012. The adapter name.
  1013. An `IUnregistered` event is generated with an `IAdapterRegistration`.
  1014. """
  1015. def registeredAdapters():
  1016. """Return an iterable of `IAdapterRegistration` instances.
  1017. These registrations describe the current adapter registrations
  1018. in the object.
  1019. """
  1020. def registerSubscriptionAdapter(factory, required=None, provides=None,
  1021. name=u'', info=''):
  1022. """Register a subscriber factory
  1023. :param factory:
  1024. The object used to compute the adapter
  1025. :param required:
  1026. This is a sequence of specifications for objects to be
  1027. adapted. If omitted, then the value of the factory's
  1028. ``__component_adapts__`` attribute will be used. The
  1029. ``__component_adapts__`` attribute is
  1030. normally set using the adapter
  1031. decorator. If the factory doesn't have a
  1032. ``__component_adapts__`` adapts attribute, then this
  1033. argument is required.
  1034. :param provided:
  1035. This is the interface provided by the adapter and
  1036. implemented by the factory. If the factory implements
  1037. a single interface, then this argument is optional and
  1038. the factory-implemented interface will be used.
  1039. :param name:
  1040. The adapter name.
  1041. Currently, only the empty string is accepted. Other
  1042. strings will be accepted in the future when support for
  1043. named subscribers is added.
  1044. :param info:
  1045. An object that can be converted to a string to provide
  1046. information about the registration.
  1047. A `IRegistered` event is generated with an
  1048. `ISubscriptionAdapterRegistration`.
  1049. """
  1050. def unregisterSubscriptionAdapter(factory=None, required=None,
  1051. provides=None, name=u''):
  1052. """Unregister a subscriber factory.
  1053. :returns:
  1054. A boolean is returned indicating whether the registry was
  1055. changed. If the given component is None and there is no
  1056. component registered, or if the given component is not
  1057. None and is not registered, then the function returns
  1058. False, otherwise it returns True.
  1059. :param factory:
  1060. This is the object used to compute the adapter. The
  1061. factory can be None, in which case any factories
  1062. registered to implement the given provided interface
  1063. for the given required specifications with the given
  1064. name are unregistered.
  1065. :param required:
  1066. This is a sequence of specifications for objects to be
  1067. adapted. If omitted, then the value of the factory's
  1068. ``__component_adapts__`` attribute will be used. The
  1069. ``__component_adapts__`` attribute is
  1070. normally set using the adapter
  1071. decorator. If the factory doesn't have a
  1072. ``__component_adapts__`` adapts attribute, then this
  1073. argument is required.
  1074. :param provided:
  1075. This is the interface provided by the adapter and
  1076. implemented by the factory. If the factory is not
  1077. None implements a single interface, then this argument
  1078. is optional and the factory-implemented interface will
  1079. be used.
  1080. :param name:
  1081. The adapter name.
  1082. Currently, only the empty string is accepted. Other
  1083. strings will be accepted in the future when support for
  1084. named subscribers is added.
  1085. An `IUnregistered` event is generated with an
  1086. `ISubscriptionAdapterRegistration`.
  1087. """
  1088. def registeredSubscriptionAdapters():
  1089. """Return an iterable of `ISubscriptionAdapterRegistration` instances.
  1090. These registrations describe the current subscription adapter
  1091. registrations in the object.
  1092. """
  1093. def registerHandler(handler, required=None, name=u'', info=''):
  1094. """Register a handler.
  1095. A handler is a subscriber that doesn't compute an adapter
  1096. but performs some function when called.
  1097. :param handler:
  1098. The object used to handle some event represented by
  1099. the objects passed to it.
  1100. :param required:
  1101. This is a sequence of specifications for objects to be
  1102. adapted. If omitted, then the value of the factory's
  1103. ``__component_adapts__`` attribute will be used. The
  1104. ``__component_adapts__`` attribute is
  1105. normally set using the adapter
  1106. decorator. If the factory doesn't have a
  1107. ``__component_adapts__`` adapts attribute, then this
  1108. argument is required.
  1109. :param name:
  1110. The handler name.
  1111. Currently, only the empty string is accepted. Other
  1112. strings will be accepted in the future when support for
  1113. named handlers is added.
  1114. :param info:
  1115. An object that can be converted to a string to provide
  1116. information about the registration.
  1117. A `IRegistered` event is generated with an `IHandlerRegistration`.
  1118. """
  1119. def unregisterHandler(handler=None, required=None, name=u''):
  1120. """Unregister a handler.
  1121. A handler is a subscriber that doesn't compute an adapter
  1122. but performs some function when called.
  1123. :returns: A boolean is returned indicating whether the registry was
  1124. changed.
  1125. :param handler:
  1126. This is the object used to handle some event
  1127. represented by the objects passed to it. The handler
  1128. can be None, in which case any handlers registered for
  1129. the given required specifications with the given are
  1130. unregistered.
  1131. :param required:
  1132. This is a sequence of specifications for objects to be
  1133. adapted. If omitted, then the value of the factory's
  1134. ``__component_adapts__`` attribute will be used. The
  1135. ``__component_adapts__`` attribute is
  1136. normally set using the adapter
  1137. decorator. If the factory doesn't have a
  1138. ``__component_adapts__`` adapts attribute, then this
  1139. argument is required.
  1140. :param name:
  1141. The handler name.
  1142. Currently, only the empty string is accepted. Other
  1143. strings will be accepted in the future when support for
  1144. named handlers is added.
  1145. An `IUnregistered` event is generated with an `IHandlerRegistration`.
  1146. """
  1147. def registeredHandlers():
  1148. """Return an iterable of `IHandlerRegistration` instances.
  1149. These registrations describe the current handler registrations
  1150. in the object.
  1151. """
  1152. class IComponents(IComponentLookup, IComponentRegistry):
  1153. """Component registration and access
  1154. """
  1155. # end formerly in zope.component