# Path: mfr/core/exceptions.py
# class PluginError(waterbutler.core.exceptions.PluginError):
# class ExtensionError(PluginError):
# class RendererError(ExtensionError):
# class ExporterError(ExtensionError):
# class SubprocessError(ExporterError):
# class ProviderError(PluginError):
# class DownloadError(ProviderError):
# class MetadataError(ProviderError):
# class TooBigToRenderError(ProviderError):
# class DriverManagerError(PluginError):
# class MakeProviderError(DriverManagerError):
# class UnsupportedExtensionError(DriverManagerError):
# class MakeRendererError(UnsupportedExtensionError):
# class MakeExporterError(UnsupportedExtensionError):
#     __TYPE = 'plugin'
#     __TYPE = 'extension'
#     __TYPE = 'renderer'
#     __TYPE = 'exporter'
#     __TYPE = 'subprocess'
#     __TYPE = 'provider'
#     __TYPE = 'download'
#     __TYPE = 'metadata'
#     __TYPE = 'too_big_to_render'
#     __TYPE = 'drivermanager'
#     __TYPE = 'unsupported_extension'
#     def __init__(self, message, *args, code=500, **kwargs):
#     def as_html(self):
#     def _format_original_exception(self, exc):
#     def __init__(self, message, *args, extension: str='', **kwargs):
#     def __init__(self, message, *args, renderer_class: str='', **kwargs):
#     def __init__(self, message, *args, exporter_class: str='', **kwargs):
#     def __init__(self, message, *args, code: int=500, process: str='', cmd: str='',
#                  returncode: int=None, path: str='', **kwargs):
#     def __init__(self, message, *args, provider: str='', **kwargs):
#     def __init__(self, message, *args, download_url: str='', response: str='', **kwargs):
#     def __init__(self, message, *args, metadata_url: str='', response: str='', **kwargs):
#     def __init__(self, message, *args, requested_size: int=None, maximum_size: int=None,
#                  code: int=400, **kwargs):
#     def __init__(self, message, *args, namespace: str='', name: str='', invoke_on_load: bool=None,
#                  invoke_args: dict=None, **kwargs):
#     def __init__(self, message, *args, code: int=500, **kwargs):
#     def __init__(self, *args, code: int=400, handler_type: str='', **kwargs):
#     def __init__(self, *args, **kwargs):
#     def __init__(self, *args, **kwargs):
# 
# Path: mfr/core/provider.py
# class BaseProvider(metaclass=abc.ABCMeta):
# class ProviderMetadata:
#     def __init__(self, request, url, action=None):
#     def NAME(self):
#     def metadata(self):
#     def download(self):
#     def __init__(self, name, ext, content_type, unique_key, download_url, stable_id=None):
#     def serialize(self):
# 
# Path: mfr/settings.py
# MAX_FILE_SIZE_TO_RENDER = {'.csv': 100000000,
#                            '.xlsx': 1000000000,
#                            '.tsv': 1000000000,
#                            '.sav': 1000000000,
#                            '.xls': 1000000000,
#                            '.zip': 1000000000}
# 
# Path: mfr/core/exceptions.py
# class TooBigToRenderError(ProviderError):
#     """If the user tries to render a file larger than a server specified maximum, throw a
#     TooBigToRenderError.
#     """
# 
#     __TYPE = 'too_big_to_render'
# 
#     def __init__(self, message, *args, requested_size: int=None, maximum_size: int=None,
#                  code: int=400, **kwargs):
#         super().__init__(message, *args, code=code, **kwargs)
#         self.requested_size = requested_size
#         self.maximum_size = maximum_size
#         self.attr_stack.append([self.__TYPE, {
#             'requested_size': self.requested_size,
#             'maximum_size': self.maximum_size,
#         }])


import os
import json
import hashlib
import logging
import mimetypes
import furl
import aiohttp
from urllib.parse import urlparse
from aiohttp.errors import ContentEncodingError
from waterbutler.core import streams
from mfr.core import exceptions
from mfr.core import provider
from mfr.core.utils import sizeof_fmt
from mfr.providers.osf import settings
from mfr.settings import MAX_FILE_SIZE_TO_RENDER
from mfr.core.exceptions import TooBigToRenderError
            if response_code != 200:
                raise exceptions.MetadataError(
                    'Failed to fetch file metadata from WaterButler. Received response: ',
                    'code {} {}'.format(str(response_code), str(response_reason)),
                    metadata_url=download_url,
                    response=response_reason,
                    provider=self.NAME,
                    code=400
                )

            try:
                metadata = {'data': json.loads(response_headers['x-waterbutler-metadata'])['attributes']}
            except ContentEncodingError:
                pass  # hack: aiohttp tries to unzip empty body when Content-Encoding is set

        self.metrics.add('metadata.raw', metadata)

        # e.g.,
        # metadata = {'data': {
        #     'name': 'blah.png',
        #     'contentType': 'image/png',
        #     'etag': 'ABCD123456...',
        #     'extra': {
        #         ...
        #     },
        # }}

        name, ext = os.path.splitext(metadata['data']['name'])
        size = metadata['data']['size']


