Use object factory in annotations adapters
authorThierry Florac <thierry.florac@onf.fr>
Thu, 17 Jan 2019 10:48:03 +0100
changeset 123 6c949ed8d549
parent 122 650c19fa0e5b
child 124 9855b3ca8577
Use object factory in annotations adapters
src/pyams_media/media.py
--- a/src/pyams_media/media.py	Fri Dec 28 10:57:14 2018 +0100
+++ b/src/pyams_media/media.py	Thu Jan 17 10:48:03 2019 +0100
@@ -12,32 +12,27 @@
 
 __docformat__ = 'restructuredtext'
 
-
-# import standard library
 import re
-
 from mimetypes import guess_extension, guess_type
 
-# import interfaces
+from pyramid.events import subscriber
+from transaction.interfaces import ITransactionManager
+from zope.container.folder import Folder
+from zope.interface import Interface, alsoProvides
+from zope.lifecycleevent import ObjectCreatedEvent
+from zope.lifecycleevent.interfaces import IObjectAddedEvent
+from zope.traversing.interfaces import ITraversable
+
+from pyams_file.file import FileFactory
 from pyams_file.interfaces import IFile
-from pyams_media.interfaces import IMediaInfo, CUSTOM_AUDIO_TYPES, CUSTOM_VIDEO_TYPES, IMediaConversions, \
-    IMediaConversion, IMediaConversionUtility, VIDEO_FRAME_SIZE, MEDIA_CONVERSIONS_KEY
-from pyams_utils.interfaces.tales import ITALESExtension
-from transaction.interfaces import ITransactionManager
-from zope.lifecycleevent.interfaces import IObjectAddedEvent
-
-# import packages
-from pyams_file.file import FileFactory
 from pyams_media.ffbase import FFmpeg
 from pyams_media.ffdocument import FFDocument
-from pyams_utils.adapter import adapter_config, ContextAdapter, ContextRequestViewAdapter, get_annotation_adapter
-from pyams_utils.registry import query_utility, get_global_registry
-from pyramid.events import subscriber
-from zope.container.folder import Folder
-from zope.interface import implementer, alsoProvides, Interface
-from zope.lifecycleevent import ObjectCreatedEvent
-from zope.traversing.interfaces import ITraversable
-
+from pyams_media.interfaces import CUSTOM_AUDIO_TYPES, CUSTOM_VIDEO_TYPES, IMediaConversion, IMediaConversionUtility, \
+    IMediaConversions, IMediaInfo, MEDIA_CONVERSIONS_KEY, VIDEO_FRAME_SIZE
+from pyams_utils.adapter import ContextAdapter, ContextRequestViewAdapter, adapter_config, get_annotation_adapter
+from pyams_utils.factory import factory_config
+from pyams_utils.interfaces.tales import ITALESExtension
+from pyams_utils.registry import get_global_registry, query_utility
 
 #
 # Media infos
@@ -71,7 +66,7 @@
 MEDIA_FRAME_SIZE = re.compile(".*-(.*)\..*")
 
 
-@implementer(IMediaConversions)
+@factory_config(IMediaConversions)
 class MediaConversions(Folder):
     """Media conversions"""
 
@@ -122,7 +117,7 @@
 @adapter_config(context=IFile, provides=IMediaConversions)
 def media_conversions_factory(context):
     """Media conversions factory"""
-    return get_annotation_adapter(context, MEDIA_CONVERSIONS_KEY, MediaConversions,
+    return get_annotation_adapter(context, MEDIA_CONVERSIONS_KEY, IMediaConversions,
                                   name='++conversions++')