/usr/share/pyshared/zope/dublincore/tests/timeannotators.txt is in python-zope.dublincore 3.8.2-0ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 | ===============
Time annotators
===============
Time annotators store the creation resp. last modification time of an object.
Set up
======
>>> class Content(object):
... created = None
... modified = None
The annotations are stored on the ``IZopeDublinCore`` adapter. This dummy adapter
reads and writes from/to the context object.
>>> import zope.component
>>> import zope.dublincore.interfaces
>>> class DummyDublinCore(object):
... def __init__(self, context):
... self.__dict__['context'] = context
...
... def __getattr__(self, name):
... return getattr(self.context, name)
...
... def __setattr__(self, name, value):
... setattr(self.context, name, value)
>>> zope.component.provideAdapter(
... DummyDublinCore, (Content,), zope.dublincore.interfaces.IZopeDublinCore)
Created annotator
=================
The created annotator sets creation and modification time to current time.
>>> content = Content()
It is registered for the ``ObjectCreatedEvent``:
>>> import zope.dublincore.timeannotators
>>> import zope.lifecycleevent.interfaces
>>> zope.component.provideHandler(
... zope.dublincore.timeannotators.CreatedAnnotator,
... (zope.lifecycleevent.interfaces.IObjectCreatedEvent,))
>>> import zope.event
>>> import zope.lifecycleevent
>>> zope.event.notify(zope.lifecycleevent.ObjectCreatedEvent(content))
Both ``created`` and ``modified`` get set:
>>> content.created
datetime.datetime(<DATETIME>, tzinfo=<UTC>)
>>> content.modified
datetime.datetime(<DATETIME>, tzinfo=<UTC>)
The created annotator can also be registered for (object, event):
>>> zope.component.provideHandler(
... zope.dublincore.timeannotators.CreatedAnnotator,
... (None,
... zope.lifecycleevent.interfaces.IObjectCreatedEvent,))
>>> content = Content()
>>> ignored = zope.component.subscribers(
... (content, zope.lifecycleevent.ObjectCreatedEvent(content)), None)
Both ``created`` and ``modified`` get set this way, too:
>>> content.created
datetime.datetime(<DATETIME>, tzinfo=<UTC>)
>>> content.modified
datetime.datetime(<DATETIME>, tzinfo=<UTC>)
Modified annotator
==================
The modified annotator only sets the modification time to current time.
>>> content = Content()
It is registered for the ``ObjectModifiedEvent``:
>>> zope.component.provideHandler(
... zope.dublincore.timeannotators.ModifiedAnnotator,
... (zope.lifecycleevent.interfaces.IObjectModifiedEvent,))
>>> zope.event.notify(zope.lifecycleevent.ObjectModifiedEvent(content))
Only ``modified`` gets set:
>>> print content.created
None
>>> content.modified
datetime.datetime(<DATETIME>, tzinfo=<UTC>)
The modified annotator can also be registered for (object, event):
>>> zope.component.provideHandler(
... zope.dublincore.timeannotators.ModifiedAnnotator,
... (None,
... zope.lifecycleevent.interfaces.IObjectModifiedEvent,))
>>> content = Content()
>>> ignored = zope.component.subscribers(
... (content, zope.lifecycleevent.ObjectModifiedEvent(content)), None)
``modified`` gets set, this way, too:
>>> print content.created
None
>>> content.modified
datetime.datetime(<DATETIME>, tzinfo=<UTC>)
|