Skip to content

Commit 9987c1b

Browse files
committed
Fix docs examples to work with Python 3
Signed-off-by: Joffrey F <[email protected]>
1 parent 5467658 commit 9987c1b

File tree

4 files changed

+69
-12
lines changed

4 files changed

+69
-12
lines changed

docker/api/daemon.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ def events(self, since=None, until=None, filters=None, decode=None):
4242
4343
Example:
4444
45-
>>> for event in client.events()
46-
... print event
45+
>>> for event in client.events(decode=True)
46+
... print(event)
4747
{u'from': u'image/with:tag',
4848
u'id': u'container-id',
4949
u'status': u'start',
@@ -54,7 +54,7 @@ def events(self, since=None, until=None, filters=None, decode=None):
5454
5555
>>> events = client.events()
5656
>>> for event in events:
57-
... print event
57+
... print(event)
5858
>>> # and cancel from another thread
5959
>>> events.close()
6060
"""

docker/api/image.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -352,8 +352,8 @@ def pull(self, repository, tag=None, stream=False, auth_config=None,
352352
353353
Example:
354354
355-
>>> for line in cli.pull('busybox', stream=True):
356-
... print(json.dumps(json.loads(line), indent=4))
355+
>>> for line in cli.pull('busybox', stream=True, decode=True):
356+
... print(json.dumps(line, indent=4))
357357
{
358358
"status": "Pulling image (latest) from busybox",
359359
"progressDetail": {},
@@ -428,12 +428,12 @@ def push(self, repository, tag=None, stream=False, auth_config=None,
428428
If the server returns an error.
429429
430430
Example:
431-
>>> for line in cli.push('yourname/app', stream=True):
432-
... print line
433-
{"status":"Pushing repository yourname/app (1 tags)"}
434-
{"status":"Pushing","progressDetail":{},"id":"511136ea3c5a"}
435-
{"status":"Image already pushed, skipping","progressDetail":{},
436-
"id":"511136ea3c5a"}
431+
>>> for line in cli.push('yourname/app', stream=True, decode=True):
432+
... print(line)
433+
{'status': 'Pushing repository yourname/app (1 tags)'}
434+
{'status': 'Pushing','progressDetail': {}, 'id': '511136ea3c5a'}
435+
{'status': 'Image already pushed, skipping', 'progressDetail':{},
436+
'id': '511136ea3c5a'}
437437
...
438438
439439
"""

docker/api/mixin.py

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
from typing import Any, Dict, Iterable, List, Optional, Union
2+
3+
import requests
4+
5+
from ..constants import DEFAULT_DOCKER_API_VERSION, DEFAULT_TIMEOUT_SECONDS
6+
7+
class BaseMixin(object):
8+
base_url: str = ''
9+
credstore_env: Optional[Dict[str, str]] = None
10+
timeout: int = DEFAULT_TIMEOUT_SECONDS
11+
_auth_configs: Dict[str, Dict]
12+
_general_configs: Dict[str, Dict]
13+
_version: str = DEFAULT_DOCKER_API_VERSION
14+
15+
def _url(self, pathfmt: str, *args, **kwargs) -> str:
16+
raise NotImplemented
17+
18+
def _post(self, url: str, **kwargs) -> requests.Response:
19+
raise NotImplemented
20+
21+
def _get(self, url: str, **kwargs) -> requests.Response:
22+
raise NotImplemented
23+
24+
def _put(self, url: str, **kwargs) -> requests.Response:
25+
raise NotImplemented
26+
27+
def _delete(self, url: str, **kwargs) -> requests.Response:
28+
raise NotImplemented
29+
30+
def _post_json(self, url: str, data: Optional[Union[Dict[str, Any], List[Any]]], **kwargs) -> requests.Response:
31+
raise NotImplemented
32+
33+
def _raise_for_status(self, response: requests.Response) -> None:
34+
raise NotImplemented
35+
36+
def _result(self, response: requests.Response, json: bool=False, binary: bool=False) -> Any:
37+
raise NotImplemented
38+
39+
def _stream_helper(self, response: requests.Response, decode: bool = False) -> Iterable:
40+
raise NotImplemented
41+
42+
def _get_raw_response_socket(self, response: requests.Response) -> Iterable:
43+
raise NotImplemented
44+
45+
def _read_from_socket(
46+
self,
47+
response: requests.Response,
48+
stream: bool,
49+
tty: bool = False) -> Union[Iterable[bytes], bytes]:
50+
raise NotImplemented
51+
52+
def _stream_raw_result(
53+
self,
54+
response: requests.Response,
55+
chunk_size: int = 1,
56+
decode: bool = True) -> Iterable[bytes]:
57+
raise NotImplemented

docker/types/daemon.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class CancellableStream(object):
1515
Example:
1616
>>> events = client.events()
1717
>>> for event in events:
18-
... print event
18+
... print(event)
1919
>>> # and cancel from another thread
2020
>>> events.close()
2121
"""

0 commit comments

Comments
 (0)