mirror of https://github.com/docker/docker-py.git
npipe support cleanup
Signed-off-by: Joffrey F <joffrey@docker.com>
This commit is contained in:
parent
4a8832ca8b
commit
b5d9312f9a
|
@ -26,14 +26,14 @@ from . import api
|
|||
from . import constants
|
||||
from . import errors
|
||||
from .auth import auth
|
||||
from .unixconn import unixconn
|
||||
from .ssladapter import ssladapter
|
||||
from .tls import TLSConfig
|
||||
from .transport import UnixAdapter
|
||||
from .utils import utils, check_resource, update_headers, kwargs_from_env
|
||||
try:
|
||||
from .npipeconn import npipeconn
|
||||
from .transport import NpipeAdapter
|
||||
except ImportError:
|
||||
pass
|
||||
from .ssladapter import ssladapter
|
||||
from .utils import utils, check_resource, update_headers, kwargs_from_env
|
||||
from .tls import TLSConfig
|
||||
|
||||
|
||||
def from_env(**kwargs):
|
||||
|
@ -65,7 +65,7 @@ class Client(
|
|||
|
||||
base_url = utils.parse_host(base_url, sys.platform, tls=bool(tls))
|
||||
if base_url.startswith('http+unix://'):
|
||||
self._custom_adapter = unixconn.UnixAdapter(base_url, timeout)
|
||||
self._custom_adapter = UnixAdapter(base_url, timeout)
|
||||
self.mount('http+docker://', self._custom_adapter)
|
||||
self.base_url = 'http+docker://localunixsocket'
|
||||
elif base_url.startswith('npipe://'):
|
||||
|
@ -73,7 +73,12 @@ class Client(
|
|||
raise errors.DockerException(
|
||||
'The npipe:// protocol is only supported on Windows'
|
||||
)
|
||||
self._custom_adapter = npipeconn.NpipeAdapter(base_url, timeout)
|
||||
try:
|
||||
self._custom_adapter = NpipeAdapter(base_url, timeout)
|
||||
except NameError:
|
||||
raise errors.DockerException(
|
||||
'Install pypiwin32 package to enable npipe:// support'
|
||||
)
|
||||
self.mount('http+docker://', self._custom_adapter)
|
||||
self.base_url = 'http+docker://localnpipe'
|
||||
else:
|
||||
|
|
|
@ -1,37 +0,0 @@
|
|||
import win32pipe
|
||||
import win32file
|
||||
|
||||
import random
|
||||
|
||||
def pipe_name():
|
||||
return 'testpipe{}'.format(random.randint(0, 4096))
|
||||
|
||||
def create_pipe(name):
|
||||
handle = win32pipe.CreateNamedPipe(
|
||||
'//./pipe/{}'.format(name),
|
||||
win32pipe.PIPE_ACCESS_DUPLEX,
|
||||
win32pipe.PIPE_TYPE_BYTE | win32pipe.PIPE_READMODE_BYTE | win32pipe.PIPE_WAIT,
|
||||
128, 4096, 4096, 300, None
|
||||
)
|
||||
return handle
|
||||
|
||||
def rw_loop(pipe):
|
||||
err = win32pipe.ConnectNamedPipe(pipe, None)
|
||||
if err != 0:
|
||||
raise RuntimeError('Error code: {}'.format(err))
|
||||
while True:
|
||||
err, data = win32file.ReadFile(pipe, 4096, None)
|
||||
if err != 0:
|
||||
raise RuntimeError('Error code: {}'.format(err))
|
||||
print('Data received: ', data, len(data))
|
||||
win32file.WriteFile(pipe, b'ACK', None)
|
||||
|
||||
|
||||
def __main__():
|
||||
name = pipe_name()
|
||||
print('Initializing pipe {}'.format(name))
|
||||
pipe = create_pipe(name)
|
||||
print('Pipe created, entering server loop.')
|
||||
rw_loop(pipe)
|
||||
|
||||
__main__()
|
|
@ -0,0 +1,3 @@
|
|||
# flake8: noqa
|
||||
from .npipe import NpipeAdapter
|
||||
from .unixconn import UnixAdapter
|
2
setup.py
2
setup.py
|
@ -35,7 +35,7 @@ setup(
|
|||
description="Python client for Docker.",
|
||||
url='https://github.com/docker/docker-py/',
|
||||
packages=[
|
||||
'docker', 'docker.api', 'docker.auth', 'docker.unixconn',
|
||||
'docker', 'docker.api', 'docker.auth', 'docker.transport',
|
||||
'docker.utils', 'docker.utils.ports', 'docker.ssladapter'
|
||||
],
|
||||
install_requires=requirements,
|
||||
|
|
Loading…
Reference in New Issue