We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
DockerClient.images.pull() has inconsistent parameter naming
The [documentation](https://docker-py.readthedocs.io/en/stable/images.html) for Images::pull states the usage as: pull(name, **kwargs). However, its Parameters description does not have 'name' but just has 'repository' (which used to work with the older low-level api client)

Looking at the code, the docker-py/docker/models/images.py has the function declared as:
def pull(self, name, **kwargs) and passes name, kwargs to the docker-py/docker/api/image.py:: ImageApiMixin::pull whose parameter is named repository (and not name).

The consequence is:
**client.images.pull(repository=<repository_details>)** fails with TypeError: pull() takes exactly 2 arguments (1 given) since it expects name though as per the documentation, repository should work. 

client.images.pull(name=<name>, repository=<repo_details>) fails with TypeError: pull() got multiple values for keyword argument 'repository' as the name parameter was passed in to the next method which interprets it as repository. 

client.images.pull('image_name') - works - and works for a name that has registry / tag in it. 

Given that under the wraps, we are accepting a repository format for this API, Can we just rename the only mandatory parameter as repository (from current 'name'). This would be consistent with the older behavior and to be consistent with the push api - and more in line with the actual default behavior when no parameter name is specified. 





--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `docker/models/images.py`
Content:
```
1 import itertools
2 import re
3 
4 import six
5 
6 from ..api import APIClient
7 from ..errors import BuildError, ImageLoadError
8 from ..utils import parse_repository_tag
9 from ..utils.json_stream import json_stream
10 from .resource import Collection, Model
11 
12 
13 class Image(Model):
14     """
15     An image on the server.
16     """
17     def __repr__(self):
18         return "<%s: '%s'>" % (self.__class__.__name__, "', '".join(self.tags))
19 
20     @property
21     def labels(self):
22         """
23         The labels of an image as dictionary.
24         """
25         result = self.attrs['Config'].get('Labels')
26         return result or {}
27 
28     @property
29     def short_id(self):
30         """
31         The ID of the image truncated to 10 characters, plus the ``sha256:``
32         prefix.
33         """
34         if self.id.startswith('sha256:'):
35             return self.id[:17]
36         return self.id[:10]
37 
38     @property
39     def tags(self):
40         """
41         The image's tags.
42         """
43         tags = self.attrs.get('RepoTags')
44         if tags is None:
45             tags = []
46         return [tag for tag in tags if tag != '<none>:<none>']
47 
48     def history(self):
49         """
50         Show the history of an image.
51 
52         Returns:
53             (str): The history of the image.
54 
55         Raises:
56             :py:class:`docker.errors.APIError`
57                 If the server returns an error.
58         """
59         return self.client.api.history(self.id)
60 
61     def save(self):
62         """
63         Get a tarball of an image. Similar to the ``docker save`` command.
64 
65         Returns:
66             (generator): A stream of raw archive data.
67 
68         Raises:
69             :py:class:`docker.errors.APIError`
70                 If the server returns an error.
71 
72         Example:
73 
74             >>> image = cli.get_image("busybox:latest")
75             >>> f = open('/tmp/busybox-latest.tar', 'w')
76             >>> for chunk in image:
77             >>>   f.write(chunk)
78             >>> f.close()
79         """
80         return self.client.api.get_image(self.id)
81 
82     def tag(self, repository, tag=None, **kwargs):
83         """
84         Tag this image into a repository. Similar to the ``docker tag``
85         command.
86 
87         Args:
88             repository (str): The repository to set for the tag
89             tag (str): The tag name
90             force (bool): Force
91 
92         Raises:
93             :py:class:`docker.errors.APIError`
94                 If the server returns an error.
95 
96         Returns:
97             (bool): ``True`` if successful
98         """
99         return self.client.api.tag(self.id, repository, tag=tag, **kwargs)
100 
101 
102 class ImageCollection(Collection):
103     model = Image
104 
105     def build(self, **kwargs):
106         """
107         Build an image and return it. Similar to the ``docker build``
108         command. Either ``path`` or ``fileobj`` must be set.
109 
110         If you have a tar file for the Docker build context (including a
111         Dockerfile) already, pass a readable file-like object to ``fileobj``
112         and also pass ``custom_context=True``. If the stream is compressed
113         also, set ``encoding`` to the correct value (e.g ``gzip``).
114 
115         If you want to get the raw output of the build, use the
116         :py:meth:`~docker.api.build.BuildApiMixin.build` method in the
117         low-level API.
118 
119         Args:
120             path (str): Path to the directory containing the Dockerfile
121             fileobj: A file object to use as the Dockerfile. (Or a file-like
122                 object)
123             tag (str): A tag to add to the final image
124             quiet (bool): Whether to return the status
125             nocache (bool): Don't use the cache when set to ``True``
126             rm (bool): Remove intermediate containers. The ``docker build``
127                 command now defaults to ``--rm=true``, but we have kept the old
128                 default of `False` to preserve backward compatibility
129             timeout (int): HTTP timeout
130             custom_context (bool): Optional if using ``fileobj``
131             encoding (str): The encoding for a stream. Set to ``gzip`` for
132                 compressing
133             pull (bool): Downloads any updates to the FROM image in Dockerfiles
134             forcerm (bool): Always remove intermediate containers, even after
135                 unsuccessful builds
136             dockerfile (str): path within the build context to the Dockerfile
137             buildargs (dict): A dictionary of build arguments
138             container_limits (dict): A dictionary of limits applied to each
139                 container created by the build process. Valid keys:
140 
141                 - memory (int): set memory limit for build
142                 - memswap (int): Total memory (memory + swap), -1 to disable
143                     swap
144                 - cpushares (int): CPU shares (relative weight)
145                 - cpusetcpus (str): CPUs in which to allow execution, e.g.,
146                     ``"0-3"``, ``"0,1"``
147             shmsize (int): Size of `/dev/shm` in bytes. The size must be
148                 greater than 0. If omitted the system uses 64MB
149             labels (dict): A dictionary of labels to set on the image
150             cache_from (list): A list of images used for build cache
151                 resolution
152             target (str): Name of the build-stage to build in a multi-stage
153                 Dockerfile
154             network_mode (str): networking mode for the run commands during
155                 build
156             squash (bool): Squash the resulting images layers into a
157                 single layer.
158             extra_hosts (dict): Extra hosts to add to /etc/hosts in building
159                 containers, as a mapping of hostname to IP address.
160             platform (str): Platform in the format ``os[/arch[/variant]]``.
161 
162         Returns:
163             (tuple): The first item is the :py:class:`Image` object for the
164                 image that was build. The second item is a generator of the
165                 build logs as JSON-decoded objects.
166 
167         Raises:
168             :py:class:`docker.errors.BuildError`
169                 If there is an error during the build.
170             :py:class:`docker.errors.APIError`
171                 If the server returns any other error.
172             ``TypeError``
173                 If neither ``path`` nor ``fileobj`` is specified.
174         """
175         resp = self.client.api.build(**kwargs)
176         if isinstance(resp, six.string_types):
177             return self.get(resp)
178         last_event = None
179         image_id = None
180         result_stream, internal_stream = itertools.tee(json_stream(resp))
181         for chunk in internal_stream:
182             if 'error' in chunk:
183                 raise BuildError(chunk['error'], result_stream)
184             if 'stream' in chunk:
185                 match = re.search(
186                     r'(^Successfully built |sha256:)([0-9a-f]+)$',
187                     chunk['stream']
188                 )
189                 if match:
190                     image_id = match.group(2)
191             last_event = chunk
192         if image_id:
193             return (self.get(image_id), result_stream)
194         raise BuildError(last_event or 'Unknown', result_stream)
195 
196     def get(self, name):
197         """
198         Gets an image.
199 
200         Args:
201             name (str): The name of the image.
202 
203         Returns:
204             (:py:class:`Image`): The image.
205 
206         Raises:
207             :py:class:`docker.errors.ImageNotFound`
208                 If the image does not exist.
209             :py:class:`docker.errors.APIError`
210                 If the server returns an error.
211         """
212         return self.prepare_model(self.client.api.inspect_image(name))
213 
214     def list(self, name=None, all=False, filters=None):
215         """
216         List images on the server.
217 
218         Args:
219             name (str): Only show images belonging to the repository ``name``
220             all (bool): Show intermediate image layers. By default, these are
221                 filtered out.
222             filters (dict): Filters to be processed on the image list.
223                 Available filters:
224                 - ``dangling`` (bool)
225                 - ``label`` (str): format either ``key`` or ``key=value``
226 
227         Returns:
228             (list of :py:class:`Image`): The images.
229 
230         Raises:
231             :py:class:`docker.errors.APIError`
232                 If the server returns an error.
233         """
234         resp = self.client.api.images(name=name, all=all, filters=filters)
235         return [self.get(r["Id"]) for r in resp]
236 
237     def load(self, data):
238         """
239         Load an image that was previously saved using
240         :py:meth:`~docker.models.images.Image.save` (or ``docker save``).
241         Similar to ``docker load``.
242 
243         Args:
244             data (binary): Image data to be loaded.
245 
246         Returns:
247             (list of :py:class:`Image`): The images.
248 
249         Raises:
250             :py:class:`docker.errors.APIError`
251                 If the server returns an error.
252         """
253         resp = self.client.api.load_image(data)
254         images = []
255         for chunk in resp:
256             if 'stream' in chunk:
257                 match = re.search(
258                     r'(^Loaded image ID: |^Loaded image: )(.+)$',
259                     chunk['stream']
260                 )
261                 if match:
262                     image_id = match.group(2)
263                     images.append(image_id)
264             if 'error' in chunk:
265                 raise ImageLoadError(chunk['error'])
266 
267         return [self.get(i) for i in images]
268 
269     def pull(self, name, tag=None, **kwargs):
270         """
271         Pull an image of the given name and return it. Similar to the
272         ``docker pull`` command.
273         If no tag is specified, all tags from that repository will be
274         pulled.
275 
276         If you want to get the raw pull output, use the
277         :py:meth:`~docker.api.image.ImageApiMixin.pull` method in the
278         low-level API.
279 
280         Args:
281             name (str): The repository to pull
282             tag (str): The tag to pull
283             insecure_registry (bool): Use an insecure registry
284             auth_config (dict): Override the credentials that
285                 :py:meth:`~docker.client.DockerClient.login` has set for
286                 this request. ``auth_config`` should contain the ``username``
287                 and ``password`` keys to be valid.
288             platform (str): Platform in the format ``os[/arch[/variant]]``
289 
290         Returns:
291             (:py:class:`Image` or list): The image that has been pulled.
292                 If no ``tag`` was specified, the method will return a list
293                 of :py:class:`Image` objects belonging to this repository.
294 
295         Raises:
296             :py:class:`docker.errors.APIError`
297                 If the server returns an error.
298 
299         Example:
300 
301             >>> # Pull the image tagged `latest` in the busybox repo
302             >>> image = client.images.pull('busybox:latest')
303 
304             >>> # Pull all tags in the busybox repo
305             >>> images = client.images.pull('busybox')
306         """
307         if not tag:
308             name, tag = parse_repository_tag(name)
309 
310         self.client.api.pull(name, tag=tag, **kwargs)
311         if tag:
312             return self.get('{0}:{1}'.format(name, tag))
313         return self.list(name)
314 
315     def push(self, repository, tag=None, **kwargs):
316         return self.client.api.push(repository, tag=tag, **kwargs)
317     push.__doc__ = APIClient.push.__doc__
318 
319     def remove(self, *args, **kwargs):
320         self.client.api.remove_image(*args, **kwargs)
321     remove.__doc__ = APIClient.remove_image.__doc__
322 
323     def search(self, *args, **kwargs):
324         return self.client.api.search(*args, **kwargs)
325     search.__doc__ = APIClient.search.__doc__
326 
327     def prune(self, filters=None):
328         return self.client.api.prune_images(filters=filters)
329     prune.__doc__ = APIClient.prune_images.__doc__
330
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/docker/models/images.py b/docker/models/images.py
--- a/docker/models/images.py
+++ b/docker/models/images.py
@@ -266,7 +266,7 @@
 
         return [self.get(i) for i in images]
 
-    def pull(self, name, tag=None, **kwargs):
+    def pull(self, repository, tag=None, **kwargs):
         """
         Pull an image of the given name and return it. Similar to the
         ``docker pull`` command.
@@ -280,7 +280,6 @@
         Args:
             name (str): The repository to pull
             tag (str): The tag to pull
-            insecure_registry (bool): Use an insecure registry
             auth_config (dict): Override the credentials that
                 :py:meth:`~docker.client.DockerClient.login` has set for
                 this request. ``auth_config`` should contain the ``username``
@@ -305,12 +304,12 @@
             >>> images = client.images.pull('busybox')
         """
         if not tag:
-            name, tag = parse_repository_tag(name)
+            repository, tag = parse_repository_tag(repository)
 
-        self.client.api.pull(name, tag=tag, **kwargs)
+        self.client.api.pull(repository, tag=tag, **kwargs)
         if tag:
-            return self.get('{0}:{1}'.format(name, tag))
-        return self.list(name)
+            return self.get('{0}:{1}'.format(repository, tag))
+        return self.list(repository)
 
     def push(self, repository, tag=None, **kwargs):
         return self.client.api.push(repository, tag=tag, **kwargs)

{"golden_diff": "diff --git a/docker/models/images.py b/docker/models/images.py\n--- a/docker/models/images.py\n+++ b/docker/models/images.py\n@@ -266,7 +266,7 @@\n \n         return [self.get(i) for i in images]\n \n-    def pull(self, name, tag=None, **kwargs):\n+    def pull(self, repository, tag=None, **kwargs):\n         \"\"\"\n         Pull an image of the given name and return it. Similar to the\n         ``docker pull`` command.\n@@ -280,7 +280,6 @@\n         Args:\n             name (str): The repository to pull\n             tag (str): The tag to pull\n-            insecure_registry (bool): Use an insecure registry\n             auth_config (dict): Override the credentials that\n                 :py:meth:`~docker.client.DockerClient.login` has set for\n                 this request. ``auth_config`` should contain the ``username``\n@@ -305,12 +304,12 @@\n             >>> images = client.images.pull('busybox')\n         \"\"\"\n         if not tag:\n-            name, tag = parse_repository_tag(name)\n+            repository, tag = parse_repository_tag(repository)\n \n-        self.client.api.pull(name, tag=tag, **kwargs)\n+        self.client.api.pull(repository, tag=tag, **kwargs)\n         if tag:\n-            return self.get('{0}:{1}'.format(name, tag))\n-        return self.list(name)\n+            return self.get('{0}:{1}'.format(repository, tag))\n+        return self.list(repository)\n \n     def push(self, repository, tag=None, **kwargs):\n         return self.client.api.push(repository, tag=tag, **kwargs)\n", "issue": "DockerClient.images.pull() has inconsistent parameter naming\nThe [documentation](https://docker-py.readthedocs.io/en/stable/images.html) for Images::pull states the usage as: pull(name, **kwargs). However, its Parameters description does not have 'name' but just has 'repository' (which used to work with the older low-level api client)\r\n\r\nLooking at the code, the docker-py/docker/models/images.py has the function declared as:\r\ndef pull(self, name, **kwargs) and passes name, kwargs to the docker-py/docker/api/image.py:: ImageApiMixin::pull whose parameter is named repository (and not name).\r\n\r\nThe consequence is:\r\n**client.images.pull(repository=<repository_details>)** fails with TypeError: pull() takes exactly 2 arguments (1 given) since it expects name though as per the documentation, repository should work. \r\n\r\nclient.images.pull(name=<name>, repository=<repo_details>) fails with TypeError: pull() got multiple values for keyword argument 'repository' as the name parameter was passed in to the next method which interprets it as repository. \r\n\r\nclient.images.pull('image_name') - works - and works for a name that has registry / tag in it. \r\n\r\nGiven that under the wraps, we are accepting a repository format for this API, Can we just rename the only mandatory parameter as repository (from current 'name'). This would be consistent with the older behavior and to be consistent with the push api - and more in line with the actual default behavior when no parameter name is specified. \r\n\r\n\r\n\r\n\n", "before_files": [{"content": "import itertools\nimport re\n\nimport six\n\nfrom ..api import APIClient\nfrom ..errors import BuildError, ImageLoadError\nfrom ..utils import parse_repository_tag\nfrom ..utils.json_stream import json_stream\nfrom .resource import Collection, Model\n\n\nclass Image(Model):\n    \"\"\"\n    An image on the server.\n    \"\"\"\n    def __repr__(self):\n        return \"<%s: '%s'>\" % (self.__class__.__name__, \"', '\".join(self.tags))\n\n    @property\n    def labels(self):\n        \"\"\"\n        The labels of an image as dictionary.\n        \"\"\"\n        result = self.attrs['Config'].get('Labels')\n        return result or {}\n\n    @property\n    def short_id(self):\n        \"\"\"\n        The ID of the image truncated to 10 characters, plus the ``sha256:``\n        prefix.\n        \"\"\"\n        if self.id.startswith('sha256:'):\n            return self.id[:17]\n        return self.id[:10]\n\n    @property\n    def tags(self):\n        \"\"\"\n        The image's tags.\n        \"\"\"\n        tags = self.attrs.get('RepoTags')\n        if tags is None:\n            tags = []\n        return [tag for tag in tags if tag != '<none>:<none>']\n\n    def history(self):\n        \"\"\"\n        Show the history of an image.\n\n        Returns:\n            (str): The history of the image.\n\n        Raises:\n            :py:class:`docker.errors.APIError`\n                If the server returns an error.\n        \"\"\"\n        return self.client.api.history(self.id)\n\n    def save(self):\n        \"\"\"\n        Get a tarball of an image. Similar to the ``docker save`` command.\n\n        Returns:\n            (generator): A stream of raw archive data.\n\n        Raises:\n            :py:class:`docker.errors.APIError`\n                If the server returns an error.\n\n        Example:\n\n            >>> image = cli.get_image(\"busybox:latest\")\n            >>> f = open('/tmp/busybox-latest.tar', 'w')\n            >>> for chunk in image:\n            >>>   f.write(chunk)\n            >>> f.close()\n        \"\"\"\n        return self.client.api.get_image(self.id)\n\n    def tag(self, repository, tag=None, **kwargs):\n        \"\"\"\n        Tag this image into a repository. Similar to the ``docker tag``\n        command.\n\n        Args:\n            repository (str): The repository to set for the tag\n            tag (str): The tag name\n            force (bool): Force\n\n        Raises:\n            :py:class:`docker.errors.APIError`\n                If the server returns an error.\n\n        Returns:\n            (bool): ``True`` if successful\n        \"\"\"\n        return self.client.api.tag(self.id, repository, tag=tag, **kwargs)\n\n\nclass ImageCollection(Collection):\n    model = Image\n\n    def build(self, **kwargs):\n        \"\"\"\n        Build an image and return it. Similar to the ``docker build``\n        command. Either ``path`` or ``fileobj`` must be set.\n\n        If you have a tar file for the Docker build context (including a\n        Dockerfile) already, pass a readable file-like object to ``fileobj``\n        and also pass ``custom_context=True``. If the stream is compressed\n        also, set ``encoding`` to the correct value (e.g ``gzip``).\n\n        If you want to get the raw output of the build, use the\n        :py:meth:`~docker.api.build.BuildApiMixin.build` method in the\n        low-level API.\n\n        Args:\n            path (str): Path to the directory containing the Dockerfile\n            fileobj: A file object to use as the Dockerfile. (Or a file-like\n                object)\n            tag (str): A tag to add to the final image\n            quiet (bool): Whether to return the status\n            nocache (bool): Don't use the cache when set to ``True``\n            rm (bool): Remove intermediate containers. The ``docker build``\n                command now defaults to ``--rm=true``, but we have kept the old\n                default of `False` to preserve backward compatibility\n            timeout (int): HTTP timeout\n            custom_context (bool): Optional if using ``fileobj``\n            encoding (str): The encoding for a stream. Set to ``gzip`` for\n                compressing\n            pull (bool): Downloads any updates to the FROM image in Dockerfiles\n            forcerm (bool): Always remove intermediate containers, even after\n                unsuccessful builds\n            dockerfile (str): path within the build context to the Dockerfile\n            buildargs (dict): A dictionary of build arguments\n            container_limits (dict): A dictionary of limits applied to each\n                container created by the build process. Valid keys:\n\n                - memory (int): set memory limit for build\n                - memswap (int): Total memory (memory + swap), -1 to disable\n                    swap\n                - cpushares (int): CPU shares (relative weight)\n                - cpusetcpus (str): CPUs in which to allow execution, e.g.,\n                    ``\"0-3\"``, ``\"0,1\"``\n            shmsize (int): Size of `/dev/shm` in bytes. The size must be\n                greater than 0. If omitted the system uses 64MB\n            labels (dict): A dictionary of labels to set on the image\n            cache_from (list): A list of images used for build cache\n                resolution\n            target (str): Name of the build-stage to build in a multi-stage\n                Dockerfile\n            network_mode (str): networking mode for the run commands during\n                build\n            squash (bool): Squash the resulting images layers into a\n                single layer.\n            extra_hosts (dict): Extra hosts to add to /etc/hosts in building\n                containers, as a mapping of hostname to IP address.\n            platform (str): Platform in the format ``os[/arch[/variant]]``.\n\n        Returns:\n            (tuple): The first item is the :py:class:`Image` object for the\n                image that was build. The second item is a generator of the\n                build logs as JSON-decoded objects.\n\n        Raises:\n            :py:class:`docker.errors.BuildError`\n                If there is an error during the build.\n            :py:class:`docker.errors.APIError`\n                If the server returns any other error.\n            ``TypeError``\n                If neither ``path`` nor ``fileobj`` is specified.\n        \"\"\"\n        resp = self.client.api.build(**kwargs)\n        if isinstance(resp, six.string_types):\n            return self.get(resp)\n        last_event = None\n        image_id = None\n        result_stream, internal_stream = itertools.tee(json_stream(resp))\n        for chunk in internal_stream:\n            if 'error' in chunk:\n                raise BuildError(chunk['error'], result_stream)\n            if 'stream' in chunk:\n                match = re.search(\n                    r'(^Successfully built |sha256:)([0-9a-f]+)$',\n                    chunk['stream']\n                )\n                if match:\n                    image_id = match.group(2)\n            last_event = chunk\n        if image_id:\n            return (self.get(image_id), result_stream)\n        raise BuildError(last_event or 'Unknown', result_stream)\n\n    def get(self, name):\n        \"\"\"\n        Gets an image.\n\n        Args:\n            name (str): The name of the image.\n\n        Returns:\n            (:py:class:`Image`): The image.\n\n        Raises:\n            :py:class:`docker.errors.ImageNotFound`\n                If the image does not exist.\n            :py:class:`docker.errors.APIError`\n                If the server returns an error.\n        \"\"\"\n        return self.prepare_model(self.client.api.inspect_image(name))\n\n    def list(self, name=None, all=False, filters=None):\n        \"\"\"\n        List images on the server.\n\n        Args:\n            name (str): Only show images belonging to the repository ``name``\n            all (bool): Show intermediate image layers. By default, these are\n                filtered out.\n            filters (dict): Filters to be processed on the image list.\n                Available filters:\n                - ``dangling`` (bool)\n                - ``label`` (str): format either ``key`` or ``key=value``\n\n        Returns:\n            (list of :py:class:`Image`): The images.\n\n        Raises:\n            :py:class:`docker.errors.APIError`\n                If the server returns an error.\n        \"\"\"\n        resp = self.client.api.images(name=name, all=all, filters=filters)\n        return [self.get(r[\"Id\"]) for r in resp]\n\n    def load(self, data):\n        \"\"\"\n        Load an image that was previously saved using\n        :py:meth:`~docker.models.images.Image.save` (or ``docker save``).\n        Similar to ``docker load``.\n\n        Args:\n            data (binary): Image data to be loaded.\n\n        Returns:\n            (list of :py:class:`Image`): The images.\n\n        Raises:\n            :py:class:`docker.errors.APIError`\n                If the server returns an error.\n        \"\"\"\n        resp = self.client.api.load_image(data)\n        images = []\n        for chunk in resp:\n            if 'stream' in chunk:\n                match = re.search(\n                    r'(^Loaded image ID: |^Loaded image: )(.+)$',\n                    chunk['stream']\n                )\n                if match:\n                    image_id = match.group(2)\n                    images.append(image_id)\n            if 'error' in chunk:\n                raise ImageLoadError(chunk['error'])\n\n        return [self.get(i) for i in images]\n\n    def pull(self, name, tag=None, **kwargs):\n        \"\"\"\n        Pull an image of the given name and return it. Similar to the\n        ``docker pull`` command.\n        If no tag is specified, all tags from that repository will be\n        pulled.\n\n        If you want to get the raw pull output, use the\n        :py:meth:`~docker.api.image.ImageApiMixin.pull` method in the\n        low-level API.\n\n        Args:\n            name (str): The repository to pull\n            tag (str): The tag to pull\n            insecure_registry (bool): Use an insecure registry\n            auth_config (dict): Override the credentials that\n                :py:meth:`~docker.client.DockerClient.login` has set for\n                this request. ``auth_config`` should contain the ``username``\n                and ``password`` keys to be valid.\n            platform (str): Platform in the format ``os[/arch[/variant]]``\n\n        Returns:\n            (:py:class:`Image` or list): The image that has been pulled.\n                If no ``tag`` was specified, the method will return a list\n                of :py:class:`Image` objects belonging to this repository.\n\n        Raises:\n            :py:class:`docker.errors.APIError`\n                If the server returns an error.\n\n        Example:\n\n            >>> # Pull the image tagged `latest` in the busybox repo\n            >>> image = client.images.pull('busybox:latest')\n\n            >>> # Pull all tags in the busybox repo\n            >>> images = client.images.pull('busybox')\n        \"\"\"\n        if not tag:\n            name, tag = parse_repository_tag(name)\n\n        self.client.api.pull(name, tag=tag, **kwargs)\n        if tag:\n            return self.get('{0}:{1}'.format(name, tag))\n        return self.list(name)\n\n    def push(self, repository, tag=None, **kwargs):\n        return self.client.api.push(repository, tag=tag, **kwargs)\n    push.__doc__ = APIClient.push.__doc__\n\n    def remove(self, *args, **kwargs):\n        self.client.api.remove_image(*args, **kwargs)\n    remove.__doc__ = APIClient.remove_image.__doc__\n\n    def search(self, *args, **kwargs):\n        return self.client.api.search(*args, **kwargs)\n    search.__doc__ = APIClient.search.__doc__\n\n    def prune(self, filters=None):\n        return self.client.api.prune_images(filters=filters)\n    prune.__doc__ = APIClient.prune_images.__doc__\n", "path": "docker/models/images.py"}], "after_files": [{"content": "import itertools\nimport re\n\nimport six\n\nfrom ..api import APIClient\nfrom ..errors import BuildError, ImageLoadError\nfrom ..utils import parse_repository_tag\nfrom ..utils.json_stream import json_stream\nfrom .resource import Collection, Model\n\n\nclass Image(Model):\n    \"\"\"\n    An image on the server.\n    \"\"\"\n    def __repr__(self):\n        return \"<%s: '%s'>\" % (self.__class__.__name__, \"', '\".join(self.tags))\n\n    @property\n    def labels(self):\n        \"\"\"\n        The labels of an image as dictionary.\n        \"\"\"\n        result = self.attrs['Config'].get('Labels')\n        return result or {}\n\n    @property\n    def short_id(self):\n        \"\"\"\n        The ID of the image truncated to 10 characters, plus the ``sha256:``\n        prefix.\n        \"\"\"\n        if self.id.startswith('sha256:'):\n            return self.id[:17]\n        return self.id[:10]\n\n    @property\n    def tags(self):\n        \"\"\"\n        The image's tags.\n        \"\"\"\n        tags = self.attrs.get('RepoTags')\n        if tags is None:\n            tags = []\n        return [tag for tag in tags if tag != '<none>:<none>']\n\n    def history(self):\n        \"\"\"\n        Show the history of an image.\n\n        Returns:\n            (str): The history of the image.\n\n        Raises:\n            :py:class:`docker.errors.APIError`\n                If the server returns an error.\n        \"\"\"\n        return self.client.api.history(self.id)\n\n    def save(self):\n        \"\"\"\n        Get a tarball of an image. Similar to the ``docker save`` command.\n\n        Returns:\n            (generator): A stream of raw archive data.\n\n        Raises:\n            :py:class:`docker.errors.APIError`\n                If the server returns an error.\n\n        Example:\n\n            >>> image = cli.get_image(\"busybox:latest\")\n            >>> f = open('/tmp/busybox-latest.tar', 'w')\n            >>> for chunk in image:\n            >>>   f.write(chunk)\n            >>> f.close()\n        \"\"\"\n        return self.client.api.get_image(self.id)\n\n    def tag(self, repository, tag=None, **kwargs):\n        \"\"\"\n        Tag this image into a repository. Similar to the ``docker tag``\n        command.\n\n        Args:\n            repository (str): The repository to set for the tag\n            tag (str): The tag name\n            force (bool): Force\n\n        Raises:\n            :py:class:`docker.errors.APIError`\n                If the server returns an error.\n\n        Returns:\n            (bool): ``True`` if successful\n        \"\"\"\n        return self.client.api.tag(self.id, repository, tag=tag, **kwargs)\n\n\nclass ImageCollection(Collection):\n    model = Image\n\n    def build(self, **kwargs):\n        \"\"\"\n        Build an image and return it. Similar to the ``docker build``\n        command. Either ``path`` or ``fileobj`` must be set.\n\n        If you have a tar file for the Docker build context (including a\n        Dockerfile) already, pass a readable file-like object to ``fileobj``\n        and also pass ``custom_context=True``. If the stream is compressed\n        also, set ``encoding`` to the correct value (e.g ``gzip``).\n\n        If you want to get the raw output of the build, use the\n        :py:meth:`~docker.api.build.BuildApiMixin.build` method in the\n        low-level API.\n\n        Args:\n            path (str): Path to the directory containing the Dockerfile\n            fileobj: A file object to use as the Dockerfile. (Or a file-like\n                object)\n            tag (str): A tag to add to the final image\n            quiet (bool): Whether to return the status\n            nocache (bool): Don't use the cache when set to ``True``\n            rm (bool): Remove intermediate containers. The ``docker build``\n                command now defaults to ``--rm=true``, but we have kept the old\n                default of `False` to preserve backward compatibility\n            timeout (int): HTTP timeout\n            custom_context (bool): Optional if using ``fileobj``\n            encoding (str): The encoding for a stream. Set to ``gzip`` for\n                compressing\n            pull (bool): Downloads any updates to the FROM image in Dockerfiles\n            forcerm (bool): Always remove intermediate containers, even after\n                unsuccessful builds\n            dockerfile (str): path within the build context to the Dockerfile\n            buildargs (dict): A dictionary of build arguments\n            container_limits (dict): A dictionary of limits applied to each\n                container created by the build process. Valid keys:\n\n                - memory (int): set memory limit for build\n                - memswap (int): Total memory (memory + swap), -1 to disable\n                    swap\n                - cpushares (int): CPU shares (relative weight)\n                - cpusetcpus (str): CPUs in which to allow execution, e.g.,\n                    ``\"0-3\"``, ``\"0,1\"``\n            shmsize (int): Size of `/dev/shm` in bytes. The size must be\n                greater than 0. If omitted the system uses 64MB\n            labels (dict): A dictionary of labels to set on the image\n            cache_from (list): A list of images used for build cache\n                resolution\n            target (str): Name of the build-stage to build in a multi-stage\n                Dockerfile\n            network_mode (str): networking mode for the run commands during\n                build\n            squash (bool): Squash the resulting images layers into a\n                single layer.\n            extra_hosts (dict): Extra hosts to add to /etc/hosts in building\n                containers, as a mapping of hostname to IP address.\n            platform (str): Platform in the format ``os[/arch[/variant]]``.\n\n        Returns:\n            (tuple): The first item is the :py:class:`Image` object for the\n                image that was build. The second item is a generator of the\n                build logs as JSON-decoded objects.\n\n        Raises:\n            :py:class:`docker.errors.BuildError`\n                If there is an error during the build.\n            :py:class:`docker.errors.APIError`\n                If the server returns any other error.\n            ``TypeError``\n                If neither ``path`` nor ``fileobj`` is specified.\n        \"\"\"\n        resp = self.client.api.build(**kwargs)\n        if isinstance(resp, six.string_types):\n            return self.get(resp)\n        last_event = None\n        image_id = None\n        result_stream, internal_stream = itertools.tee(json_stream(resp))\n        for chunk in internal_stream:\n            if 'error' in chunk:\n                raise BuildError(chunk['error'], result_stream)\n            if 'stream' in chunk:\n                match = re.search(\n                    r'(^Successfully built |sha256:)([0-9a-f]+)$',\n                    chunk['stream']\n                )\n                if match:\n                    image_id = match.group(2)\n            last_event = chunk\n        if image_id:\n            return (self.get(image_id), result_stream)\n        raise BuildError(last_event or 'Unknown', result_stream)\n\n    def get(self, name):\n        \"\"\"\n        Gets an image.\n\n        Args:\n            name (str): The name of the image.\n\n        Returns:\n            (:py:class:`Image`): The image.\n\n        Raises:\n            :py:class:`docker.errors.ImageNotFound`\n                If the image does not exist.\n            :py:class:`docker.errors.APIError`\n                If the server returns an error.\n        \"\"\"\n        return self.prepare_model(self.client.api.inspect_image(name))\n\n    def list(self, name=None, all=False, filters=None):\n        \"\"\"\n        List images on the server.\n\n        Args:\n            name (str): Only show images belonging to the repository ``name``\n            all (bool): Show intermediate image layers. By default, these are\n                filtered out.\n            filters (dict): Filters to be processed on the image list.\n                Available filters:\n                - ``dangling`` (bool)\n                - ``label`` (str): format either ``key`` or ``key=value``\n\n        Returns:\n            (list of :py:class:`Image`): The images.\n\n        Raises:\n            :py:class:`docker.errors.APIError`\n                If the server returns an error.\n        \"\"\"\n        resp = self.client.api.images(name=name, all=all, filters=filters)\n        return [self.get(r[\"Id\"]) for r in resp]\n\n    def load(self, data):\n        \"\"\"\n        Load an image that was previously saved using\n        :py:meth:`~docker.models.images.Image.save` (or ``docker save``).\n        Similar to ``docker load``.\n\n        Args:\n            data (binary): Image data to be loaded.\n\n        Returns:\n            (list of :py:class:`Image`): The images.\n\n        Raises:\n            :py:class:`docker.errors.APIError`\n                If the server returns an error.\n        \"\"\"\n        resp = self.client.api.load_image(data)\n        images = []\n        for chunk in resp:\n            if 'stream' in chunk:\n                match = re.search(\n                    r'(^Loaded image ID: |^Loaded image: )(.+)$',\n                    chunk['stream']\n                )\n                if match:\n                    image_id = match.group(2)\n                    images.append(image_id)\n            if 'error' in chunk:\n                raise ImageLoadError(chunk['error'])\n\n        return [self.get(i) for i in images]\n\n    def pull(self, repository, tag=None, **kwargs):\n        \"\"\"\n        Pull an image of the given name and return it. Similar to the\n        ``docker pull`` command.\n        If no tag is specified, all tags from that repository will be\n        pulled.\n\n        If you want to get the raw pull output, use the\n        :py:meth:`~docker.api.image.ImageApiMixin.pull` method in the\n        low-level API.\n\n        Args:\n            name (str): The repository to pull\n            tag (str): The tag to pull\n            auth_config (dict): Override the credentials that\n                :py:meth:`~docker.client.DockerClient.login` has set for\n                this request. ``auth_config`` should contain the ``username``\n                and ``password`` keys to be valid.\n            platform (str): Platform in the format ``os[/arch[/variant]]``\n\n        Returns:\n            (:py:class:`Image` or list): The image that has been pulled.\n                If no ``tag`` was specified, the method will return a list\n                of :py:class:`Image` objects belonging to this repository.\n\n        Raises:\n            :py:class:`docker.errors.APIError`\n                If the server returns an error.\n\n        Example:\n\n            >>> # Pull the image tagged `latest` in the busybox repo\n            >>> image = client.images.pull('busybox:latest')\n\n            >>> # Pull all tags in the busybox repo\n            >>> images = client.images.pull('busybox')\n        \"\"\"\n        if not tag:\n            repository, tag = parse_repository_tag(repository)\n\n        self.client.api.pull(repository, tag=tag, **kwargs)\n        if tag:\n            return self.get('{0}:{1}'.format(repository, tag))\n        return self.list(repository)\n\n    def push(self, repository, tag=None, **kwargs):\n        return self.client.api.push(repository, tag=tag, **kwargs)\n    push.__doc__ = APIClient.push.__doc__\n\n    def remove(self, *args, **kwargs):\n        self.client.api.remove_image(*args, **kwargs)\n    remove.__doc__ = APIClient.remove_image.__doc__\n\n    def search(self, *args, **kwargs):\n        return self.client.api.search(*args, **kwargs)\n    search.__doc__ = APIClient.search.__doc__\n\n    def prune(self, filters=None):\n        return self.client.api.prune_images(filters=filters)\n    prune.__doc__ = APIClient.prune_images.__doc__\n", "path": "docker/models/images.py"}]}