ZCML¶
Directives to be used in ZCML.
These directives are all in the http://nextthought.com/ntp/ext
namespace,
and are loaded using the meta.zcml
file.
Example (non-sensical) of all the directives:
<configure xmlns:ext="http://nextthought.com/ntp/ext">
<include package="nti.externalization" file="meta.zcml" />
<ext:registerMimeFactories module="the.module" />
<ext:registerAutoPackageIO
root_interfaces="other_module.interfaces.IExtRoot"
modules="other_module.factories"
iobase="other_module.externalization.IOBase"
register_legacy_search_module="yes" />
<ext:classObjectFactory
factory="third_module.Factory"
name="AName" />
<ext:anonymousObjectFactory
factory="module3.Factory"
for="interfaces.ISchema"
field="field" />
<ext:anonymousObjectFactoryInPlace
for="interfaces.ISchema"
field="field2" />
</configure>
-
interface
IRegisterInternalizationMimeFactoriesDirective
[source]¶ Defines the
ext:registerMimeFactories
directive.Poke through the classes defined in module. If a class defines the
mimeType
attribute and can be created externally, (because it defines__external_can_create__
to be true), registers a factory utility under themimeType
name. (For backwards compatibility,mime_type
is accepted if there is nomimeType
.)Factories are discovered using
find_factories_in_module
.See
nti.externalization.internalization.find_factory_for()
for how factories are used.-
module
¶ Module to scan for Mime factories to add
Implementation: zope.configuration.fields.GlobalObject
Read Only: False Required: True Default Value: None
-
-
interface
IAutoPackageExternalizationDirective
[source]¶ Defines the
ext:registerAutoPackageIO
directive.This directive combines the effects of
IRegisterInternalizationMimeFactoriesDirective
with that ofautopackage
, removing all need to repeat root interfaces and module names.After this directive is complete, a new class that descends from
AutoPackageSearchingScopedInterfaceObjectIO
will be registered as theIInternalObjectIO
adapter for all of the root_interface objects, and the modules (or factory_modules) will be searched for object factories viaIRegisterInternalizationMimeFactoriesDirective
.Changed in version 1.0: Add the register_legacy_search_module keyword argument, defaulting to False. Previously legacy search modules would always be registered, but now you must explicitly ask for it.
-
root_interfaces
¶ The root interfaces defined by the package.
Implementation: zope.configuration.fields.Tokens
Read Only: False Required: True Default Value: None Allowed Type: list
Value Type
Implementation: zope.configuration.fields.GlobalInterface
Read Only: False Required: True Default Value: None Value Type
Implementation: zope.schema.InterfaceField
Read Only: False Required: True Default Value: None
-
factory_modules
¶ If given, module names that should be searched for internalization factories.
If not given, all modules will be examined. If given, only these modules will be searched.
Implementation: zope.configuration.fields.Tokens
Read Only: False Required: False Default Value: None Allowed Type: list
Value Type
Implementation: zope.configuration.fields.GlobalObject
Read Only: False Required: True Default Value: None
-
register_legacy_search_module
¶ Register found factories by their class name.
If true (not the default), then, in addition to registering factories by their mime type, also register them all by their class name. This is not recommended; currently no conflicts are caught and the order is ill-defined. See https://github.com/NextThought/nti.externalization/issues/33
Implementation: zope.configuration.fields.Bool
Read Only: False Required: False Default Value: False Allowed Type: bool
-
iobase
¶ If given, a base class that will be used. You can customize aspects of externalization that way.
This class should descend from
object
, and it should implement the extension methods documented to customizeAutoPackageSearchingScopedInterfaceObjectIO
.Implementation: zope.configuration.fields.GlobalObject
Read Only: False Required: False Default Value: None
-
modules
¶ Module names that contain the implementations of the root_interfaces.
Implementation: zope.configuration.fields.Tokens
Read Only: False Required: True Default Value: None Allowed Type: list
Value Type
Implementation: zope.configuration.fields.GlobalObject
Read Only: False Required: True Default Value: None
-
-
interface
IClassObjectFactoryDirective
[source]¶ Defines the
ext:classObjectFactory
directive.This directive registers a single
nti.externalization.interfaces.IClassObjectFactory
.The factory will be registered for a class object.
-
factory
¶ The class object that will be created.
This must define the
__external_can_create__
attribute to be true.Implementation: zope.configuration.fields.GlobalObject
Read Only: False Required: True Default Value: None
-
description
¶ Description
Provides a description for the object.
Implementation: zope.configuration.fields.MessageID
Read Only: False Required: False Default Value: None Allowed Type: unicode
-
name
¶ The name for the factory.
If not given, the
__external_class_name__
of the class will be used. If that’s not available, the__name__
will be used.Implementation: zope.configuration.fields.PythonIdentifier
Read Only: False Required: False Default Value: None Allowed Type: str
-
trusted
¶ Ignore any value for
__external_can_create__
on the factory.Implementation: zope.configuration.fields.Bool
Read Only: False Required: False Default Value: False Allowed Type: bool
-
title
¶ Title
Provides a title for the object.
Implementation: zope.configuration.fields.MessageID
Read Only: False Required: False Default Value: None Allowed Type: unicode
-
-
interface
IBaseAnonymousObjectFactoryDirective
[source]¶ The common parts of anonymous object factory directives.
New in version 1.0a3.
-
field
¶ The name of the schema field
The factory results will be assigned to this field.
Implementation: zope.configuration.fields.PythonIdentifier
Read Only: False Required: True Default Value: None Allowed Type: str
-
for_
¶ The interface that is the parent object this will be used for
Implementation: zope.configuration.fields.GlobalInterface
Read Only: False Required: True Default Value: None Value Type
Implementation: zope.schema.InterfaceField
Read Only: False Required: True Default Value: None
-
-
interface
IAnonymousObjectFactoryDirective
[source]¶ Extends:
nti.externalization.zcml.IBaseAnonymousObjectFactoryDirective
Defines the
ext:anonymousObjectFactory
directive.This directive registers a single
nti.externaliaztion.interfaces.IAnonymousObjectFactory
for a single field used within a single object.New in version 1.0a3.
-
trusted
¶ Ignore any value for
__external_can_create__
on the factory.Implementation: zope.configuration.fields.Bool
Read Only: False Required: False Default Value: False Allowed Type: bool
-
factory
¶ The class object that will be created.
Implementation: zope.configuration.fields.GlobalObject
Read Only: False Required: True Default Value: None
-
description
¶ Description
Provides a description for the object.
Implementation: zope.configuration.fields.MessageID
Read Only: False Required: False Default Value: None Allowed Type: unicode
-
pass_external_object_to_factory
¶ Pass the external object to the factory.
If true (not the default), then, the factory will recieve one argument, the anonymous external data. Otherwise, it gets no arguments.
Implementation: zope.configuration.fields.Bool
Read Only: False Required: False Default Value: False Allowed Type: bool
-
title
¶ Title
Provides a title for the object.
Implementation: zope.configuration.fields.MessageID
Read Only: False Required: False Default Value: None Allowed Type: unicode
-
-
interface
IAnonymousObjectFactoryInPlaceDirective
[source]¶ Extends:
nti.externalization.zcml.IBaseAnonymousObjectFactoryDirective
Defines the
anonymousObjectFactoryInPlace
directive.This directive causes the external object itself to be used and updated in place. This is helpful when the object itself is not modelled, but its values are.
Such data might look like this:
{'home': {'MimeType': 'Address', ...}, 'work': {'MimeType': "Address', ...}}
And it might have a schema field that looks like this:
class IAddress(Interface): pass class IHasAddresses(Interface): addresses = Dict( title=u"A mapping of address objects.", key_type=TextLine(title=u"Adresss key"), value_type=Object(IAddress))
The ZCML would then look like this:
<ext:anonymoustObjectFactoryInPlace for="IHasAddresses" field="addresses" />
New in version 1.0a3.
-
find_factories_in_module
(module, case_sensitive=False)[source]¶ Look through the
vars
of module to find any eligible factory functions.An eligible factory is a callable object with a True value for the attribute
__external_can_create__
.If module is really a module, then only objects that are defined in that module will be found. Otherwise (module is some namespace object) any callable object is acceptable.
Parameters: case_sensitive (bool) – If False (the default), then the results will have each factory twice, once with its found name, and once with its name lower cased. Returns: An iterable of found (name, factory).