blob: e73ca52e6f6c37dd4cb7e8cbbd7abfc957afd70d [file] [log] [blame]
from abc import abstractmethod
from twitter.common.lang import Interface
class Fetcher(Interface):
class Error(Exception): pass
def fetch(self, uri, directory):
class FetcherFactory(object):
"""A singleton factory for Fetchers."""
def register_fetcher(cls, scheme, fetcher):
cls._FETCHERS[scheme.rstrip('://')] = fetcher
def get_fetcher(cls, uri):
:return: A Fetcher instance that matches this URI. None if no fetcher is registered with the
URI's scheme.
scheme = uri.split('://')[0]
fetcher = cls._FETCHERS.get(scheme)
if not fetcher:
raise ValueError("No Fetcher is registered for URI scheme '%s'" % scheme)
return fetcher