def should_block_on_frame(self, frame):
if not should_debug_code(frame.f_code):
return False
# It is still possible that we're somewhere in standard library code, but that code was invoked by our
# internal debugger machinery (e.g. socket.sendall or text encoding while tee'ing print output to VS).
# We don't want to block on any of that, either, so walk the stack and see if we hit debugger frames
# at some point below the non-debugger ones.
while frame is not None:
# There is usually going to be a debugger frame at the very bottom of the stack - the one that
# invoked user code on this thread when starting debugging. If we reached that, then everything
# above is user code, so we know that we do want to block here.
if frame.f_code in DEBUG_ENTRYPOINTS:
break
# Otherwise, check if it's some other debugger code.
filename = path.normcase(frame.f_code.co_filename)
is_debugger_frame = False
for debugger_file in DONT_DEBUG:
if is_same_py_file(filename, debugger_file):
# If it is, then the frames above it on the stack that we have just walked through
# were for debugger internal purposes, and we do not want to block here.
return False
frame = frame.f_back
return True
python类sendall()的实例源码
def should_block_on_frame(self, frame):
if not should_debug_code(frame.f_code):
return False
# It is still possible that we're somewhere in standard library code, but that code was invoked by our
# internal debugger machinery (e.g. socket.sendall or text encoding while tee'ing print output to VS).
# We don't want to block on any of that, either, so walk the stack and see if we hit debugger frames
# at some point below the non-debugger ones.
while frame is not None:
# There is usually going to be a debugger frame at the very bottom of the stack - the one that
# invoked user code on this thread when starting debugging. If we reached that, then everything
# above is user code, so we know that we do want to block here.
if frame.f_code in DEBUG_ENTRYPOINTS:
break
# Otherwise, check if it's some other debugger code.
filename = path.normcase(frame.f_code.co_filename)
is_debugger_frame = False
for debugger_file in DONT_DEBUG:
if is_same_py_file(filename, debugger_file):
# If it is, then the frames above it on the stack that we have just walked through
# were for debugger internal purposes, and we do not want to block here.
return False
frame = frame.f_back
return True
def escape(self, data):
"""\
This generator function is for the user. All outgoing data has to be
properly escaped, so that no IAC character in the data stream messes up
the Telnet state machine in the server.
socket.sendall(escape(data))
"""
for byte in iterbytes(data):
if byte == IAC:
yield IAC
yield IAC
else:
yield byte
# - incoming data filter
def escape(self, data):
"""\
This generator function is for the user. All outgoing data has to be
properly escaped, so that no IAC character in the data stream messes up
the Telnet state machine in the server.
socket.sendall(escape(data))
"""
for byte in iterbytes(data):
if byte == IAC:
yield IAC
yield IAC
else:
yield byte
# - incoming data filter
def write(self, data):
"""\
Output the given string over the serial port. Can block if the
connection is blocked. May raise SerialException if the connection is
closed.
"""
if not self._isOpen: raise portNotOpenError
self._write_lock.acquire()
try:
try:
self._socket.sendall(to_bytes(data).replace(IAC, IAC_DOUBLED))
except socket.error, e:
raise SerialException("connection failed (socket error): %s" % e) # XXX what exception if socket connection fails
finally:
self._write_lock.release()
return len(data)
def escape(self, data):
"""\
this generator function is for the user. all outgoing data has to be
properly escaped, so that no IAC character in the data stream messes up
the Telnet state machine in the server.
socket.sendall(escape(data))
"""
for byte in data:
if byte == IAC:
yield IAC
yield IAC
else:
yield byte
# - incoming data filter
def write(self, data):
"""\
Output the given string over the serial port. Can block if the
connection is blocked. May raise SerialException if the connection is
closed.
"""
if not self._isOpen: raise portNotOpenError
self._write_lock.acquire()
try:
try:
self._socket.sendall(to_bytes(data).replace(IAC, IAC_DOUBLED))
except socket.error, e:
raise SerialException("connection failed (socket error): %s" % e) # XXX what exception if socket connection fails
finally:
self._write_lock.release()
return len(data)
def escape(self, data):
"""\
this generator function is for the user. all outgoing data has to be
properly escaped, so that no IAC character in the data stream messes up
the Telnet state machine in the server.
socket.sendall(escape(data))
"""
for byte in data:
if byte == IAC:
yield IAC
yield IAC
else:
yield byte
# - incoming data filter
def escape(self, data):
"""\
This generator function is for the user. All outgoing data has to be
properly escaped, so that no IAC character in the data stream messes up
the Telnet state machine in the server.
socket.sendall(escape(data))
"""
for byte in iterbytes(data):
if byte == IAC:
yield IAC
yield IAC
else:
yield byte
# - incoming data filter
def write(self, data):
"""\
Output the given string over the serial port. Can block if the
connection is blocked. May raise SerialException if the connection is
closed.
"""
if not self._isOpen: raise portNotOpenError
self._write_lock.acquire()
try:
try:
self._socket.sendall(to_bytes(data).replace(IAC, IAC_DOUBLED))
except socket.error, e:
raise SerialException("connection failed (socket error): %s" % e) # XXX what exception if socket connection fails
finally:
self._write_lock.release()
return len(data)
def escape(self, data):
"""\
This generator function is for the user. All outgoing data has to be
properly escaped, so that no IAC character in the data stream messes up
the Telnet state machine in the server.
socket.sendall(escape(data))
"""
for byte in iterbytes(data):
if byte == IAC:
yield IAC
yield IAC
else:
yield byte
# - incoming data filter
def escape(self, data):
"""\
This generator function is for the user. All outgoing data has to be
properly escaped, so that no IAC character in the data stream messes up
the Telnet state machine in the server.
socket.sendall(escape(data))
"""
for byte in iterbytes(data):
if byte == IAC:
yield IAC
yield IAC
else:
yield byte
# - incoming data filter
def write(self, data):
"""\
Output the given string over the serial port. Can block if the
connection is blocked. May raise SerialException if the connection is
closed.
"""
if not self._isOpen: raise portNotOpenError
self._write_lock.acquire()
try:
try:
self._socket.sendall(to_bytes(data).replace(IAC, IAC_DOUBLED))
except socket.error, e:
raise SerialException("connection failed (socket error): %s" % e) # XXX what exception if socket connection fails
finally:
self._write_lock.release()
return len(data)
def escape(self, data):
"""\
this generator function is for the user. all outgoing data has to be
properly escaped, so that no IAC character in the data stream messes up
the Telnet state machine in the server.
socket.sendall(escape(data))
"""
for byte in data:
if byte == IAC:
yield IAC
yield IAC
else:
yield byte
# - incoming data filter
def write(self, data):
"""\
Output the given string over the serial port. Can block if the
connection is blocked. May raise SerialException if the connection is
closed.
"""
if not self._isOpen: raise portNotOpenError
self._write_lock.acquire()
try:
try:
self._socket.sendall(to_bytes(data).replace(IAC, IAC_DOUBLED))
except socket.error, e:
raise SerialException("connection failed (socket error): %s" % e) # XXX what exception if socket connection fails
finally:
self._write_lock.release()
return len(data)
def escape(self, data):
"""\
This generator function is for the user. All outgoing data has to be
properly escaped, so that no IAC character in the data stream messes up
the Telnet state machine in the server.
socket.sendall(escape(data))
"""
for byte in data:
if byte == IAC:
yield IAC
yield IAC
else:
yield byte
# - incoming data filter
def write(self, data):
"""\
Output the given string over the serial port. Can block if the
connection is blocked. May raise SerialException if the connection is
closed.
"""
if not self._isOpen: raise portNotOpenError
self._write_lock.acquire()
try:
try:
self._socket.sendall(to_bytes(data).replace(IAC, IAC_DOUBLED))
except socket.error, e:
raise SerialException("connection failed (socket error): %s" % e) # XXX what exception if socket connection fails
finally:
self._write_lock.release()
return len(data)
def escape(self, data):
"""\
this generator function is for the user. all outgoing data has to be
properly escaped, so that no IAC character in the data stream messes up
the Telnet state machine in the server.
socket.sendall(escape(data))
"""
for byte in data:
if byte == IAC:
yield IAC
yield IAC
else:
yield byte
# - incoming data filter
def escape(self, data):
"""\
This generator function is for the user. All outgoing data has to be
properly escaped, so that no IAC character in the data stream messes up
the Telnet state machine in the server.
socket.sendall(escape(data))
"""
for byte in iterbytes(data):
if byte == IAC:
yield IAC
yield IAC
else:
yield byte
# - incoming data filter
def escape(self, data):
"""\
This generator function is for the user. All outgoing data has to be
properly escaped, so that no IAC character in the data stream messes up
the Telnet state machine in the server.
socket.sendall(escape(data))
"""
for byte in iterbytes(data):
if byte == IAC:
yield IAC
yield IAC
else:
yield byte
# - incoming data filter
def should_block_on_frame(self, frame):
if not should_debug_code(frame.f_code):
return False
# It is still possible that we're somewhere in standard library code, but that code was invoked by our
# internal debugger machinery (e.g. socket.sendall or text encoding while tee'ing print output to VS).
# We don't want to block on any of that, either, so walk the stack and see if we hit debugger frames
# at some point below the non-debugger ones.
while frame is not None:
# There is usually going to be a debugger frame at the very bottom of the stack - the one that
# invoked user code on this thread when starting debugging. If we reached that, then everything
# above is user code, so we know that we do want to block here.
if frame.f_code in DEBUG_ENTRYPOINTS:
break
# Otherwise, check if it's some other debugger code.
filename = path.normcase(frame.f_code.co_filename)
is_debugger_frame = False
for debugger_file in DONT_DEBUG:
if is_same_py_file(filename, debugger_file):
# If it is, then the frames above it on the stack that we have just walked through
# were for debugger internal purposes, and we do not want to block here.
return False
frame = frame.f_back
return True
def should_block_on_frame(self, frame):
if not should_debug_code(frame.f_code):
return False
# It is still possible that we're somewhere in standard library code, but that code was invoked by our
# internal debugger machinery (e.g. socket.sendall or text encoding while tee'ing print output to VS).
# We don't want to block on any of that, either, so walk the stack and see if we hit debugger frames
# at some point below the non-debugger ones.
while frame is not None:
# There is usually going to be a debugger frame at the very bottom of the stack - the one that
# invoked user code on this thread when starting debugging. If we reached that, then everything
# above is user code, so we know that we do want to block here.
if frame.f_code in DEBUG_ENTRYPOINTS:
break
# Otherwise, check if it's some other debugger code.
filename = path.normcase(frame.f_code.co_filename)
is_debugger_frame = False
for debugger_file in DONT_DEBUG:
if is_same_py_file(filename, debugger_file):
# If it is, then the frames above it on the stack that we have just walked through
# were for debugger internal purposes, and we do not want to block here.
return False
frame = frame.f_back
return True
def should_block_on_frame(self, frame):
if not should_debug_code(frame.f_code):
return False
# It is still possible that we're somewhere in standard library code, but that code was invoked by our
# internal debugger machinery (e.g. socket.sendall or text encoding while tee'ing print output to VS).
# We don't want to block on any of that, either, so walk the stack and see if we hit debugger frames
# at some point below the non-debugger ones.
while frame is not None:
# There is usually going to be a debugger frame at the very bottom of the stack - the one that
# invoked user code on this thread when starting debugging. If we reached that, then everything
# above is user code, so we know that we do want to block here.
if frame.f_code in DEBUG_ENTRYPOINTS:
break
# Otherwise, check if it's some other debugger code.
filename = path.normcase(frame.f_code.co_filename)
is_debugger_frame = False
for debugger_file in DONT_DEBUG:
if is_same_py_file(filename, debugger_file):
# If it is, then the frames above it on the stack that we have just walked through
# were for debugger internal purposes, and we do not want to block here.
return False
frame = frame.f_back
return True
def escape(self, data):
"""\
This generator function is for the user. All outgoing data has to be
properly escaped, so that no IAC character in the data stream messes up
the Telnet state machine in the server.
socket.sendall(escape(data))
"""
for byte in iterbytes(data):
if byte == IAC:
yield IAC
yield IAC
else:
yield byte
# - incoming data filter
def test_ssl_close(self):
def serve(listener):
sock, addr = listener.accept()
sock.recv(8192)
try:
self.assertEqual(b'', sock.recv(8192))
except greenio.SSL.ZeroReturnError:
pass
sock = listen_ssl_socket()
server_coro = eventlet.spawn(serve, sock)
raw_client = eventlet.connect(sock.getsockname())
client = ssl.wrap_socket(raw_client)
client.sendall(b'X')
greenio.shutdown_safe(client)
client.close()
server_coro.wait()
def test_ssl_unwrap(self):
def serve():
sock, addr = listener.accept()
self.assertEqual(sock.recv(6), b'before')
sock_ssl = ssl.wrap_socket(sock, tests.private_key_file, tests.certificate_file,
server_side=True)
sock_ssl.do_handshake()
self.assertEqual(sock_ssl.recv(6), b'during')
sock2 = sock_ssl.unwrap()
self.assertEqual(sock2.recv(5), b'after')
sock2.close()
listener = eventlet.listen(('127.0.0.1', 0))
server_coro = eventlet.spawn(serve)
client = eventlet.connect(listener.getsockname())
client.sendall(b'before')
client_ssl = ssl.wrap_socket(client)
client_ssl.do_handshake()
client_ssl.sendall(b'during')
client2 = client_ssl.unwrap()
client2.sendall(b'after')
server_coro.wait()
def should_block_on_frame(self, frame):
if not should_debug_code(frame.f_code):
return False
# It is still possible that we're somewhere in standard library code, but that code was invoked by our
# internal debugger machinery (e.g. socket.sendall or text encoding while tee'ing print output to VS).
# We don't want to block on any of that, either, so walk the stack and see if we hit debugger frames
# at some point below the non-debugger ones.
while frame is not None:
# There is usually going to be a debugger frame at the very bottom of the stack - the one that
# invoked user code on this thread when starting debugging. If we reached that, then everything
# above is user code, so we know that we do want to block here.
if frame.f_code in DEBUG_ENTRYPOINTS:
break
# Otherwise, check if it's some other debugger code.
filename = path.normcase(frame.f_code.co_filename)
is_debugger_frame = False
for debugger_file in DONT_DEBUG:
if is_same_py_file(filename, debugger_file):
# If it is, then the frames above it on the stack that we have just walked through
# were for debugger internal purposes, and we do not want to block here.
return False
frame = frame.f_back
return True
def should_block_on_frame(self, frame):
if not should_debug_code(frame.f_code):
return False
# It is still possible that we're somewhere in standard library code, but that code was invoked by our
# internal debugger machinery (e.g. socket.sendall or text encoding while tee'ing print output to VS).
# We don't want to block on any of that, either, so walk the stack and see if we hit debugger frames
# at some point below the non-debugger ones.
while frame is not None:
# There is usually going to be a debugger frame at the very bottom of the stack - the one that
# invoked user code on this thread when starting debugging. If we reached that, then everything
# above is user code, so we know that we do want to block here.
if frame.f_code in DEBUG_ENTRYPOINTS:
break
# Otherwise, check if it's some other debugger code.
filename = path.normcase(frame.f_code.co_filename)
is_debugger_frame = False
for debugger_file in DONT_DEBUG:
if is_same_py_file(filename, debugger_file):
# If it is, then the frames above it on the stack that we have just walked through
# were for debugger internal purposes, and we do not want to block here.
return False
frame = frame.f_back
return True
def write(self, data):
"""\
Output the given byte string over the serial port. Can block if the
connection is blocked. May raise SerialException if the connection is
closed.
"""
if not self.is_open:
raise portNotOpenError
with self._write_lock:
try:
self._socket.sendall(to_bytes(data).replace(IAC, IAC_DOUBLED))
except socket.error as e:
raise SerialException("connection failed (socket error): %s" % (e,))
return len(data)
def _internal_raw_write(self, data):
"""internal socket write with no data escaping. used to send telnet stuff."""
with self._write_lock:
self._socket.sendall(data)