# Path: media_nommer/utils/logger.py
# def debug(message):
# def info(message):
# def warning(message):
# def error(message_or_obj=None):
# 
# Path: media_nommer/core/storage_backends/exceptions.py
# class InfileNotFoundException(StorageException):
#     """
#     Raised by storage backends when the given source_path (the media to encode)
#     cannot be found. 
#     """
#     pass
# 
# Path: media_nommer/core/storage_backends/base_backend.py
# class BaseStorageBackend(object):
#     """
#     This class serves as a protocol for storage backends. Each storage backend
#     should override the following methods, if supported by whatever protocols
#     they interact with.
#     """
#     @classmethod
#     def download_file(cls, uri, fobj):
#         """
#         Given a URI, download the file to the ``fobj`` file-like object.
# 
#         :param str uri: The URI of a file to download.
#         :param file fobj: A file-like object to download the file to.
#         :rtype: file
#         :returns: A file handle to the downloaded file.
#         """
#         msg = "Backend doesn't implement download_file()"
#         raise NotImplementedError(msg)
# 
#     @classmethod
#     def upload_file(cls, uri, fobj):
#         """
#         Given a file-like object, upload it to the specified URI.
# 
#         :param str uri: The URI to upload the file to.
#         :param file fobj: The file-like object to upload.
#         :returns: Return value and type depends on backend.
#         """
#         msg = "Backend doesn't implement upload_file()"
#         raise NotImplementedError(msg)


import urllib2
from media_nommer.utils import logger
from media_nommer.core.storage_backends.exceptions import InfileNotFoundException
from media_nommer.core.storage_backends.base_backend import BaseStorageBackend
an http:// or https:// protocol specified.
"""

class HTTPBackend(BaseStorageBackend):
    """
    Abstracts access to HTTP via the common set of file storage backend methods.

    .. note:: ``upload_file`` is not implemented yet, not sure how
        it should work.
    """
    @classmethod
    def download_file(cls, uri, fobj):
        """
        Given a URI, download the file to the ``fobj`` file-like object.
        
        :param str uri: The URI of a file to download.
        :param file fobj: A file-like object to download the file to.
        :rtype: file
        :returns: A file handle to the downloaded file.
        """
        request = urllib2.Request(uri)

        try:
            download = urllib2.urlopen(request)
        except urllib2.URLError, e:
            message = "The specified input file cannot be found: %s" % e
            raise InfileNotFoundException(message)

        fobj.write(download.read())


# Path: media_nommer/utils/logger.py
# def debug(message):
# def info(message):
# def warning(message):
# def error(message_or_obj=None):
# 
# Path: media_nommer/core/storage_backends/exceptions.py
# class InfileNotFoundException(StorageException):
#     """
#     Raised by storage backends when the given source_path (the media to encode)
#     cannot be found. 
#     """
#     pass
# 
# Path: media_nommer/core/storage_backends/base_backend.py
# class BaseStorageBackend(object):
#     """
#     This class serves as a protocol for storage backends. Each storage backend
#     should override the following methods, if supported by whatever protocols
#     they interact with.
#     """
#     @classmethod
#     def download_file(cls, uri, fobj):
#         """
#         Given a URI, download the file to the ``fobj`` file-like object.
# 
#         :param str uri: The URI of a file to download.
#         :param file fobj: A file-like object to download the file to.
#         :rtype: file
#         :returns: A file handle to the downloaded file.
#         """
#         msg = "Backend doesn't implement download_file()"
#         raise NotImplementedError(msg)
# 
#     @classmethod
#     def upload_file(cls, uri, fobj):
#         """
#         Given a file-like object, upload it to the specified URI.
# 
#         :param str uri: The URI to upload the file to.
#         :param file fobj: The file-like object to upload.
#         :returns: Return value and type depends on backend.
#         """
#         msg = "Backend doesn't implement upload_file()"
#         raise NotImplementedError(msg)


# Path: media_nommer/core/storage_backends/http.py
import urllib2
from media_nommer.utils import logger
from media_nommer.core.storage_backends.exceptions import InfileNotFoundException
from media_nommer.core.storage_backends.base_backend import BaseStorageBackend

an http:// or https:// protocol specified.
"""

class HTTPBackend(BaseStorageBackend):
    """
    Abstracts access to HTTP via the common set of file storage backend methods.

    .. note:: ``upload_file`` is not implemented yet, not sure how
        it should work.
    """
    @classmethod
    def download_file(cls, uri, fobj):
        """
        Given a URI, download the file to the ``fobj`` file-like object.
        
        :param str uri: The URI of a file to download.
        :param file fobj: A file-like object to download the file to.
        :rtype: file
        :returns: A file handle to the downloaded file.
        """
        request = urllib2.Request(uri)

        try:
            download = urllib2.urlopen(request)
        except urllib2.URLError, e:
            message = "The specified input file cannot be found: %s" % e
            raise InfileNotFoundException(message)

        fobj.write(download.read())


        logger.debug("HTTPBackend.download_file(): " \