# Path: webpack/exceptions.py
# class BundlingError(Exception):
#     pass
# 
# class WebpackWarning(Warning):
#     pass
# 
# Path: webpack/bundle.py
# class WebpackBundle(object):
#     def __init__(self, data, options=None):
#         self.data = data
#         self.options = options
# 
#     def render_css(self):
#         urls = []
#         for entry in self.get_urls().values():
#             urls += entry['css']
#         rendered = ['<link rel="stylesheet" href="{}">'.format(url) for url in urls]
#         return '\n'.join(rendered)
# 
#     def render_js(self):
#         urls = []
#         for entry in self.get_urls().values():
#             urls += entry['js']
#         rendered = ['<script src="{}"></script>'.format(url) for url in urls]
#         return '\n'.join(rendered)
# 
#     def get_assets(self):
#         return self.data['assets']
# 
#     def get_output(self):
#         return self.data['output']
# 
#     def get_urls(self):
#         return self.data['urls']
# 
#     def get_output_options(self):
#         return self.data['outputOptions']
# 
#     def get_library(self):
#         return self.get_output_options().get('library', None)
# 
# Path: webpack/exceptions.py
# class BuildServerConnectionError(Exception):
#     pass
# 
# class BuildServerUnexpectedResponse(Exception):
#     pass
# 
# Path: webpack/options.py
# def generate_compiler_options(config_file, extra_context=None, setting_overrides=None):
#     if not _setting(setting_overrides, 'OUTPUT_ROOT'):
#         raise ImproperlyConfigured('webpack.conf.settings.OUTPUT_ROOT has not been defined.')
# 
#     if not _setting(setting_overrides, 'STATIC_URL'):
#         raise ImproperlyConfigured('webpack.conf.settings.STATIC_URL has not been defined.')
# 
#     context = {}
#     if conf.settings.CONTEXT:
#         context.update(conf.settings.CONTEXT)
#     if extra_context:
#         context.update(extra_context)
# 
#     options = {
#         'config': find_config_file(config_file),
#         'watch': _setting(setting_overrides, 'WATCH'),
#         'cache': _setting(setting_overrides, 'CACHE'),
#         'hmr': _setting(setting_overrides, 'HMR'),
#         'context': context,
#         'outputPath': conf.settings.get_path_to_output_dir(),
#         'publicPath': conf.settings.get_public_path(),
#         'staticRoot': _setting(setting_overrides, 'OUTPUT_ROOT'),
#         'staticUrl': _setting(setting_overrides, 'STATIC_URL'),
#         'aggregateTimeout': _setting(setting_overrides, 'AGGREGATE_TIMEOUT'),
#     }
# 
#     if conf.settings.CACHE_DIR:
#         options['cacheDir'] = _setting(setting_overrides, 'CACHE_DIR')
# 
#     # As it defaults to `undefined` it's only defined if necessary
#     if conf.settings.POLL is not None:
#         options['poll'] = _setting(setting_overrides, 'POLL')
# 
#     # Avoid collisions by directing output into unique directories
#     hashable_content = '{}__{}'.format(json.dumps(options), __version__)
#     hashable_content = hashable_content.encode('utf-8')
#     options_hash = hashlib.md5(hashable_content).hexdigest()
#     options['outputPath'] = os.path.join(options['outputPath'], options_hash)
#     options['publicPath'] += '/' + options_hash
# 
#     # Used in the test suite
#     options['__python_webpack_hash__'] = options_hash
# 
#     return options


import requests
import warnings
from .exceptions import BundlingError, WebpackWarning
from .bundle import WebpackBundle
from .exceptions import BuildServerConnectionError, BuildServerUnexpectedResponse
from .options import generate_compiler_options

        try:
            res = requests.post(self.url, json=options)
        except requests.ConnectionError:
            raise BuildServerConnectionError('Tried to send build request to {}'.format(self.url))

        if res.status_code != 200:
            raise BuildServerUnexpectedResponse(
                'Unexpected response from {} - {}: {}'.format(self.url, res.status_code, res.text)
            )

        output = res.json()

        error = output['error']
        data = output['data']
        stats = data and data.get('stats', None)

        if stats:
            for warning in stats['warnings']:
                warnings.warn(warning, WebpackWarning)

        if error:
            # webpack-build spits up the first error that it sees, but sometimes the most
            # informative errors are in the `stats.errors` object
            if stats and stats['errors']:
                error_objects = stats['errors']
            else:
                error_objects = [error]

            errors = []

