ztm.interfacemanager ==================== ztm.interfacemanager offers functionality to automatically add marker interfaces to instances of topics (and role players) using their subject identifier. >>> import zope.interface >>> import ztm.interfacemanager >>> class IArticle(zope.interface.Interface): ... """A marker interface for instances of the topic type Article.""" ... ztm.interfacemanager.bind_to_instances_of(u'http://psi.example.com/article') ... The interface is now registered with the InterfaceManager utility. >>> cr = zope.component.getSiteManager() >>> manager = cr.getUtility(ztm.interfacemanager.interfaces.IInterfaceManager) >>> u'http://psi.example.com/article' in manager.topicinterfaces True Now we create a topic map: >>> topicmap = ztm.topicmaps.topicmap.TopicMap() And fill it some content: >>> topictype = topicmap.createTopic() >>> topictype.addSubjectIdentifier(u'http://psi.example.com/article') >>> topic = topicmap.createTopic() >>> topic.addType(topictype) >>> IArticle.providedBy(topic) True Notice that the interface is not added to the topic type whose subject identifier is used: >>> IArticle.providedBy(topictype) False You can also mark role players: >>> class IPlaywright(Interface): ... """A marker for topics playing the author in associations.""" ... ztm.interfacemanager.bind_to_players_of(u'http://psi.example.com/playwright') ... Lets fill the topic map with more types needed to create an association: >>> person = topicmap.createTopic() >>> playwright = topicmap.createTopic(subjectidentifiers=(u'http://psi.example.com/playwright',)) >>> authorship = topicmap.createTopic() >>> work = topicmap.createTopic() >>> play = topicmap.createTopic() >>> ibsen = topicmap.createTopic() >>> ibsen.addType(person) >>> heddagabler = topicmap.createTopic() >>> heddagabler.addType(play) And finally the association. >>> topicmap.createAssociation(authorship, playwright, ibsen, work, heddagabler) #DOCTEST: +ELLIPSIS Now ibsen should be marked as a playwright. >>> IPlaywright.providedBy(author) True >>> IPlaywright.providedBy(heddagabler) False .. warning:: ztm.interfacemanager does not currently follow super-sub type relationships. This may be added in the future. See the `ztm.interfacemanager documentation`_ for more information. .. _ztm.interfacemanager documentation: http://ztmproject.org/documentation/ztm.interfacemanager