Package IO
Support for handling the IO for all the objects in a package, typically via a ZCML directive.
- class AutoPackageSearchingScopedInterfaceObjectIO(context, iface_upper_bound=None, validate_after_update=True)[source]
Bases:
ModuleScopedInterfaceObjectIOA special, magic, type of interface-driven input and output, one designed for the common use case of a package that provides the common pattern:
interfaces.py
externalization.py (where a subclass of this object lives)
configure.zcml (where the subclass is registered as an adapter for each object; you may also then provide mime-factories as well)
other modules, where types are defined for the external interfaces.
Once you derive from this class and implement the abstract methods, you need to call
__class_init__()(exactly once) on your subclass.You do not have to derive from this class; the common case is handled via the ZCML directive
<ext:registerAutoPackageIO>(nti.externalization.zcml.IAutoPackageExternalizationDirective). You can still customize the behaviour by providing theiobaseargument.- Parameters:
iface_upper_bound – The upper bound on the schema to use to externalize
ext_self; we will use the most derived sub-interface of this interface that the object implements. Subclasses can either override this constructor to pass this parameter (while taking one argument themselves, to be usable as an adapter), or they can define the class attribute_ext_iface_upper_boundvalidate_after_update (bool) – If
True(the default) then the entire schema will be validated after an object has been updated withupdate_from_external_object(), not just the keys that were assigned.
- classmethod __class_init__()[source]
Class initializer. Should be called exactly once on each distinct subclass.
First, makes all interfaces returned by
_ap_enumerate_externalizable_root_interfaces()externalizable by setting the__external_class_name__tagged value (to_ap_compute_external_class_name_from_interface_and_instance()). (SeeInterfaceObjectIO.)Then, find all of the object factories and initialize them using
_ap_find_factories(). A namespace object representing these factories is returned.Changed in version 1.0: Registering the factories using
register_legacy_search_module()is no longer done by default. If you are using this class outside of ZCML, you will need to subclass and override this method to make that call yourself. If you are using ZCML, you will need to set the appropriate attribute to True.
- classmethod _ap_compute_external_class_name_from_concrete_class(a_type) str[source]
Return the string value of the external class name.
By default this will be either the value of
__external_class_name__or, if not found, the value of__name__.Subclasses may override.
- classmethod _ap_compute_external_class_name_from_interface_and_instance(unused_iface, impl)[source]
Assigned as the tagged value
__external_class_name__to each interface. This will be called on an instance implementing iface.See also
- classmethod _ap_compute_external_mimetype(package_name, unused_a_type, ext_class_name) str[source]
Return the string value of the external mime type for the given type in the given package having the given external name (probably derived from
_ap_compute_external_class_name_from_concrete_class()).For example, given the arguments (‘nti.assessment’, FooBar, ‘FooBar’), the result will be ‘application/vnd.nextthought.assessment.foobar’.
Subclasses may override.
- classmethod _ap_enumerate_externalizable_root_interfaces(interfaces) Iterable[source]
Return an iterable of the root interfaces in this package that should be externalized.
Subclasses must implement.
- classmethod _ap_enumerate_module_names() Iterable[str][source]
Return an iterable of module names in this package that should be searched to find factories.
Subclasses must implement.
- classmethod _ap_find_factories(package_name)[source]
Return a namespace object whose attribute names are external class names and whose attribute values are classes that can be created externally.
For each module returned by
_ap_enumerate_module_names(), we will resolve it against the value of package_name (normally that given by_ap_find_package_name()). The module is then searched for classes that live in that module. If a class implements an interface that has a tagged value of__external_class_name__, it is added to the return value. The external class name (the name of the attribute) is computed by_ap_compute_external_class_name_from_concrete_class().Each class that is found has an appropriate
mimeTypeadded to it (derived by_ap_compute_external_mimetype()), if it does not already have one; these classes also have the attribute__external_can_create__set to true on them if they do not have a value for it at all. This makes the classes ready to be used withregisterMimeFactories(), which is done automatically by the ZCML directiveIAutoPackageExternalizationDirective.Each class that is found is also marked as implementing
zope.mimetype.interfaces.IContentTypeAware.
- classmethod _ap_find_package_interface_module()[source]
Return the module that should be searched for interfaces.
By default, this will be the
interfacessub-module of the package returned from_ap_find_package_name().Subclasses may override.