# Path: mfr/core/exceptions.py
# class PluginError(waterbutler.core.exceptions.PluginError):
# class ExtensionError(PluginError):
# class RendererError(ExtensionError):
# class ExporterError(ExtensionError):
# class SubprocessError(ExporterError):
# class ProviderError(PluginError):
# class DownloadError(ProviderError):
# class MetadataError(ProviderError):
# class TooBigToRenderError(ProviderError):
# class DriverManagerError(PluginError):
# class MakeProviderError(DriverManagerError):
# class UnsupportedExtensionError(DriverManagerError):
# class MakeRendererError(UnsupportedExtensionError):
# class MakeExporterError(UnsupportedExtensionError):
#     __TYPE = 'plugin'
#     __TYPE = 'extension'
#     __TYPE = 'renderer'
#     __TYPE = 'exporter'
#     __TYPE = 'subprocess'
#     __TYPE = 'provider'
#     __TYPE = 'download'
#     __TYPE = 'metadata'
#     __TYPE = 'too_big_to_render'
#     __TYPE = 'drivermanager'
#     __TYPE = 'unsupported_extension'
#     def __init__(self, message, *args, code=500, **kwargs):
#     def as_html(self):
#     def _format_original_exception(self, exc):
#     def __init__(self, message, *args, extension: str='', **kwargs):
#     def __init__(self, message, *args, renderer_class: str='', **kwargs):
#     def __init__(self, message, *args, exporter_class: str='', **kwargs):
#     def __init__(self, message, *args, code: int=500, process: str='', cmd: str='',
#                  returncode: int=None, path: str='', **kwargs):
#     def __init__(self, message, *args, provider: str='', **kwargs):
#     def __init__(self, message, *args, download_url: str='', response: str='', **kwargs):
#     def __init__(self, message, *args, metadata_url: str='', response: str='', **kwargs):
#     def __init__(self, message, *args, requested_size: int=None, maximum_size: int=None,
#                  code: int=400, **kwargs):
#     def __init__(self, message, *args, namespace: str='', name: str='', invoke_on_load: bool=None,
#                  invoke_args: dict=None, **kwargs):
#     def __init__(self, message, *args, code: int=500, **kwargs):
#     def __init__(self, *args, code: int=400, handler_type: str='', **kwargs):
#     def __init__(self, *args, **kwargs):
#     def __init__(self, *args, **kwargs):
# 
# Path: mfr/core/provider.py
# class BaseProvider(metaclass=abc.ABCMeta):
# class ProviderMetadata:
#     def __init__(self, request, url, action=None):
#     def NAME(self):
#     def metadata(self):
#     def download(self):
#     def __init__(self, name, ext, content_type, unique_key, download_url, stable_id=None):
#     def serialize(self):
# 
# Path: mfr/settings.py
# MAX_FILE_SIZE_TO_RENDER = {'.csv': 100000000,
#                            '.xlsx': 1000000000,
#                            '.tsv': 1000000000,
#                            '.sav': 1000000000,
#                            '.xls': 1000000000,
#                            '.zip': 1000000000}
# 
# Path: mfr/core/exceptions.py
# class TooBigToRenderError(ProviderError):
#     """If the user tries to render a file larger than a server specified maximum, throw a
#     TooBigToRenderError.
#     """
# 
#     __TYPE = 'too_big_to_render'
# 
#     def __init__(self, message, *args, requested_size: int=None, maximum_size: int=None,
#                  code: int=400, **kwargs):
#         super().__init__(message, *args, code=code, **kwargs)
#         self.requested_size = requested_size
#         self.maximum_size = maximum_size
#         self.attr_stack.append([self.__TYPE, {
#             'requested_size': self.requested_size,
#             'maximum_size': self.maximum_size,
#         }])


# Path: mfr/providers/osf/provider.py
import os
import json
import hashlib
import logging
import mimetypes
import furl
import aiohttp
from urllib.parse import urlparse
from aiohttp.errors import ContentEncodingError
from waterbutler.core import streams
from mfr.core import exceptions
from mfr.core import provider
from mfr.core.utils import sizeof_fmt
from mfr.providers.osf import settings
from mfr.settings import MAX_FILE_SIZE_TO_RENDER
from mfr.core.exceptions import TooBigToRenderError

            if response_code != 200:
                raise exceptions.MetadataError(
                    'Failed to fetch file metadata from WaterButler. Received response: ',
                    'code {} {}'.format(str(response_code), str(response_reason)),
                    metadata_url=download_url,
                    response=response_reason,
                    provider=self.NAME,
                    code=400
                )

            try:
                metadata = {'data': json.loads(response_headers['x-waterbutler-metadata'])['attributes']}
            except ContentEncodingError:
                pass  # hack: aiohttp tries to unzip empty body when Content-Encoding is set

        self.metrics.add('metadata.raw', metadata)

        # e.g.,
        # metadata = {'data': {
        #     'name': 'blah.png',
        #     'contentType': 'image/png',
        #     'etag': 'ABCD123456...',
        #     'extra': {
        #         ...
        #     },
        # }}

        name, ext = os.path.splitext(metadata['data']['name'])
        size = metadata['data']['size']


        max_file_size = MAX_FILE_SIZE_TO_RENDER.get(ext)