# Path: media_nommer/utils/logger.py
# def debug(message):
# def info(message):
# def warning(message):
# def error(message_or_obj=None):
# 
# Path: media_nommer/utils/uri_parsing.py
# def get_values_from_media_uri(uri_str):
#     """
#     Given a valid URI string, break it up into its component pieces like
#     protocol, hostname, and path, along with some optional elements like 
#     username, password, and port. All of these values are returned in a dict.
#     
#     The following keys should always be in the dict:
#     * protocol
#     * host
#     * path
#     
#     The following are set when present, but absent when not:
#     * port
#     * username
#     * password
#     
#     :param str uri_str: A valid URI string.
#     :returns: A dict of strings.
#     """
#     # The dict that will be later returned.
#     values = {}
# 
#     dslash_split = uri_str.split('://', 1)
#     values['protocol'] = dslash_split[0]
#     try:
#         url_str = dslash_split[1]
#     except IndexError:
#         # If this split fails, we've definitely forgotten the protocol.
#         msg = 'No protocol specified. Pre-pend "proto://" to your current ' \
#               'value of "%s", where "proto" is your choice of protocol.' % uri_str
#         raise InvalidUri(msg)
# 
#     # An '@' symbol indicates the presence of a username and/or username+pass.
#     has_auth_details = '@' in url_str
#     if has_auth_details:
#         auth_host_split = url_str.split('@', 1)
#         # Should be just the username or username@pass.
#         auth_details = auth_host_split[0]
# 
#         # A colon is used to separate username from passwords.
#         has_password = ':' in auth_details
#         if has_password:
#             user_pass_split = auth_details.split(':', 1)
#             values['username'] = user_pass_split[0]
#             values['password'] = user_pass_split[1]
#         else:
#             values['username'] = auth_details
# 
#         # Seperated the host/path from auth details. 
#         host_and_path = auth_host_split[1]
#     else:
#         host_and_path = url_str
# 
#     # Split the host and path up.
#     host_path_split = host_and_path.split('/', 1)
#     values['host'] = host_path_split[0]
# 
#     try:
#         values['path'] = host_path_split[1]
#     except IndexError:
#         # This means that no trailing slash was present in the URI str after
#         # the host was specified. Assume they mean the root path.
#         values['path'] = '/'
# 
#     if ':' in values['host']:
#         # Looks like they specified a port.
#         host_port_split = values['host'].split(':')
#         values['host'] = host_port_split[0]
#         values['port'] = host_port_split[1]
# 
#     return values
# 
# 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 boto
from media_nommer.utils import logger
from media_nommer.utils.uri_parsing import get_values_from_media_uri
from media_nommer.core.storage_backends.exceptions import InfileNotFoundException
from media_nommer.core.storage_backends.base_backend import BaseStorageBackend
                                          values['password'])
        bucket = conn.get_bucket(values['host'])
        key = bucket.get_key(values['path'])

        logger.debug("S3Backend.download_file(): " \
                     "Downloading: %s" % uri)

        try:
            key.get_contents_to_file(fobj)
        except AttributeError:
            # Raised by ResumableDownloadHandler in boto when the given S3
            # key can't be found.
            message = "The specified input file cannot be found."
            raise InfileNotFoundException(message)

        logger.debug("S3Backend.download_file(): " \
                     "Download of %s completed." % uri)
        return fobj

    @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 populate the S3 key from.
        :rtype: :py:class:`boto.s3.key.Key`
        :returns: The newly set boto key.
        """
        # Breaks the URI into usable componenents.

# Path: media_nommer/utils/logger.py
# def debug(message):
# def info(message):
# def warning(message):
# def error(message_or_obj=None):
# 
# Path: media_nommer/utils/uri_parsing.py
# def get_values_from_media_uri(uri_str):
#     """
#     Given a valid URI string, break it up into its component pieces like
#     protocol, hostname, and path, along with some optional elements like 
#     username, password, and port. All of these values are returned in a dict.
#     
#     The following keys should always be in the dict:
#     * protocol
#     * host
#     * path
#     
#     The following are set when present, but absent when not:
#     * port
#     * username
#     * password
#     
#     :param str uri_str: A valid URI string.
#     :returns: A dict of strings.
#     """
#     # The dict that will be later returned.
#     values = {}
# 
#     dslash_split = uri_str.split('://', 1)
#     values['protocol'] = dslash_split[0]
#     try:
#         url_str = dslash_split[1]
#     except IndexError:
#         # If this split fails, we've definitely forgotten the protocol.
#         msg = 'No protocol specified. Pre-pend "proto://" to your current ' \
#               'value of "%s", where "proto" is your choice of protocol.' % uri_str
#         raise InvalidUri(msg)
# 
#     # An '@' symbol indicates the presence of a username and/or username+pass.
#     has_auth_details = '@' in url_str
#     if has_auth_details:
#         auth_host_split = url_str.split('@', 1)
#         # Should be just the username or username@pass.
#         auth_details = auth_host_split[0]
# 
#         # A colon is used to separate username from passwords.
#         has_password = ':' in auth_details
#         if has_password:
#             user_pass_split = auth_details.split(':', 1)
#             values['username'] = user_pass_split[0]
#             values['password'] = user_pass_split[1]
#         else:
#             values['username'] = auth_details
# 
#         # Seperated the host/path from auth details. 
#         host_and_path = auth_host_split[1]
#     else:
#         host_and_path = url_str
# 
#     # Split the host and path up.
#     host_path_split = host_and_path.split('/', 1)
#     values['host'] = host_path_split[0]
# 
#     try:
#         values['path'] = host_path_split[1]
#     except IndexError:
#         # This means that no trailing slash was present in the URI str after
#         # the host was specified. Assume they mean the root path.
#         values['path'] = '/'
# 
#     if ':' in values['host']:
#         # Looks like they specified a port.
#         host_port_split = values['host'].split(':')
#         values['host'] = host_port_split[0]
#         values['port'] = host_port_split[1]
# 
#     return values
# 
# 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/s3.py
import boto
from media_nommer.utils import logger
from media_nommer.utils.uri_parsing import get_values_from_media_uri
from media_nommer.core.storage_backends.exceptions import InfileNotFoundException
from media_nommer.core.storage_backends.base_backend import BaseStorageBackend

                                          values['password'])
        bucket = conn.get_bucket(values['host'])
        key = bucket.get_key(values['path'])

        logger.debug("S3Backend.download_file(): " \
                     "Downloading: %s" % uri)

        try:
            key.get_contents_to_file(fobj)
        except AttributeError:
            # Raised by ResumableDownloadHandler in boto when the given S3
            # key can't be found.
            message = "The specified input file cannot be found."
            raise InfileNotFoundException(message)

        logger.debug("S3Backend.download_file(): " \
                     "Download of %s completed." % uri)
        return fobj

    @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 populate the S3 key from.
        :rtype: :py:class:`boto.s3.key.Key`
        :returns: The newly set boto key.
        """
        # Breaks the URI into usable componenents.

        values = get_values_from_media_uri(uri)