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
18d4db09
Kaydet (Commit)
18d4db09
authored
Nis 07, 2014
tarafından
Evgeniy L
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Moved APIError exception to docker.errors module.
üst
231042a5
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
44 additions
and
41 deletions
+44
-41
__init__.py
docker/__init__.py
+1
-1
client.py
docker/client.py
+2
-36
errors.py
docker/errors.py
+37
-0
integration_test.py
tests/integration_test.py
+4
-4
No files found.
docker/__init__.py
Dosyayı görüntüle @
18d4db09
...
...
@@ -15,4 +15,4 @@
__title__
=
'docker-py'
__version__
=
'0.3.0'
from
.client
import
Client
,
APIError
# flake8: noqa
from
.client
import
Client
# flake8: noqa
docker/client.py
Dosyayı görüntüle @
18d4db09
...
...
@@ -24,6 +24,7 @@ import six
from
.auth
import
auth
from
.unixconn
import
unixconn
from
.utils
import
utils
from
docker
import
errors
if
not
six
.
PY3
:
import
websocket
...
...
@@ -33,41 +34,6 @@ DEFAULT_TIMEOUT_SECONDS = 60
STREAM_HEADER_SIZE_BYTES
=
8
class
APIError
(
requests
.
exceptions
.
HTTPError
):
def
__init__
(
self
,
message
,
response
,
explanation
=
None
):
# requests 1.2 supports response as a keyword argument, but
# requests 1.1 doesn't
super
(
APIError
,
self
)
.
__init__
(
message
)
self
.
response
=
response
self
.
explanation
=
explanation
if
self
.
explanation
is
None
and
response
.
content
:
self
.
explanation
=
response
.
content
.
strip
()
def
__str__
(
self
):
message
=
super
(
APIError
,
self
)
.
__str__
()
if
self
.
is_client_error
():
message
=
'
%
s Client Error:
%
s'
%
(
self
.
response
.
status_code
,
self
.
response
.
reason
)
elif
self
.
is_server_error
():
message
=
'
%
s Server Error:
%
s'
%
(
self
.
response
.
status_code
,
self
.
response
.
reason
)
if
self
.
explanation
:
message
=
'
%
s ("
%
s")'
%
(
message
,
self
.
explanation
)
return
message
def
is_client_error
(
self
):
return
400
<=
self
.
response
.
status_code
<
500
def
is_server_error
(
self
):
return
500
<=
self
.
response
.
status_code
<
600
class
Client
(
requests
.
Session
):
def
__init__
(
self
,
base_url
=
None
,
version
=
DEFAULT_DOCKER_API_VERSION
,
timeout
=
DEFAULT_TIMEOUT_SECONDS
):
...
...
@@ -112,7 +78,7 @@ class Client(requests.Session):
try
:
response
.
raise_for_status
()
except
requests
.
exceptions
.
HTTPError
as
e
:
raise
APIError
(
e
,
response
,
explanation
=
explanation
)
raise
errors
.
APIError
(
e
,
response
,
explanation
=
explanation
)
def
_result
(
self
,
response
,
json
=
False
,
binary
=
False
):
assert
not
(
json
and
binary
)
...
...
docker/errors.py
Dosyayı görüntüle @
18d4db09
...
...
@@ -11,6 +11,43 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import
requests
class
APIError
(
requests
.
exceptions
.
HTTPError
):
def
__init__
(
self
,
message
,
response
,
explanation
=
None
):
# requests 1.2 supports response as a keyword argument, but
# requests 1.1 doesn't
super
(
APIError
,
self
)
.
__init__
(
message
)
self
.
response
=
response
self
.
explanation
=
explanation
if
self
.
explanation
is
None
and
response
.
content
:
self
.
explanation
=
response
.
content
.
strip
()
def
__str__
(
self
):
message
=
super
(
APIError
,
self
)
.
__str__
()
if
self
.
is_client_error
():
message
=
'
%
s Client Error:
%
s'
%
(
self
.
response
.
status_code
,
self
.
response
.
reason
)
elif
self
.
is_server_error
():
message
=
'
%
s Server Error:
%
s'
%
(
self
.
response
.
status_code
,
self
.
response
.
reason
)
if
self
.
explanation
:
message
=
'
%
s ("
%
s")'
%
(
message
,
self
.
explanation
)
return
message
def
is_client_error
(
self
):
return
400
<=
self
.
response
.
status_code
<
500
def
is_server_error
(
self
):
return
500
<=
self
.
response
.
status_code
<
600
class
DockerException
(
Exception
):
pass
...
...
tests/integration_test.py
Dosyayı görüntüle @
18d4db09
...
...
@@ -41,13 +41,13 @@ class BaseTestCase(unittest.TestCase):
for
img
in
self
.
tmp_imgs
:
try
:
self
.
client
.
remove_image
(
img
)
except
docker
.
APIError
:
except
docker
.
errors
.
APIError
:
pass
for
container
in
self
.
tmp_containers
:
try
:
self
.
client
.
stop
(
container
,
timeout
=
1
)
self
.
client
.
remove_container
(
container
)
except
docker
.
APIError
:
except
docker
.
errors
.
APIError
:
pass
#########################
...
...
@@ -641,7 +641,7 @@ class TestPull(BaseTestCase):
try
:
self
.
client
.
remove_image
(
'joffrey/test001'
)
self
.
client
.
remove_image
(
'376968a23351'
)
except
docker
.
APIError
:
except
docker
.
errors
.
APIError
:
pass
info
=
self
.
client
.
info
()
self
.
assertIn
(
'Images'
,
info
)
...
...
@@ -660,7 +660,7 @@ class TestPullStream(BaseTestCase):
try
:
self
.
client
.
remove_image
(
'joffrey/test001'
)
self
.
client
.
remove_image
(
'376968a23351'
)
except
docker
.
APIError
:
except
docker
.
errors
.
APIError
:
pass
info
=
self
.
client
.
info
()
self
.
assertIn
(
'Images'
,
info
)
...
...
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