Python socket.sendall() Examples

The following are code examples for showing how to use socket.sendall(). They are extracted from open source Python projects. You can vote up the examples you like or vote down the exmaples you don't like. You can also save this page to your account.

Example 1
Project: deb-python-eventlet   Author: openstack   File: ssl_test.py    (license) View Source Project 8 votes vote down vote up
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() 
Example 2
Project: pythonVSCode   Author: DonJayamanne   File: visualstudio_py_debugger.py    (license) View Source Project 6 votes vote down vote up
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 
Example 3
Project: pythonVSCode   Author: DonJayamanne   File: visualstudio_py_debugger.py    (license) View Source Project 6 votes vote down vote up
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 
Example 4
Project: android3dblendermouse   Author: sketchpunk   File: rfc2217.py    (license) View Source Project 6 votes vote down vote up
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 
Example 5
Project: microperi   Author: c0d3st0rm   File: rfc2217.py    (license) View Source Project 6 votes vote down vote up
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 
Example 6
Project: microbit-gateway   Author: whaleygeek   File: rfc2217.py    (license) View Source Project 6 votes vote down vote up
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) 
Example 7
Project: microbit-gateway   Author: whaleygeek   File: rfc2217.py    (license) View Source Project 6 votes vote down vote up
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 
Example 8
Project: mb_remote   Author: whaleygeek   File: rfc2217.py    (license) View Source Project 6 votes vote down vote up
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) 
Example 9
Project: mb_remote   Author: whaleygeek   File: rfc2217.py    (license) View Source Project 6 votes vote down vote up
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 
Example 10
Project: gcodeplot   Author: arpruss   File: rfc2217.py    (license) View Source Project 6 votes vote down vote up
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 
Example 11
Project: gcodeplot   Author: arpruss   File: rfc2217.py    (license) View Source Project 6 votes vote down vote up
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) 
Example 12
Project: bitio   Author: whaleygeek   File: rfc2217.py    (license) View Source Project 6 votes vote down vote up
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 
Example 13
Project: microbit-serial   Author: martinohanlon   File: rfc2217.py    (license) View Source Project 6 votes vote down vote up
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 
Example 14
Project: CANbit   Author: whaleygeek   File: rfc2217.py    (license) View Source Project 6 votes vote down vote up
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) 
Example 15
Project: CANbit   Author: whaleygeek   File: rfc2217.py    (license) View Source Project 6 votes vote down vote up
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 
Example 16
Project: driveboardapp   Author: nortd   File: rfc2217.py    (license) View Source Project 6 votes vote down vote up
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) 
Example 17
Project: driveboardapp   Author: nortd   File: rfc2217.py    (license) View Source Project 6 votes vote down vote up
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 
Example 18
Project: mb_sdcard   Author: whaleygeek   File: rfc2217.py    (license) View Source Project 6 votes vote down vote up
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) 
Example 19
Project: mb_sdcard   Author: whaleygeek   File: rfc2217.py    (license) View Source Project 6 votes vote down vote up
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 
Example 20
Project: ddt4all   Author: cedricp   File: rfc2217.py    (license) View Source Project 6 votes vote down vote up
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 
Example 21
Project: mt7687-serial-uploader   Author: will127534   File: rfc2217.py    (license) View Source Project 6 votes vote down vote up
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 
Example 22
Project: HomeAutomation   Author: gs2671   File: visualstudio_py_debugger.py    (license) View Source Project 6 votes vote down vote up
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 
Example 23
Project: xidian-sfweb   Author: Gear420   File: visualstudio_py_debugger.py    (license) View Source Project 6 votes vote down vote up
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 
Example 24
Project: skojjt   Author: martin-green   File: visualstudio_py_debugger.py    (license) View Source Project 6 votes vote down vote up
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 
Example 25
Project: Jackal_Velodyne_Duke   Author: MengGuo   File: rfc2217.py    (license) View Source Project 6 votes vote down vote up
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 
Example 26
Project: DjangoWebProject   Author: wrkettlitz   File: visualstudio_py_debugger.py    (license) View Source Project 6 votes vote down vote up
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 
Example 27
Project: ApiRestPythonTest   Author: rvfvazquez   File: visualstudio_py_debugger.py    (license) View Source Project 6 votes vote down vote up
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 
Example 28
Project: android3dblendermouse   Author: sketchpunk   File: rfc2217.py    (license) View Source Project 5 votes vote down vote up
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) 
Example 29
Project: android3dblendermouse   Author: sketchpunk   File: rfc2217.py    (license) View Source Project 5 votes vote down vote up
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) 
Example 30
Project: microperi   Author: c0d3st0rm   File: rfc2217.py    (license) View Source Project 5 votes vote down vote up
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) 
Example 31
Project: microperi   Author: c0d3st0rm   File: rfc2217.py    (license) View Source Project 5 votes vote down vote up
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) 
Example 32
Project: microbit-gateway   Author: whaleygeek   File: rfc2217.py    (license) View Source Project 5 votes vote down vote up
def _internal_raw_write(self, data):
        """internal socket write with no data escaping. used to send telnet stuff."""
        self._write_lock.acquire()
        try:
            self._socket.sendall(data)
        finally:
            self._write_lock.release() 
