Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
D
docker-py
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
docker-py
Commits
0f366bf7
Kaydet (Commit)
0f366bf7
authored
Şub 24, 2014
tarafından
Joffrey F
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Sade Fark
Merge pull request #167 from mpetazzoni/build-output
Fix build() and events() streaming
üst
af1bb34d
a102b189
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
30 deletions
+20
-30
client.py
docker/client.py
+20
-30
No files found.
docker/client.py
Dosyayı görüntüle @
0f366bf7
...
...
@@ -226,21 +226,13 @@ class Client(requests.Session):
def
_create_websocket_connection
(
self
,
url
):
return
websocket
.
create_connection
(
url
)
def
_stream_result
(
self
,
response
):
"""Generator for straight-out, non chunked-encoded HTTP responses."""
self
.
_raise_for_status
(
response
)
for
line
in
response
.
iter_lines
(
chunk_size
=
1
,
decode_unicode
=
True
):
# filter out keep-alive new lines
if
line
:
yield
line
+
'
\n
'
def
_stream_result_socket
(
self
,
response
):
def
_get_raw_response_socket
(
self
,
response
):
self
.
_raise_for_status
(
response
)
return
response
.
raw
.
_fp
.
fp
.
_sock
def
_stream_helper
(
self
,
response
):
"""Generator for data coming from a chunked-encoded HTTP response."""
socket_fp
=
self
.
_
stream_result
_socket
(
response
)
socket_fp
=
self
.
_
get_raw_response
_socket
(
response
)
socket_fp
.
setblocking
(
1
)
socket
=
socket_fp
.
makefile
()
while
True
:
...
...
@@ -269,7 +261,7 @@ class Client(requests.Session):
def
_multiplexed_socket_stream_helper
(
self
,
response
):
"""A generator of multiplexed data blocks coming from a response
socket."""
socket
=
self
.
_
stream_result
_socket
(
response
)
socket
=
self
.
_
get_raw_response
_socket
(
response
)
def
recvall
(
socket
,
size
):
data
=
''
...
...
@@ -308,9 +300,18 @@ class Client(requests.Session):
u
=
self
.
_url
(
"/containers/{0}/attach"
.
format
(
container
))
response
=
self
.
_post
(
u
,
params
=
params
,
stream
=
stream
)
# Stream multi-plexing was introduced in API v1.6.
# Stream multi-plexing was only introduced in API v1.6. Anything before
# that needs old-style streaming.
if
utils
.
compare_version
(
'1.6'
,
self
.
_version
)
<
0
:
return
stream
and
self
.
_stream_result
(
response
)
or
\
def
stream_result
():
self
.
_raise_for_status
(
response
)
for
line
in
response
.
iter_lines
(
chunk_size
=
1
,
decode_unicode
=
True
):
# filter out keep-alive new lines
if
line
:
yield
line
return
stream
and
stream_result
(
response
)
or
\
self
.
_result
(
response
,
binary
=
True
)
return
stream
and
self
.
_multiplexed_socket_stream_helper
(
response
)
or
\
...
...
@@ -323,13 +324,15 @@ class Client(requests.Session):
'stderr'
:
1
,
'stream'
:
1
}
if
ws
:
return
self
.
_attach_websocket
(
container
,
params
)
if
isinstance
(
container
,
dict
):
container
=
container
.
get
(
'Id'
)
u
=
self
.
_url
(
"/containers/{0}/attach"
.
format
(
container
))
return
self
.
_
stream_result
_socket
(
self
.
post
(
return
self
.
_
get_raw_response
_socket
(
self
.
post
(
u
,
None
,
params
=
self
.
_attach_params
(
params
),
stream
=
True
))
def
build
(
self
,
path
=
None
,
tag
=
None
,
quiet
=
False
,
fileobj
=
None
,
...
...
@@ -367,8 +370,9 @@ class Client(requests.Session):
if
context
is
not
None
:
context
.
close
()
if
stream
or
utils
.
compare_version
(
'1.8'
,
self
.
_version
)
>=
0
:
return
self
.
_stream_
result
(
response
)
return
self
.
_stream_
helper
(
response
)
else
:
output
=
self
.
_result
(
response
)
srch
=
r'Successfully built ([0-9a-f]+)'
...
...
@@ -446,21 +450,7 @@ class Client(requests.Session):
format
(
container
))),
True
)
def
events
(
self
):
u
=
self
.
_url
(
"/events"
)
socket
=
self
.
_stream_result_socket
(
self
.
get
(
u
,
stream
=
True
))
while
True
:
chunk
=
socket
.
recv
(
4096
)
if
chunk
:
# Messages come in the format of length, data, newline.
length
,
data
=
chunk
.
split
(
"
\n
"
,
1
)
length
=
int
(
length
,
16
)
if
length
>
len
(
data
):
data
+=
socket
.
recv
(
length
-
len
(
data
))
yield
json
.
loads
(
data
)
else
:
break
return
self
.
_stream_helper
(
self
.
get
(
self
.
_url
(
'/events'
),
stream
=
True
))
def
export
(
self
,
container
):
if
isinstance
(
container
,
dict
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment