# Path: lambda_src/runcmd/docker/errors.py
# class BuildError(Exception):
#     pass
# 
# Path: lambda_src/runcmd/docker/models/resource.py
# class Collection(object):
#     """
#     A base class for representing all objects of a particular type on the
#     server.
#     """
# 
#     #: The type of object this collection represents, set by subclasses
#     model = None
# 
#     def __init__(self, client=None):
#         #: The client pointing at the server that this collection of objects
#         #: is on.
#         self.client = client
# 
#     def __call__(self, *args, **kwargs):
#         raise TypeError(
#             "'{}' object is not callable. You might be trying to use the old "
#             "(pre-2.0) API - use docker.APIClient if so."
#             .format(self.__class__.__name__))
# 
#     def list(self):
#         raise NotImplementedError
# 
#     def get(self, key):
#         raise NotImplementedError
# 
#     def create(self, attrs=None):
#         raise NotImplementedError
# 
#     def prepare_model(self, attrs):
#         """
#         Create a model from a set of attributes.
#         """
#         if isinstance(attrs, Model):
#             attrs.client = self.client
#             attrs.collection = self
#             return attrs
#         elif isinstance(attrs, dict):
#             return self.model(attrs=attrs, client=self.client, collection=self)
#         else:
#             raise Exception("Can't create %s from %s" %
#                             (self.model.__name__, attrs))
# 
# class Model(object):
#     """
#     A base class for representing a single object on the server.
#     """
#     id_attribute = 'Id'
# 
#     def __init__(self, attrs=None, client=None, collection=None):
#         #: A client pointing at the server that this object is on.
#         self.client = client
# 
#         #: The collection that this model is part of.
#         self.collection = collection
# 
#         #: The raw representation of this object from the API
#         self.attrs = attrs
#         if self.attrs is None:
#             self.attrs = {}
# 
#     def __repr__(self):
#         return "<%s: %s>" % (self.__class__.__name__, self.short_id)
# 
#     def __eq__(self, other):
#         return isinstance(other, self.__class__) and self.id == other.id
# 
#     @property
#     def id(self):
#         """
#         The ID of the object.
#         """
#         return self.attrs.get(self.id_attribute)
# 
#     @property
#     def short_id(self):
#         """
#         The ID of the object, truncated to 10 characters.
#         """
#         return self.id[:10]
# 
#     def reload(self):
#         """
#         Load this object from the server again and update ``attrs`` with the
#         new data.
#         """
#         new_model = self.collection.get(self.id)
#         self.attrs = new_model.attrs


import re
import six
from ..api import APIClient
from ..errors import BuildError
from ..utils.json_stream import json_stream
from .resource import Collection, Model
                - cpusetcpus (str): CPUs in which to allow execution, e.g.,
                    ``"0-3"``, ``"0,1"``
            decode (bool): If set to ``True``, the returned stream will be
                decoded into dicts on the fly. Default ``False``.

        Returns:
            (:py:class:`Image`): The built image.

        Raises:
            :py:class:`docker.errors.BuildError`
                If there is an error during the build.
            :py:class:`docker.errors.APIError`
                If the server returns any other error.
            ``TypeError``
                If neither ``path`` nor ``fileobj`` is specified.
        """
        resp = self.client.api.build(**kwargs)
        if isinstance(resp, six.string_types):
            return self.get(resp)
        events = list(json_stream(resp))
        if not events:
            return BuildError('Unknown')
        event = events[-1]
        if 'stream' in event:
            match = re.search(r'Successfully built ([0-9a-f]+)',
                              event.get('stream', ''))
            if match:
                image_id = match.group(1)
                return self.get(image_id)


# Path: lambda_src/runcmd/docker/errors.py
# class BuildError(Exception):
#     pass
# 
# Path: lambda_src/runcmd/docker/models/resource.py
# class Collection(object):
#     """
#     A base class for representing all objects of a particular type on the
#     server.
#     """
# 
#     #: The type of object this collection represents, set by subclasses
#     model = None
# 
#     def __init__(self, client=None):
#         #: The client pointing at the server that this collection of objects
#         #: is on.
#         self.client = client
# 
#     def __call__(self, *args, **kwargs):
#         raise TypeError(
#             "'{}' object is not callable. You might be trying to use the old "
#             "(pre-2.0) API - use docker.APIClient if so."
#             .format(self.__class__.__name__))
# 
#     def list(self):
#         raise NotImplementedError
# 
#     def get(self, key):
#         raise NotImplementedError
# 
#     def create(self, attrs=None):
#         raise NotImplementedError
# 
#     def prepare_model(self, attrs):
#         """
#         Create a model from a set of attributes.
#         """
#         if isinstance(attrs, Model):
#             attrs.client = self.client
#             attrs.collection = self
#             return attrs
#         elif isinstance(attrs, dict):
#             return self.model(attrs=attrs, client=self.client, collection=self)
#         else:
#             raise Exception("Can't create %s from %s" %
#                             (self.model.__name__, attrs))
# 
# class Model(object):
#     """
#     A base class for representing a single object on the server.
#     """
#     id_attribute = 'Id'
# 
#     def __init__(self, attrs=None, client=None, collection=None):
#         #: A client pointing at the server that this object is on.
#         self.client = client
# 
#         #: The collection that this model is part of.
#         self.collection = collection
# 
#         #: The raw representation of this object from the API
#         self.attrs = attrs
#         if self.attrs is None:
#             self.attrs = {}
# 
#     def __repr__(self):
#         return "<%s: %s>" % (self.__class__.__name__, self.short_id)
# 
#     def __eq__(self, other):
#         return isinstance(other, self.__class__) and self.id == other.id
# 
#     @property
#     def id(self):
#         """
#         The ID of the object.
#         """
#         return self.attrs.get(self.id_attribute)
# 
#     @property
#     def short_id(self):
#         """
#         The ID of the object, truncated to 10 characters.
#         """
#         return self.id[:10]
# 
#     def reload(self):
#         """
#         Load this object from the server again and update ``attrs`` with the
#         new data.
#         """
#         new_model = self.collection.get(self.id)
#         self.attrs = new_model.attrs


# Path: lambda_src/runcmd/docker/models/images.py
import re
import six
from ..api import APIClient
from ..errors import BuildError
from ..utils.json_stream import json_stream
from .resource import Collection, Model

                - cpusetcpus (str): CPUs in which to allow execution, e.g.,
                    ``"0-3"``, ``"0,1"``
            decode (bool): If set to ``True``, the returned stream will be
                decoded into dicts on the fly. Default ``False``.

        Returns:
            (:py:class:`Image`): The built image.

        Raises:
            :py:class:`docker.errors.BuildError`
                If there is an error during the build.
            :py:class:`docker.errors.APIError`
                If the server returns any other error.
            ``TypeError``
                If neither ``path`` nor ``fileobj`` is specified.
        """
        resp = self.client.api.build(**kwargs)
        if isinstance(resp, six.string_types):
            return self.get(resp)
        events = list(json_stream(resp))
        if not events:
            return BuildError('Unknown')
        event = events[-1]
        if 'stream' in event:
            match = re.search(r'Successfully built ([0-9a-f]+)',
                              event.get('stream', ''))
            if match:
                image_id = match.group(1)
                return self.get(image_id)


        raise BuildError(event.get('error') or event)