Example 33
Project: mb_remote   Author: whaleygeek   File: rfc2217.py    (license) View Source Project 5 votes vote down vote up
def _internal_raw_write(self, data):
        """internal socket write with no data escaping. used to send telnet stuff."""
        self._write_lock.acquire()
        try:
            self._socket.sendall(data)
        finally:
            self._write_lock.release() 
Example 34
Project: gcodeplot   Author: arpruss   File: rfc2217.py    (license) View Source Project 5 votes vote down vote up
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): {}".format(e))
        return len(data) 
Example 35
Project: gcodeplot   Author: arpruss   File: rfc2217.py    (license) View Source Project 5 votes vote down vote up
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) 
Example 36
Project: gcodeplot   Author: arpruss   File: rfc2217.py    (license) View Source Project 5 votes vote down vote up
def _internal_raw_write(self, data):
        """internal socket write with no data escaping. used to send telnet stuff."""
        self._write_lock.acquire()
        try:
            self._socket.sendall(data)
        finally:
            self._write_lock.release() 
Example 37
Project: SMAC-M   Author: LarsSchy   File: process_level.py    (license) View Source Project 5 votes vote down vote up
def send_progress(socket, min, max, current):
    if socket:
        s = "p:min={},max={},current={}\n".format(min, max, current)
        try:
            r = socket.sendall(s)
        except:
            print ("Error sending progress information") 
Example 38
Project: bitio   Author: whaleygeek   File: rfc2217.py    (license) View Source Project 5 votes vote down vote up
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): {}".format(e))
        return len(data) 
Example 39
Project: bitio   Author: whaleygeek   File: rfc2217.py    (license) View Source Project 5 votes vote down vote up
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) 
Example 40
Project: microbit-serial   Author: martinohanlon   File: rfc2217.py    (license) View Source Project 5 votes vote down vote up
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) 
Example 41
Project: microbit-serial   Author: martinohanlon   File: rfc2217.py    (license) View Source Project 5 votes vote down vote up
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) 
Example 42
Project: CANbit   Author: whaleygeek   File: rfc2217.py    (license) View Source Project 5 votes vote down vote up
def _internal_raw_write(self, data):
        """internal socket write with no data escaping. used to send telnet stuff."""
        self._write_lock.acquire()
        try:
            self._socket.sendall(data)
        finally:
            self._write_lock.release() 
Example 43
Project: driveboardapp   Author: nortd   File: rfc2217.py    (license) View Source Project 5 votes vote down vote up
def _internal_raw_write(self, data):
        """internal socket write with no data escaping. used to send telnet stuff."""
        self._write_lock.acquire()
        try:
            self._socket.sendall(data)
        finally:
            self._write_lock.release() 
Example 44
Project: LMDocker-project   Author: xiaozhazi   File: client.py    (license) View Source Project 5 votes vote down vote up
def send_file():

	try:
		socket.connect((HOST,PORT))
	except Exception,e:
		print 'Error connecting to server:%s'% e

	full_name = '/tmp/' + image_name + '.tar'

	print 'send:' + full_name

	try:
		socket.send(full_name,1024)
		data = socket.recv(1024)
	except Exception,e:
		print 'Error,socket send and recv file name failed:%s' % e
		return
	
	if data == 'ready':
		file_to_send = open(full_name,'rb')
		while True:
			data = file_to_send.read(4096)
			if not data:
				break;
			
			socket.sendall(data)
	
	file_to_send.close()
	socket.send('',1024)
	socket.close() 
Example 45
Project: ryu-lagopus-ext   Author: lagopus   File: net_ctrl.py    (license) View Source Project 5 votes vote down vote up
def _sendall(self, msg):
        return self._sock_wrap(self._socket.sendall)(msg) 
Example 46
Project: ryu-lagopus-ext   Author: lagopus   File: net_ctrl.py    (license) View Source Project 5 votes vote down vote up
def _send_success_response(rpc_session, socket, request, result):
    response = rpc_session.create_success_response(request[RPC_IDX_MSG_ID],
                                                   result)
    socket.sendall(response) 
Example 47
Project: ryu-lagopus-ext   Author: lagopus   File: net_ctrl.py    (license) View Source Project 5 votes vote down vote up
def _send_error_response(rpc_session, socket, request, emsg):
    response = rpc_session.create_error_response(request[RPC_IDX_MSG_ID],
                                                 str(emsg))
    socket.sendall(response)


# Network controller singleton 
Example 48
Project: mgr.p2p.proxy   Author: tomusdrw   File: jsonrpc.py    (license) View Source Project 5 votes vote down vote up
def sendAll(self, socket, string):
        socket.sendall(string + TERMINAL) 
Example 49
Project: mb_sdcard   Author: whaleygeek   File: rfc2217.py    (license) View Source Project 5 votes vote down vote up
def _internal_raw_write(self, data):
        """internal socket write with no data escaping. used to send telnet stuff."""
        self._write_lock.acquire()
        try:
            self._socket.sendall(data)
        finally:
            self._write_lock.release() 
Example 50
Project: ddt4all   Author: cedricp   File: rfc2217.py    (license) View Source Project 5 votes vote down vote up
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): {}".format(e))
        return len(data)