本文整理匯總了Python中ssl.SSL_ERROR_WANT_WRITE屬性的典型用法代碼示例。如果您正苦於以下問題:Python ssl.SSL_ERROR_WANT_WRITE屬性的具體用法?Python ssl.SSL_ERROR_WANT_WRITE怎麽用?Python ssl.SSL_ERROR_WANT_WRITE使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類ssl
的用法示例。
在下文中一共展示了ssl.SSL_ERROR_WANT_WRITE屬性的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: _doSSLHandshake
# 需要導入模塊: import ssl [as 別名]
# 或者: from ssl import SSL_ERROR_WANT_WRITE [as 別名]
def _doSSLHandshake(self) :
count = 0
while count < 10 :
try :
self._socket.do_handshake()
break
except ssl.SSLError as sslErr :
count += 1
if sslErr.args[0] == ssl.SSL_ERROR_WANT_READ :
select([self._socket], [], [], 1)
elif sslErr.args[0] == ssl.SSL_ERROR_WANT_WRITE :
select([], [self._socket], [], 1)
else :
raise XAsyncTCPClientException('SSL : Bad handshake : %s' % sslErr)
except Exception as ex :
raise XAsyncTCPClientException('SSL : Handshake error : %s' % ex)
# ------------------------------------------------------------------------
示例2: _do_ssl_shutdown
# 需要導入模塊: import ssl [as 別名]
# 或者: from ssl import SSL_ERROR_WANT_WRITE [as 別名]
def _do_ssl_shutdown(self):
self._ssl_closing = True
try:
self.socket = self.socket.unwrap()
except ssl.SSLError as err:
if err.args[0] in (ssl.SSL_ERROR_WANT_READ,
ssl.SSL_ERROR_WANT_WRITE):
return
except socket.error as err:
# Any "socket error" corresponds to a SSL_ERROR_SYSCALL return
# from OpenSSL's SSL_shutdown(), corresponding to a
# closed socket condition. See also:
# http://www.mail-archive.com/openssl-users@openssl.org/msg60710.html
pass
self._ssl_closing = False
if getattr(self, '_ccc', False) is False:
super(SSLConnection, self).close()
else:
pass
示例3: write_to_fd
# 需要導入模塊: import ssl [as 別名]
# 或者: from ssl import SSL_ERROR_WANT_WRITE [as 別名]
def write_to_fd(self, data: memoryview) -> int:
try:
return self.socket.send(data) # type: ignore
except ssl.SSLError as e:
if e.args[0] == ssl.SSL_ERROR_WANT_WRITE:
# In Python 3.5+, SSLSocket.send raises a WANT_WRITE error if
# the socket is not writeable; we need to transform this into
# an EWOULDBLOCK socket.error or a zero return value,
# either of which will be recognized by the caller of this
# method. Prior to Python 3.5, an unwriteable socket would
# simply return 0 bytes written.
return 0
raise
finally:
# Avoid keeping to data, which can be a memoryview.
# See https://github.com/tornadoweb/tornado/pull/2008
del data
示例4: write_to_fd
# 需要導入模塊: import ssl [as 別名]
# 或者: from ssl import SSL_ERROR_WANT_WRITE [as 別名]
def write_to_fd(self, data):
try:
return self.socket.send(data)
except ssl.SSLError as e:
if e.args[0] == ssl.SSL_ERROR_WANT_WRITE:
# In Python 3.5+, SSLSocket.send raises a WANT_WRITE error if
# the socket is not writeable; we need to transform this into
# an EWOULDBLOCK socket.error or a zero return value,
# either of which will be recognized by the caller of this
# method. Prior to Python 3.5, an unwriteable socket would
# simply return 0 bytes written.
return 0
raise
finally:
# Avoid keeping to data, which can be a memoryview.
# See https://github.com/tornadoweb/tornado/pull/2008
del data
示例5: _do_ssl_shutdown
# 需要導入模塊: import ssl [as 別名]
# 或者: from ssl import SSL_ERROR_WANT_WRITE [as 別名]
def _do_ssl_shutdown(self):
self._ssl_closing = True
try:
self.socket = self.socket.unwrap()
except ssl.SSLError as err:
if err.args[0] in (ssl.SSL_ERROR_WANT_READ,
ssl.SSL_ERROR_WANT_WRITE):
return
except OSError as err:
# Any "socket error" corresponds to a SSL_ERROR_SYSCALL return
# from OpenSSL's SSL_shutdown(), corresponding to a
# closed socket condition. See also:
# http://www.mail-archive.com/openssl-users@openssl.org/msg60710.html
pass
self._ssl_closing = False
if getattr(self, '_ccc', False) is False:
super(SSLConnection, self).close()
else:
pass
示例6: _send_discovery_request
# 需要導入模塊: import ssl [as 別名]
# 或者: from ssl import SSL_ERROR_WANT_WRITE [as 別名]
def _send_discovery_request(self, ssl_sock, thing_name):
request = self.REQUEST_TYPE_PREFIX + \
self.PAYLOAD_PREFIX + \
thing_name + \
self.PAYLOAD_SUFFIX + \
self.HOST_PREFIX + \
self._host + ":" + str(self._port) + \
self.HOST_SUFFIX
self._logger.debug("Sending discover request: " + request)
start_time = time.time()
desired_length_to_write = len(request)
actual_length_written = 0
while True:
try:
length_written = ssl_sock.write(request.encode("utf-8"))
actual_length_written += length_written
except socket.error as err:
if err.errno == ssl.SSL_ERROR_WANT_READ or err.errno == ssl.SSL_ERROR_WANT_WRITE:
pass
if actual_length_written == desired_length_to_write:
return self.LOW_LEVEL_RC_COMPLETE
if start_time + self._timeout_sec < time.time():
return self.LOW_LEVEL_RC_TIMEOUT
示例7: _receive_until
# 需要導入模塊: import ssl [as 別名]
# 或者: from ssl import SSL_ERROR_WANT_WRITE [as 別名]
def _receive_until(self, ssl_sock, criteria_function, extra_data=None):
start_time = time.time()
response = bytearray()
number_bytes_read = 0
while True: # Python does not have do-while
try:
response.append(self._convert_to_int_py3(ssl_sock.read(1)))
number_bytes_read += 1
except socket.error as err:
if err.errno == ssl.SSL_ERROR_WANT_READ or err.errno == ssl.SSL_ERROR_WANT_WRITE:
pass
if criteria_function((number_bytes_read, response, extra_data)):
return self.LOW_LEVEL_RC_COMPLETE, response
if start_time + self._timeout_sec < time.time():
return self.LOW_LEVEL_RC_TIMEOUT, response
示例8: _hasCredentialsNecessaryForWebsocket
# 需要導入模塊: import ssl [as 別名]
# 或者: from ssl import SSL_ERROR_WANT_WRITE [as 別名]
def _hasCredentialsNecessaryForWebsocket(self, allKeys):
awsAccessKeyIdCandidate = allKeys.get("aws_access_key_id")
awsSecretAccessKeyCandidate = allKeys.get("aws_secret_access_key")
# None value is NOT considered as valid entries
validEntries = awsAccessKeyIdCandidate is not None and awsAccessKeyIdCandidate is not None
if validEntries:
# Empty value is NOT considered as valid entries
validEntries &= (len(awsAccessKeyIdCandidate) != 0 and len(awsSecretAccessKeyCandidate) != 0)
return validEntries
# This is an internal class that buffers the incoming bytes into an
# internal buffer until it gets the full desired length of bytes.
# At that time, this bufferedReader will be reset.
# *Error handling:
# For retry errors (ssl.SSL_ERROR_WANT_READ, ssl.SSL_ERROR_WANT_WRITE, EAGAIN),
# leave them to the paho _packet_read for further handling (ignored and try
# again when data is available.
# For other errors, leave them to the paho _packet_read for error reporting.
示例9: send
# 需要導入模塊: import ssl [as 別名]
# 或者: from ssl import SSL_ERROR_WANT_WRITE [as 別名]
def send(self, data):
"""
If data is ``None`` then ``self.write_buf`` is used.
"""
if (data is not None) and not self.send_finished:
raise SendNotFinished(("previous send on %r is not finished, " +
"wait for on_ready_to_send") % self)
data = data or self.write_buf
self.send_finished = False
if self.ssl_config is None:
self.last_send_size = self.sock.send(data)
else:
try:
self.last_send_size = self.sock.write(data)
self.write_buf = None
except ssl.SSLError as exc:
if exc.args[0] != ssl.SSL_ERROR_WANT_WRITE:
raise
self.write_buf = data
#########################################################
示例10: _continue_tls_handshake
# 需要導入模塊: import ssl [as 別名]
# 或者: from ssl import SSL_ERROR_WANT_WRITE [as 別名]
def _continue_tls_handshake(self):
"""Continue a TLS handshake."""
try:
logger.debug(" do_handshake()")
self._socket.do_handshake()
except ssl.SSLError as err:
if err.args[0] == ssl.SSL_ERROR_WANT_READ:
self._tls_state = "want_read"
logger.debug(" want_read")
self._state_cond.notify()
return
elif err.args[0] == ssl.SSL_ERROR_WANT_WRITE:
self._tls_state = "want_write"
logger.debug(" want_write")
self._write_queue.appendleft(TLSHandshake)
return
else:
raise
self._tls_state = "connected"
self._set_state("connected")
self.event(TLSConnectedEvent(self._socket.cipher(),
self._socket.getpeercert()))
示例11: wrap_socket
# 需要導入模塊: import ssl [as 別名]
# 或者: from ssl import SSL_ERROR_WANT_WRITE [as 別名]
def wrap_socket(cls, socket):
sock = ssl.wrap_socket(socket, ssl_version=ssl.PROTOCOL_TLSv1)
while True:
try:
logger.info('Performing TLS handshade...')
sock.do_handshake()
break
except ssl.SSLError as err:
errs = (
ssl.SSL_ERROR_WANT_READ,
ssl.SSL_ERROR_WANT_WRITE)
if err.args[0] not in (errs):
raise
else:
logger.info('Continuing TLS handshake...')
logger.info('Socket wrapped')
return sock
示例12: test_flush_would_block_ssl_write_buffer
# 需要導入模塊: import ssl [as 別名]
# 或者: from ssl import SSL_ERROR_WANT_WRITE [as 別名]
def test_flush_would_block_ssl_write_buffer(self):
'''ssl.SSL_ERROR_WANT_WRITE usesthe same buffer on next send'''
pending = deque([b'1', b'2', b'3'])
with mock.patch.object(self.connection, '_pending', pending):
with mock.patch.object(self.connection, '_socket') as mock_socket:
mock_socket.send.side_effect = ssl.SSLError(
ssl.SSL_ERROR_WANT_WRITE)
self.assertFalse(self.connection._out_buffer)
self.connection.flush()
self.assertEqual(self.connection._out_buffer, b'123')
# With some more pending items, make sure we still only get '123' sent
pending = deque([b'4', b'5', b'6'])
with mock.patch.object(self.connection, '_pending', pending):
with mock.patch.object(self.connection, '_socket') as mock_socket:
mock_socket.send.return_value = 3
# The first flush should see the existing buffer
self.connection.flush()
mock_socket.send.assert_called_with(b'123')
# The second flush should see the pending requests
self.connection.flush()
mock_socket.send.assert_called_with(b'456')
示例13: write_to_fd
# 需要導入模塊: import ssl [as 別名]
# 或者: from ssl import SSL_ERROR_WANT_WRITE [as 別名]
def write_to_fd(self, data):
try:
return self.socket.send(data)
except ssl.SSLError as e:
if e.args[0] == ssl.SSL_ERROR_WANT_WRITE:
# In Python 3.5+, SSLSocket.send raises a WANT_WRITE error if
# the socket is not writeable; we need to transform this into
# an EWOULDBLOCK socket.error or a zero return value,
# either of which will be recognized by the caller of this
# method. Prior to Python 3.5, an unwriteable socket would
# simply return 0 bytes written.
return 0
raise
示例14: _do_ssl_handshake
# 需要導入模塊: import ssl [as 別名]
# 或者: from ssl import SSL_ERROR_WANT_WRITE [as 別名]
def _do_ssl_handshake(self):
try:
self.socket.do_handshake()
except ssl.SSLError as err:
if err.args[0] in (ssl.SSL_ERROR_WANT_READ,
ssl.SSL_ERROR_WANT_WRITE):
return
elif err.args[0] == ssl.SSL_ERROR_EOF:
return self.handle_close()
raise
except socket.error as err:
if err.args[0] == errno.ECONNABORTED:
return self.handle_close()
else:
self._ssl_accepting = False
示例15: send
# 需要導入模塊: import ssl [as 別名]
# 或者: from ssl import SSL_ERROR_WANT_WRITE [as 別名]
def send(self, data):
try:
return super(SSLConnection, self).send(data)
except ssl.SSLError as err:
if err.args[0] in (ssl.SSL_ERROR_EOF, ssl.SSL_ERROR_ZERO_RETURN,
ssl.SSL_ERROR_WANT_READ,
ssl.SSL_ERROR_WANT_WRITE):
return 0
raise