From 95dab599daa6f3ed33eec5678ff6a653f9f9a836 Mon Sep 17 00:00:00 2001 From: Elrond Date: Tue, 19 Mar 2013 12:42:28 +0100 Subject: [PATCH] Add sniff_handler method to mediamanagers. The MediaManagerBase gets a fallback "return False" one. The Compat-Manager checks in the dict and calls that one or returns False. --- mediagoblin/media_types/__init__.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/mediagoblin/media_types/__init__.py b/mediagoblin/media_types/__init__.py index 91e3443b..20e1918e 100644 --- a/mediagoblin/media_types/__init__.py +++ b/mediagoblin/media_types/__init__.py @@ -38,6 +38,10 @@ class MediaManagerBase(object): # Please override in actual media managers media_fetch_order = None + @staticmethod + def sniff_handler(*args, **kwargs): + return False + def __init__(self, entry): self.entry = entry @@ -68,6 +72,12 @@ class CompatMediaManager(object): def media_fetch_order(self): return self.mm_dict.get('media_fetch_order') + def sniff_handler(self, *args, **kwargs): + func = self.mm_dict.get("sniff_handler", None) + if func is not None: + return func(*args, **kwargs) + return False + def __getattr__(self, i): return self.mm_dict[i] @@ -90,8 +100,7 @@ def sniff_media(media): for media_type, manager in get_media_managers(): _log.info('Sniffing {0}'.format(media_type)) - if 'sniff_handler' in manager and \ - manager.sniff_handler(media_file, media=media): + if manager.sniff_handler(media_file, media=media): _log.info('{0} accepts the file'.format(media_type)) return media_type, manager else: -- 2.25.1