def dataReceived(self, data):
        try:
            # Try to parse what we have received until now
            io = StringIO.StringIO(''.join(self._buffer + [data]))

            action, data = pickle.load(io)

            # Unmarshalling succeeded, call callback
            if action == '_input':
                self.connection.shell_in.write(data)

            elif action == '_resize':
                self.connection.pty.set_size(*data)

            elif action == '_get_info':
                # Return information about the current server state
                processes = [ {
                            'node_name': c.connection_shell.shell.state._node.__class__.__name__,
                            'node_module': c.connection_shell.shell.state._node.__module__,
                            'running': c.connection_shell.shell.currently_running or '(Idle)'
                    } for c in self.factory.connectionPool if c.connection_shell and c.connection_shell.shell ]

                self._handle('_info', {
                            'created': self.created.isoformat(),
                            'root_node_name': self.connection.root_node.__class__.__name__,
                            'root_node_module': self.connection.root_node.__module__,
                            'processes': processes,
                    })
                self.transport.loseConnection()

            elif action == 'open-new-window':
                logging.info('Opening new window')
                # When the client wants to open a new shell (Ctrl-N press for
                # instance), check whether we are in an interactive session,
                # and if so, copy this shell.
                if self.connection.connection_shell:
                    self.connection.connection_shell.openNewShellFromReactor()
                else:
                    self._handle('open-new-window', { 'focus': True })

            elif action == '_start-interaction':
                logging.info('Starting session')

                cd_path = data.get('cd_path', None)
                action_name = data.get('action_name', None)
                parameters = data.get('parameters', None)
                open_scp_shell = data.get('open_scp_shell', False)
                term_var = data.get('term_var', False)

                self.connection.set_term_var(term_var)

                # NOTE: The defer to thread method, which will be called back
                # immeditiately, can hang (wait) if the thread pool has been
                # saturated.

                # When a new Pty was needed by an existing shell. (For instance, for
                # a parallel session. Report this connection; otherwise start a new
                # ConnectionShell.
                if PtyManager.need_pty_callback and not action_name:
                    PtyManager.need_pty_callback(self.connection)
                else:
                    self.connection.startShell(cd_path=cd_path,
                            action_name=action_name, parameters=parameters,
                            open_scp_shell=open_scp_shell)

            # Keep the remainder for the next time.
            remainder = io.read()
            self._buffer = [ remainder ]

            # In case we did receive multiple calls
            # one chunk, immediately parse again.
            if len(remainder):
                self.dataReceived('')
        except (EOFError, __HOLE__) as e:
            # Not enough data, wait for the next part to arrive
            if data:
                self._buffer.append(data)
dataset/ETHPy150Open jonathanslenders/python-deployer/deployer/run/socket_server.py/CliClientProtocol.dataReceived