mmfutils.interface¶
Stand-in for zope.interface if it is not available.
-
interface
mmfutils.interface.
Interface
¶
-
class
mmfutils.interface.
Attribute
(__name__, __doc__='')[source]¶ Bases:
zope.interface.interface.Element
Attribute descriptions
-
interface
= None¶
-
-
class
mmfutils.interface.
implementer
(*interfaces)[source]¶ Bases:
object
Declare the interfaces implemented by instances of a class.
This function is called as a class decorator.
The arguments are one or more interfaces or interface specifications (~zope.interface.interfaces.IDeclaration objects).
The interfaces given (including the interfaces in the specifications) are added to any interfaces previously declared.
Previous declarations include declarations for base classes unless implementsOnly was used.
This function is provided for convenience. It provides a more convenient way to call classImplements. For example:
@implementer(I1) class C(object): pass
is equivalent to calling:
classImplements(C, I1)
after the class has been created.
-
mmfutils.interface.
describe_interface
(interface, format='ipython')[source]¶ Return an HTML object for Jupyter notebooks that describes the interface.
- Parameters
interface (Interface) – Interface to extract documentation from.
format ('rst', 'html', 'ipython') – Return format. ‘rst’ is raw RestructuredText, ‘html’ is packaged as HTML, and ‘ipython’ is packaged as an IPython.display.HTML() object suitable for Jupyter notebooks.
Example
>>> class IExample(Interface): ... x = Attribute("Floating point number") ... def two(): ... "Return two" >>> print(describe_interface(IExample, format='rst').strip()) ``IExample`` Attributes: ``x`` -- Floating point number Methods: ``two()`` -- Return two
You can also get this wrapped as HTML:
>>> print(describe_interface(IExample, format='html').strip()) <!DOCTYPE html ... <p><tt class="docutils literal">IExample</tt></p> <blockquote> <p>Attributes:</p> <blockquote> <tt class="docutils literal">x</tt> -- Floating point number</blockquote> <p>Methods:</p> <blockquote> <tt class="docutils literal">two()</tt> -- Return two</blockquote> </blockquote> </div>
In a Jupyter notebook, this will properly display:
>>> describe_interface(IExample) <IPython.core.display.HTML object>
Other formats are not yet supported:
>>> describe_interface(IExample, format='WYSIWYG') Traceback (most recent call last): ... NotImplementedError: format WYSIWYG not supported