holado 0.2.7__py3-none-any.whl → 0.3.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of holado might be problematic. Click here for more details.
- holado/common/handlers/undefined.py +7 -1
- {holado-0.2.7.dist-info → holado-0.3.0.dist-info}/METADATA +7 -1
- {holado-0.2.7.dist-info → holado-0.3.0.dist-info}/RECORD +116 -107
- holado_ais/ais/ais_messages.py +97 -6
- holado_ais/tests/behave/steps/ais/ais_manager_steps.py +1 -1
- holado_ais/tests/behave/steps/ais/ais_messages_steps.py +45 -6
- holado_binary/ipc/bit_series.py +3 -3
- holado_binary/tests/behave/steps/ipc/binary_steps.py +1 -1
- holado_binary/tests/behave/steps/ipc/bit_series_steps.py +4 -3
- holado_context/tests/behave/steps/private/common/context_steps.py +1 -1
- holado_core/common/resource/persisted_data_manager.py +13 -16
- holado_core/common/resource/resource_manager.py +10 -10
- holado_core/common/tables/converters/table_converter.py +47 -9
- holado_core/common/tables/table.py +2 -2
- holado_core/common/tables/table_manager.py +6 -7
- holado_core/common/tables/table_with_header.py +6 -0
- holado_core/common/tools/string_tools.py +9 -0
- holado_core/tests/behave/steps/common/common_steps.py +2 -1
- holado_core/tests/behave/steps/common/config_steps.py +1 -1
- holado_core/tests/behave/steps/common/resource_steps.py +1 -1
- holado_core/tests/behave/steps/common/tables_steps.py +27 -4
- holado_data/data/generator/generator_manager.py +39 -0
- holado_data/tests/behave/steps/data/generator_steps.py +1 -1
- holado_data/tests/behave/steps/tools/utils_steps.py +1 -2
- holado_db/tests/behave/steps/tools/db/db_client_steps.py +1 -1
- holado_db/tests/behave/steps/tools/db/postgresql_client_steps.py +1 -1
- holado_db/tests/behave/steps/tools/db/sqlite_client_steps.py +1 -1
- holado_db/tools/db/clients/base/db_client.py +81 -28
- holado_db/tools/db/clients/postgresql/postgresql_client.py +17 -7
- holado_db/tools/db/query/base/query_builder.py +58 -7
- holado_db/tools/db/query/pypika/pypika_query_builder.py +73 -21
- holado_docker/tests/behave/steps/tools/docker_steps.py +1 -1
- holado_grpc/tests/behave/steps/api/grpc_client_steps.py +1 -1
- holado_grpc/tests/behave/steps/private/api/grpc_steps.py +1 -1
- holado_helper/script/action.py +16 -7
- holado_json/tests/behave/steps/ipc/json_steps.py +1 -1
- holado_keycloak/tests/behave/steps/tools/keycloak_client_steps.py +1 -1
- holado_multitask/tests/behave/steps/multiprocessing_steps.py +1 -1
- holado_multitask/tests/behave/steps/multithreading_steps.py +1 -1
- holado_protobuf/ipc/protobuf/types/google/protobuf.py +1 -1
- holado_protobuf/tests/behave/steps/ipc/protobuf_steps.py +1 -1
- holado_python/common/tools/datetime.py +31 -12
- holado_python/standard_library/socket/blocking_socket.py +112 -42
- holado_python/standard_library/socket/echo_server.py +4 -3
- holado_python/standard_library/socket/message_socket.py +69 -22
- holado_python/standard_library/socket/non_blocking_socket.py +65 -67
- holado_python/standard_library/socket/socket.py +272 -32
- holado_python/standard_library/ssl/resources/certificates/NOTES.txt +1 -1
- holado_python/standard_library/ssl/resources/certificates/rootCACert.pem +24 -0
- holado_python/standard_library/ssl/resources/certificates/tcpbin.crt +21 -0
- holado_python/standard_library/ssl/resources/certificates/tcpbin.key +28 -0
- holado_python/standard_library/ssl/ssl.py +138 -21
- holado_python/tests/behave/steps/convert_steps.py +1 -1
- holado_python/tests/behave/steps/iterable_steps.py +1 -1
- holado_python/tests/behave/steps/standard_library/csv_steps.py +1 -1
- holado_python/tests/behave/steps/standard_library/datetime_steps.py +1 -1
- holado_python/tests/behave/steps/standard_library/hashlib_steps.py +1 -1
- holado_python/tests/behave/steps/standard_library/multiprocessing_steps.py +1 -1
- holado_python/tests/behave/steps/standard_library/queue_steps.py +1 -1
- holado_python/tests/behave/steps/standard_library/socket_steps.py +147 -21
- holado_python/tests/behave/steps/standard_library/ssl_steps.py +87 -16
- holado_rabbitmq/tests/behave/steps/tools/rabbitmq_client_steps.py +48 -20
- holado_rabbitmq/tests/behave/steps/tools/rabbitmq_server_steps.py +1 -1
- holado_rabbitmq/tools/rabbitmq/rabbitmq_client.py +19 -13
- holado_rabbitmq/tools/rabbitmq/rabbitmq_manager.py +2 -29
- holado_redis/tests/behave/steps/tools/redis_client_steps.py +1 -1
- holado_rest/tests/behave/steps/api/rest_client_steps.py +1 -1
- holado_rest/tests/behave/steps/private/api/rest_steps.py +1 -1
- holado_s3/tests/behave/steps/private/tools/s3_steps.py +1 -1
- holado_s3/tests/behave/steps/tools/s3_client_steps.py +1 -1
- holado_s3/tests/behave/steps/tools/s3_server_steps.py +1 -1
- holado_scripting/tests/behave/steps/common/tools/variable_convert_steps.py +3 -2
- holado_scripting/tests/behave/steps/common/tools/variable_new_steps.py +1 -1
- holado_scripting/tests/behave/steps/common/tools/variable_steps.py +1 -1
- holado_scripting/tests/behave/steps/common/tools/variable_verify_steps.py +1 -1
- holado_scripting/tests/behave/steps/scenario/function_steps.py +1 -1
- holado_scripting/tests/behave/steps/scenario/if_steps.py +1 -1
- holado_scripting/tests/behave/steps/scenario/loop_steps.py +1 -1
- holado_scripting/text/interpreter/functions/function_apply_function.py +60 -0
- holado_scripting/text/interpreter/functions/function_to_string.py +50 -0
- holado_scripting/text/interpreter/text_interpreter.py +4 -0
- holado_sftp/tests/behave/steps/private/tools/sftp_steps.py +1 -1
- holado_sftp/tests/behave/steps/tools/sftp_client_steps.py +1 -1
- holado_sftp/tests/behave/steps/tools/sftp_server_steps.py +1 -1
- holado_swagger/tests/behave/steps/swagger_hub/mockserver_steps.py +1 -1
- holado_system/system/command/command.py +14 -9
- holado_system/tests/behave/steps/system/commands_steps.py +1 -1
- holado_system/tests/behave/steps/system/file_steps.py +1 -1
- holado_system/tests/behave/steps/system/system_steps.py +1 -1
- holado_test/scenario/step_tools.py +5 -4
- holado_test/scenario/tester_tools.py +6 -3
- holado_test/tests/behave/steps/scenario/exception_steps.py +1 -1
- holado_test/tests/behave/steps/scenario/scenario_steps.py +1 -1
- holado_test/tests/behave/steps/scenario/tester_steps.py +4 -4
- holado_value/common/tables/converters/value_table_converter.py +52 -8
- holado_value/common/tables/value_table_cell.py +5 -0
- holado_value/common/tables/value_table_manager.py +0 -10
- holado_value/common/tables/value_table_row.py +0 -1
- holado_value/common/tools/value.py +5 -1
- holado_ws/tests/behave/steps/api/web_service_steps.py +1 -1
- holado_yaml/tests/behave/steps/yaml_steps.py +1 -1
- holado_yaml/yaml/yaml_manager.py +2 -2
- test_holado/features/NonReg/common/tables/table.feature +30 -24
- test_holado/features/NonReg/holado_ais/ais_message-bitarray_to_nmea.feature +1 -1
- test_holado/features/NonReg/holado_python/standard_library/socket/local_echo_server/socket_reset.feature +191 -0
- test_holado/features/NonReg/holado_python/standard_library/{socket_with_ssl.feature → socket/local_echo_server/socket_with_tls_and_verify.feature} +126 -27
- test_holado/features/NonReg/holado_python/standard_library/socket/local_echo_server/socket_with_tls_without_verify.feature +299 -0
- test_holado/features/NonReg/holado_python/standard_library/{socket.feature → socket/local_echo_server/socket_without_tls.feature} +63 -1
- test_holado/features/NonReg/holado_python/standard_library/socket/tcpbin.com/socket_with_mtls.feature +214 -0
- test_holado/features/NonReg/holado_python/standard_library/socket/tcpbin.com/socket_with_tls.feature +184 -0
- test_holado/features/NonReg/holado_python/standard_library/socket/tcpbin.com/socket_without_tls.feature +169 -0
- test_holado/features/NonReg/tools/RabbitMQ.feature +9 -9
- test_holado/features/NonReg/tools/RabbitMQ_steps.feature +8 -8
- test_holado/logging.conf +5 -3
- holado_core/common/transport/__init__.py +0 -0
- holado_core/common/transport/crc.py +0 -40
- {holado-0.2.7.dist-info → holado-0.3.0.dist-info}/WHEEL +0 -0
- {holado-0.2.7.dist-info → holado-0.3.0.dist-info}/licenses/LICENSE +0 -0
|
@@ -17,6 +17,9 @@ import selectors
|
|
|
17
17
|
from holado_python.standard_library.socket.non_blocking_socket import TCPNonBlockingSocketClient
|
|
18
18
|
import copy
|
|
19
19
|
import threading
|
|
20
|
+
from holado_python.standard_library.socket.blocking_socket import TCPBlockingSocketClient
|
|
21
|
+
from holado_core.common.tools.tools import Tools
|
|
22
|
+
from holado.common.handlers.undefined import undefined_argument
|
|
20
23
|
|
|
21
24
|
logger = logging.getLogger(__name__)
|
|
22
25
|
|
|
@@ -26,14 +29,14 @@ logger = logging.getLogger(__name__)
|
|
|
26
29
|
##########################################################################
|
|
27
30
|
|
|
28
31
|
|
|
29
|
-
class
|
|
32
|
+
class MessageSocketClient(object):
|
|
30
33
|
"""
|
|
31
|
-
Base class for
|
|
34
|
+
Base class for message socket client.
|
|
32
35
|
"""
|
|
33
36
|
__metaclass__ = abc.ABCMeta
|
|
34
37
|
|
|
35
|
-
def __init__(self, separator=b'\n'
|
|
36
|
-
super().__init__(
|
|
38
|
+
def __init__(self, separator=b'\n'):
|
|
39
|
+
super().__init__()
|
|
37
40
|
|
|
38
41
|
self.__separator = separator
|
|
39
42
|
self.__messages_lock = threading.Lock()
|
|
@@ -41,32 +44,36 @@ class MessageTCPSocketClient(TCPNonBlockingSocketClient):
|
|
|
41
44
|
|
|
42
45
|
@property
|
|
43
46
|
def messages(self):
|
|
44
|
-
|
|
47
|
+
with self.__messages_lock:
|
|
48
|
+
return copy.copy(self.__messages)
|
|
45
49
|
|
|
46
50
|
@property
|
|
47
51
|
def nb_messages(self):
|
|
48
|
-
|
|
52
|
+
with self.__messages_lock:
|
|
53
|
+
return len(self.__messages)
|
|
49
54
|
|
|
50
|
-
def
|
|
51
|
-
|
|
52
|
-
|
|
55
|
+
def _extract_messages_from_data(self, data):
|
|
56
|
+
while True:
|
|
57
|
+
ind = data.in_bytes.find(self.__separator)
|
|
58
|
+
if ind >=0:
|
|
59
|
+
msg = data.in_bytes[:ind]
|
|
60
|
+
self._add_message(msg)
|
|
61
|
+
data.in_bytes = data.in_bytes[ind+len(self.__separator):]
|
|
62
|
+
if Tools.do_log(logger, logging.TRACE): # @UndefinedVariable
|
|
63
|
+
logger.trace(f"[{self.name}] New message (total: {self.nb_messages}): {msg}")
|
|
64
|
+
elif Tools.do_log(logger, logging.DEBUG):
|
|
65
|
+
logger.debug(f"[{self.name}] New message (total: {self.nb_messages})")
|
|
66
|
+
else:
|
|
67
|
+
break
|
|
53
68
|
|
|
54
|
-
|
|
55
|
-
if mask & selectors.EVENT_READ:
|
|
56
|
-
with self._data_lock:
|
|
57
|
-
while True:
|
|
58
|
-
ind = self._data.in_bytes.find(self.__separator)
|
|
59
|
-
if ind >=0:
|
|
60
|
-
msg = self._data.in_bytes[:ind]
|
|
61
|
-
self.__add_message(msg)
|
|
62
|
-
self._data.in_bytes = self._data.in_bytes[ind+len(self.__separator):]
|
|
63
|
-
else:
|
|
64
|
-
break
|
|
65
|
-
|
|
66
|
-
def __add_message(self, msg):
|
|
69
|
+
def _add_message(self, msg):
|
|
67
70
|
with self.__messages_lock:
|
|
68
71
|
self.__messages.append(msg)
|
|
69
72
|
|
|
73
|
+
def reset_received_messages(self):
|
|
74
|
+
with self.__messages_lock:
|
|
75
|
+
self.__messages.clear()
|
|
76
|
+
|
|
70
77
|
def read_message(self):
|
|
71
78
|
res = None
|
|
72
79
|
with self.__messages_lock:
|
|
@@ -85,6 +92,46 @@ class MessageTCPSocketClient(TCPNonBlockingSocketClient):
|
|
|
85
92
|
|
|
86
93
|
|
|
87
94
|
|
|
95
|
+
class MessageTCPBlockingSocketClient(TCPBlockingSocketClient, MessageSocketClient):
|
|
96
|
+
"""
|
|
97
|
+
Message socket client with TCP blocking socket.
|
|
98
|
+
"""
|
|
99
|
+
def __init__(self, separator=b'\n', *, name=None, create_ipv4_socket_kwargs=None, idle_sleep_delay=undefined_argument):
|
|
100
|
+
MessageSocketClient.__init__(self, separator)
|
|
101
|
+
TCPBlockingSocketClient.__init__(self, name=name, create_ipv4_socket_kwargs=create_ipv4_socket_kwargs, idle_sleep_delay=idle_sleep_delay)
|
|
102
|
+
|
|
103
|
+
def _process_recv_send(self, *, read_bufsize=1024, read_kwargs=None, write_kwargs=None):
|
|
104
|
+
# Read from socket & write in socket
|
|
105
|
+
super()._process_recv_send(read_bufsize=read_bufsize, read_kwargs=read_kwargs, write_kwargs=write_kwargs)
|
|
106
|
+
|
|
107
|
+
# Extract messages from received data
|
|
108
|
+
if self.is_run_with_recv:
|
|
109
|
+
with self._data_lock:
|
|
110
|
+
self._extract_messages_from_data(self._data)
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
class MessageTCPNonBlockingSocketClient(TCPNonBlockingSocketClient, MessageSocketClient):
|
|
115
|
+
"""
|
|
116
|
+
Message socket client with TCP non-blocking socket.
|
|
117
|
+
"""
|
|
118
|
+
def __init__(self, separator=b'\n', *, name=None, create_ipv4_socket_kwargs=None, idle_sleep_delay=undefined_argument):
|
|
119
|
+
MessageSocketClient.__init__(self, separator)
|
|
120
|
+
TCPNonBlockingSocketClient.__init__(self, name=name, create_ipv4_socket_kwargs=create_ipv4_socket_kwargs, idle_sleep_delay=idle_sleep_delay)
|
|
121
|
+
|
|
122
|
+
def _service_connection(self, key, mask, *, read_bufsize=1024, read_kwargs=None, write_kwargs=None):
|
|
123
|
+
# Read from socket & write in socket
|
|
124
|
+
res = super()._service_connection(key, mask, read_bufsize=read_bufsize, read_kwargs=read_kwargs, write_kwargs=write_kwargs)
|
|
125
|
+
|
|
126
|
+
# Extract messages from received data
|
|
127
|
+
if mask & selectors.EVENT_READ:
|
|
128
|
+
with self._data_lock:
|
|
129
|
+
self._extract_messages_from_data(self._data)
|
|
130
|
+
|
|
131
|
+
return res
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
|
|
88
135
|
|
|
89
136
|
|
|
90
137
|
|
|
@@ -17,8 +17,9 @@ from holado_python.standard_library.socket.socket import SocketClient
|
|
|
17
17
|
import abc
|
|
18
18
|
from holado_multitask.multithreading.loopfunctionthreaded import LoopFunctionThreaded
|
|
19
19
|
import selectors
|
|
20
|
-
import
|
|
21
|
-
import
|
|
20
|
+
from holado.common.handlers.undefined import undefined_argument
|
|
21
|
+
import time
|
|
22
|
+
import ssl
|
|
22
23
|
|
|
23
24
|
logger = logging.getLogger(__name__)
|
|
24
25
|
|
|
@@ -34,111 +35,108 @@ class NonBlockingSocketClient(SocketClient):
|
|
|
34
35
|
"""
|
|
35
36
|
__metaclass__ = abc.ABCMeta
|
|
36
37
|
|
|
37
|
-
def __init__(self, *, name=None, create_ipv4_socket_kwargs=None):
|
|
38
|
+
def __init__(self, *, name=None, create_ipv4_socket_kwargs=None, idle_sleep_delay=undefined_argument, do_run_with_recv=True, do_run_with_send=True):
|
|
38
39
|
self.__selector = selectors.DefaultSelector()
|
|
39
40
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
in_bytes=b"",
|
|
43
|
-
out_bytes=b"",
|
|
44
|
-
)
|
|
45
|
-
|
|
46
|
-
# Note: __selector and __data must be defined before, since Socket.__init__ can execute create_ipv4_socket
|
|
47
|
-
super().__init__(name=name, create_ipv4_socket_kwargs=create_ipv4_socket_kwargs)
|
|
48
|
-
|
|
49
|
-
self.__start_thread = None
|
|
41
|
+
# Note: __selector must be defined before, since Socket.__init__ can execute create_ipv4_socket
|
|
42
|
+
super().__init__(name=name, create_ipv4_socket_kwargs=create_ipv4_socket_kwargs, idle_sleep_delay=idle_sleep_delay, do_run_with_recv=do_run_with_recv, do_run_with_send=do_run_with_send)
|
|
50
43
|
|
|
51
44
|
def _delete_object(self):
|
|
52
|
-
self.stop()
|
|
53
45
|
if self.internal_socket:
|
|
46
|
+
# Note: stop must be done before unregistering selector
|
|
47
|
+
self.stop()
|
|
54
48
|
self.__selector.unregister(self.internal_socket)
|
|
55
49
|
|
|
56
50
|
super()._delete_object()
|
|
57
51
|
|
|
58
52
|
def _register_socket(self, sock):
|
|
59
53
|
events = selectors.EVENT_READ | selectors.EVENT_WRITE
|
|
60
|
-
self.__selector.register(sock, events, data=self.
|
|
61
|
-
|
|
62
|
-
@property
|
|
63
|
-
def _data_lock(self):
|
|
64
|
-
return self.__data_lock
|
|
65
|
-
|
|
66
|
-
@property
|
|
67
|
-
def _data(self):
|
|
68
|
-
return self.__data
|
|
54
|
+
self.__selector.register(sock, events, data=self._data)
|
|
69
55
|
|
|
70
56
|
def start(self, *, read_bufsize=1024, read_kwargs=None, write_kwargs=None):
|
|
71
57
|
"""Start client event loop.
|
|
72
58
|
"""
|
|
73
59
|
kwargs = {'read_bufsize':read_bufsize, 'read_kwargs':read_kwargs, 'write_kwargs':write_kwargs}
|
|
74
|
-
|
|
75
|
-
self.
|
|
76
|
-
|
|
77
|
-
def stop(self):
|
|
78
|
-
if self.__start_thread is not None:
|
|
79
|
-
self.__start_thread.interrupt()
|
|
80
|
-
self.__start_thread.join()
|
|
81
|
-
self.__start_thread = None
|
|
60
|
+
thread = LoopFunctionThreaded(self._wait_and_process_events, kwargs=kwargs, register_thread=True, delay_before_run_sec=None)
|
|
61
|
+
self._start_thread(thread)
|
|
82
62
|
|
|
83
63
|
def _wait_and_process_events(self, *, read_bufsize=1024, read_kwargs=None, write_kwargs=None):
|
|
64
|
+
has_activity = False
|
|
84
65
|
events = self.__selector.select(timeout=None)
|
|
85
66
|
for key, mask in events:
|
|
86
|
-
self._service_connection(key, mask, read_bufsize=read_bufsize, read_kwargs=read_kwargs, write_kwargs=write_kwargs)
|
|
67
|
+
has_activity |= self._service_connection(key, mask, read_bufsize=read_bufsize, read_kwargs=read_kwargs, write_kwargs=write_kwargs)
|
|
68
|
+
|
|
69
|
+
# Wait before next loop if no data was exchanged
|
|
70
|
+
if not has_activity and self._idle_sleep_delay is not None:
|
|
71
|
+
time.sleep(self._idle_sleep_delay)
|
|
87
72
|
|
|
88
73
|
def _service_connection(self, key, mask, *, read_bufsize=1024, read_kwargs=None, write_kwargs=None):
|
|
74
|
+
has_activity = False
|
|
89
75
|
read_kwargs = read_kwargs if read_kwargs is not None else {}
|
|
90
76
|
write_kwargs = write_kwargs if write_kwargs is not None else {}
|
|
91
77
|
|
|
92
78
|
sock = key.fileobj
|
|
93
79
|
data = key.data
|
|
94
|
-
if mask & selectors.EVENT_READ:
|
|
95
|
-
|
|
80
|
+
if self.is_run_with_recv and mask & selectors.EVENT_READ:
|
|
81
|
+
if self.is_with_ssl:
|
|
82
|
+
# ssl doesn't suppôrt flags != 0
|
|
83
|
+
flags = 0
|
|
84
|
+
else:
|
|
85
|
+
flags = read_kwargs.get('flags', 0)
|
|
86
|
+
try:
|
|
87
|
+
recv_data = sock.recv(read_bufsize, flags)
|
|
88
|
+
except ssl.SSLWantReadError:
|
|
89
|
+
recv_data = None
|
|
96
90
|
if recv_data:
|
|
97
|
-
|
|
91
|
+
has_activity = True
|
|
92
|
+
with self._data_lock: # data is self._data
|
|
98
93
|
data.in_bytes += recv_data
|
|
99
|
-
|
|
100
|
-
|
|
94
|
+
if logger.isEnabledFor(logging.DEBUG):
|
|
95
|
+
logger.debug(f"[{self.name}] Received [{recv_data}] (type: {type(recv_data)} ; total: {len(data.in_bytes)})")
|
|
96
|
+
|
|
97
|
+
if self.is_run_with_send and mask & selectors.EVENT_WRITE:
|
|
98
|
+
with self._data_lock: # data is self._data
|
|
101
99
|
if data.out_bytes:
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
if self.__data.in_bytes:
|
|
114
|
-
res = self.__data.in_bytes[:bufsize]
|
|
115
|
-
self.__data.in_bytes = self.__data.in_bytes[bufsize:]
|
|
116
|
-
else:
|
|
117
|
-
res = b''
|
|
118
|
-
return res
|
|
100
|
+
has_activity = True
|
|
101
|
+
try:
|
|
102
|
+
sent = sock.send(data.out_bytes)
|
|
103
|
+
except ssl.SSLWantWriteError:
|
|
104
|
+
sent = 0
|
|
105
|
+
if sent > 0:
|
|
106
|
+
data.out_bytes = data.out_bytes[sent:]
|
|
107
|
+
if logger.isEnabledFor(logging.DEBUG):
|
|
108
|
+
logger.debug(f"[{self.name}] Sent {sent} data (remaining to send: {len(data.out_bytes)})")
|
|
109
|
+
|
|
110
|
+
return has_activity
|
|
119
111
|
|
|
120
|
-
def write(self, data_bytes):
|
|
121
|
-
with self.__data_lock:
|
|
122
|
-
self.__data.out_bytes += data_bytes
|
|
123
|
-
|
|
124
112
|
|
|
125
113
|
class TCPNonBlockingSocketClient(NonBlockingSocketClient):
|
|
126
114
|
"""
|
|
127
115
|
TCP socket client.
|
|
128
116
|
"""
|
|
129
117
|
|
|
130
|
-
def __init__(self, *, name=None, create_ipv4_socket_kwargs=None):
|
|
131
|
-
super().__init__(name=name, create_ipv4_socket_kwargs=create_ipv4_socket_kwargs)
|
|
118
|
+
def __init__(self, *, name=None, create_ipv4_socket_kwargs=None, idle_sleep_delay=undefined_argument, do_run_with_recv=True, do_run_with_send=True):
|
|
119
|
+
super().__init__(name=name, create_ipv4_socket_kwargs=create_ipv4_socket_kwargs, idle_sleep_delay=idle_sleep_delay, do_run_with_recv=do_run_with_recv, do_run_with_send=do_run_with_send)
|
|
132
120
|
|
|
133
121
|
def create_ipv4_socket(self, host, port, **kwargs):
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
sock = socket.create_connection((host, port), **kwargs)
|
|
137
|
-
sock.setblocking(False)
|
|
122
|
+
socket_kwargs = self._new_ssl_context_if_required(**kwargs)
|
|
138
123
|
|
|
139
|
-
if
|
|
140
|
-
sock =
|
|
141
|
-
|
|
124
|
+
if self.is_with_ssl:
|
|
125
|
+
# sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
|
126
|
+
# sock = Socket.create_connection((host, port), do_connect=False, **socket_kwargs)
|
|
127
|
+
sock = socket.create_connection((host, port), **socket_kwargs)
|
|
128
|
+
sock.setblocking(False)
|
|
129
|
+
|
|
130
|
+
wrap_socket_kwargs = self._ssl_wrap_socket_kwargs
|
|
131
|
+
do_handshake_on_connect = wrap_socket_kwargs.pop('do_handshake_on_connect', False)
|
|
132
|
+
sock = self._ssl_context.wrap_socket(sock, server_hostname=host, do_handshake_on_connect=do_handshake_on_connect, **wrap_socket_kwargs)
|
|
133
|
+
self._set_internal_socket(sock, is_ssl_handshake_done_on_connect=do_handshake_on_connect)
|
|
134
|
+
|
|
135
|
+
# sock.connect((host, port))
|
|
136
|
+
else:
|
|
137
|
+
sock = socket.create_connection((host, port), **socket_kwargs)
|
|
138
|
+
sock.setblocking(False)
|
|
139
|
+
self._set_internal_socket(sock)
|
|
142
140
|
|
|
143
141
|
# Register socket
|
|
144
142
|
self._register_socket(sock)
|