# Path: webpack/exceptions.py
# class BundlingError(Exception):
#     pass
# 
# class WebpackWarning(Warning):
#     pass
# 
# Path: webpack/bundle.py
# class WebpackBundle(object):
#     def __init__(self, data, options=None):
#         self.data = data
#         self.options = options
# 
#     def render_css(self):
#         urls = []
#         for entry in self.get_urls().values():
#             urls += entry['css']
#         rendered = ['<link rel="stylesheet" href="{}">'.format(url) for url in urls]
#         return '\n'.join(rendered)
# 
#     def render_js(self):
#         urls = []
#         for entry in self.get_urls().values():
#             urls += entry['js']
#         rendered = ['<script src="{}"></script>'.format(url) for url in urls]
#         return '\n'.join(rendered)
# 
#     def get_assets(self):
#         return self.data['assets']
# 
#     def get_output(self):
#         return self.data['output']
# 
#     def get_urls(self):
#         return self.data['urls']
# 
#     def get_output_options(self):
#         return self.data['outputOptions']
# 
#     def get_library(self):
#         return self.get_output_options().get('library', None)
# 
# Path: webpack/exceptions.py
# class BuildServerConnectionError(Exception):
#     pass
# 
# class BuildServerUnexpectedResponse(Exception):
#     pass
# 
# Path: webpack/options.py
# def generate_compiler_options(config_file, extra_context=None, setting_overrides=None):
#     if not _setting(setting_overrides, 'OUTPUT_ROOT'):
#         raise ImproperlyConfigured('webpack.conf.settings.OUTPUT_ROOT has not been defined.')
# 
#     if not _setting(setting_overrides, 'STATIC_URL'):
#         raise ImproperlyConfigured('webpack.conf.settings.STATIC_URL has not been defined.')
# 
#     context = {}
#     if conf.settings.CONTEXT:
#         context.update(conf.settings.CONTEXT)
#     if extra_context:
#         context.update(extra_context)
# 
#     options = {
#         'config': find_config_file(config_file),
#         'watch': _setting(setting_overrides, 'WATCH'),
#         'cache': _setting(setting_overrides, 'CACHE'),
#         'hmr': _setting(setting_overrides, 'HMR'),
#         'context': context,
#         'outputPath': conf.settings.get_path_to_output_dir(),
#         'publicPath': conf.settings.get_public_path(),
#         'staticRoot': _setting(setting_overrides, 'OUTPUT_ROOT'),
#         'staticUrl': _setting(setting_overrides, 'STATIC_URL'),
#         'aggregateTimeout': _setting(setting_overrides, 'AGGREGATE_TIMEOUT'),
#     }
# 
#     if conf.settings.CACHE_DIR:
#         options['cacheDir'] = _setting(setting_overrides, 'CACHE_DIR')
# 
#     # As it defaults to `undefined` it's only defined if necessary
#     if conf.settings.POLL is not None:
#         options['poll'] = _setting(setting_overrides, 'POLL')
# 
#     # Avoid collisions by directing output into unique directories
#     hashable_content = '{}__{}'.format(json.dumps(options), __version__)
#     hashable_content = hashable_content.encode('utf-8')
#     options_hash = hashlib.md5(hashable_content).hexdigest()
#     options['outputPath'] = os.path.join(options['outputPath'], options_hash)
#     options['publicPath'] += '/' + options_hash
# 
#     # Used in the test suite
#     options['__python_webpack_hash__'] = options_hash
# 
#     return options


# Path: webpack/build_server.py
import requests
import warnings
from .exceptions import BundlingError, WebpackWarning
from .bundle import WebpackBundle
from .exceptions import BuildServerConnectionError, BuildServerUnexpectedResponse
from .options import generate_compiler_options


        try:
            res = requests.post(self.url, json=options)
        except requests.ConnectionError:
            raise BuildServerConnectionError('Tried to send build request to {}'.format(self.url))

        if res.status_code != 200:
            raise BuildServerUnexpectedResponse(
                'Unexpected response from {} - {}: {}'.format(self.url, res.status_code, res.text)
            )

        output = res.json()

        error = output['error']
        data = output['data']
        stats = data and data.get('stats', None)

        if stats:
            for warning in stats['warnings']:
                warnings.warn(warning, WebpackWarning)

        if error:
            # webpack-build spits up the first error that it sees, but sometimes the most
            # informative errors are in the `stats.errors` object
            if stats and stats['errors']:
                error_objects = stats['errors']
            else:
                error_objects = [error]

            errors = []

            for err in error_objects: