Ejemplo n.º 1
0
    def saveglobals(self):
        """Save globals() into filename"""
        ns = self.get_current_namespace()
        from spyderlib.utils.iofuncs import iofunctions

        settings = read_packet(self.i_request)
        filename = read_packet(self.i_request)
        more_excluded_names = ["In", "Out"] if self.ipython_shell else None
        data = get_remote_data(ns, settings, mode="picklable", more_excluded_names=more_excluded_names).copy()
        return iofunctions.save(data, filename)
Ejemplo n.º 2
0
 def saveglobals(self):
     """Save globals() into filename"""
     ns = self.get_current_namespace()
     from spyderlib.utils.iofuncs import iofunctions
     settings = read_packet(self.i_request)
     filename = read_packet(self.i_request)
     more_excluded_names = ['In', 'Out'] if self.ipython_shell else None
     data = get_remote_data(ns, settings, mode='picklable',
                            more_excluded_names=more_excluded_names).copy()
     return iofunctions.save(data, filename)
Ejemplo n.º 3
0
 def setglobal(self, name):
     """
     Set global reference value
     """
     ns = self.get_reference_namespace(name)
     ns[name] = read_packet(self.i_request)
     self.refresh_after_eval = True
Ejemplo n.º 4
0
 def set_remote_view_settings(self):
     """
     Set the namespace remote view settings
     (see the namespace browser widget)
     """
     self.remote_view_settings = read_packet(self.i_request)
     self.enable_refresh_after_eval()
Ejemplo n.º 5
0
 def setglobal(self, name):
     """
     Set global reference value
     """
     ns = self.get_reference_namespace(name)
     ns[name] = read_packet(self.i_request)
     self.refresh_after_eval = True
Ejemplo n.º 6
0
 def set_remote_view_settings(self):
     """
     Set the namespace remote view settings
     (see the namespace browser widget)
     """
     self.remote_view_settings = read_packet(self.i_request)
     self.enable_refresh_after_eval()
Ejemplo n.º 7
0
 def loadglobals(self):
     """Load globals() from filename"""
     glbs = self.mglobals()
     from spyderlib.utils.iofuncs import iofunctions
     filename = read_packet(self.i_request)
     ext = read_packet(self.i_request)
     load_func = iofunctions.load_funcs[ext]
     data, error_message = load_func(filename)
     if error_message:
         return error_message
     for key in data.keys():
         new_key = fix_reference_name(key, blacklist=glbs.keys())
         if new_key != key:
             data[new_key] = data.pop(key)
     try:
         glbs.update(data)
     except Exception, error:
         return str(error)
Ejemplo n.º 8
0
 def loadglobals(self):
     """Load globals() from filename"""
     glbs = self.mglobals()
     from spyderlib.utils.iofuncs import iofunctions
     filename = read_packet(self.i_request)
     ext = read_packet(self.i_request)
     load_func = iofunctions.load_funcs[ext]
     data, error_message = load_func(filename)
     if error_message:
         return error_message
     for key in list(data.keys()):
         new_key = fix_reference_name(key, blacklist=list(glbs.keys()))
         if new_key != key:
             data[new_key] = data.pop(key)
     try:
         glbs.update(data)
     except Exception as error:
         return str(error)
     self.refresh_after_eval = True
Ejemplo n.º 9
0
 def run(self):
     """Start server"""
     sock = socket.socket(socket.AF_INET)
     sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
     sock.bind( ("127.0.0.1", self.port) )
     
     while True:
         sock.listen(2)
         conn, _addr = sock.accept()
         shell_id = read_packet(conn)
         if shell_id is not None:
             self.send_socket(shell_id, conn)
Ejemplo n.º 10
0
 def run(self):
     while True:
         try:
             conn, _addr = self.sock.accept()
         except socket.error as e:
             badfd = errno.WSAEBADF if os.name == 'nt' else errno.EBADF
             extra = errno.WSAENOTSOCK if os.name == 'nt' else badfd
             if e.args[0] in [errno.ECONNABORTED, badfd, extra]:
                 return
             # See Issue 1275 for details on why errno EINTR is
             # silently ignored here.
             eintr = errno.WSAEINTR if os.name == 'nt' else errno.EINTR
             if e.args[0] == eintr:
                 continue
             raise
         if not self._initialized:
             server_port = read_packet(conn)
             if isinstance(server_port, int):
                 self._initialized = True
                 self.initialized.emit(server_port)
         else:
             self.request_handled.emit(read_packet(conn))
Ejemplo n.º 11
0
 def run(self):
     while True:
         try:
             conn, _addr = self.sock.accept()
         except socket.error as e:
             badfd = errno.WSAEBADF if os.name == 'nt' else errno.EBADF
             extra = errno.WSAENOTSOCK if os.name == 'nt' else badfd
             if e.args[0] in [errno.ECONNABORTED, badfd, extra]:
                 return
             # See Issue 1275 for details on why errno EINTR is
             # silently ignored here.
             eintr = errno.WSAEINTR if os.name == 'nt' else errno.EINTR
             if e.args[0] == eintr:
                 continue
             raise
         if not self._initialized:
             server_port = read_packet(conn)
             if isinstance(server_port, int):
                 self._initialized = True
                 self.initialized.emit(server_port)
         else:
             self.request_handled.emit(read_packet(conn))
Ejemplo n.º 12
0
 def run(self):
     """Start notification thread"""
     while True:
         if self.notify_socket is None:
             continue
         output = None
         try:
             try:
                 cdict = read_packet(self.notify_socket)
             except:
                 # This except statement is intended to handle a struct.error
                 # (but when writing 'except struct.error', it doesn't work)
                 # Note: struct.error is raised when the communication has 
                 # been interrupted and the received data is not a string 
                 # of length 8 as required by struct.unpack (see read_packet)
                 break
             if cdict is None:
                 # Another notification thread has just terminated and 
                 # then wrote 'None' in the notification socket
                 # (see the 'finally' statement below)
                 continue
             if not isinstance(cdict, dict):
                 raise TypeError("Invalid data type: %r" % cdict)
             command = cdict['command']
             data = cdict.get('data')
             if command == 'pdb_step':
                 fname, lineno = data
                 self.emit(SIGNAL('pdb(QString,int)'), fname, lineno)
                 self.emit(SIGNAL('refresh_namespace_browser()'))
             elif command == 'refresh':
                 self.emit(SIGNAL('refresh_namespace_browser()'))
             elif command == 'remote_view':
                 self.sig_process_remote_view.emit(data)
             elif command == 'ipykernel':
                 self.emit(SIGNAL('new_ipython_kernel(QString)'), data)
             elif command == 'open_file':
                 fname, lineno = data
                 self.emit(SIGNAL('open_file(QString,int)'), fname, lineno)
             else:
                 raise RuntimeError('Unsupported command: %r' % command)
             if DEBUG_INTROSPECTION:
                 logging.debug("received command: %r" % command)
         except:
             log_last_error(LOG_FILENAME, "notification thread")
         finally:
             try:
                 write_packet(self.notify_socket, output)
             except:
                 # The only reason why it should fail is that Spyder is 
                 # closing while this thread is still alive
                 break
Ejemplo n.º 13
0
 def run(self):
     """Start notification thread"""
     while True:
         if self.notify_socket is None:
             continue
         output = None
         try:
             try:
                 cdict = read_packet(self.notify_socket)
             except:
                 # This except statement is intended to handle a struct.error
                 # (but when writing 'except struct.error', it doesn't work)
                 # Note: struct.error is raised when the communication has
                 # been interrupted and the received data is not a string
                 # of length 8 as required by struct.unpack (see read_packet)
                 break
             if cdict is None:
                 # Another notification thread has just terminated and
                 # then wrote 'None' in the notification socket
                 # (see the 'finally' statement below)
                 continue
             if not isinstance(cdict, dict):
                 raise TypeError("Invalid data type: %r" % cdict)
             command = cdict['command']
             data = cdict.get('data')
             if command == 'pdb_step':
                 fname, lineno = data
                 self.sig_pdb.emit(fname, lineno)
                 self.refresh_namespace_browser.emit()
             elif command == 'refresh':
                 self.refresh_namespace_browser.emit()
             elif command == 'remote_view':
                 self.sig_process_remote_view.emit(data)
             elif command == 'ipykernel':
                 self.new_ipython_kernel.emit(data)
             elif command == 'open_file':
                 fname, lineno = data
                 self.open_file.emit(fname, lineno)
             else:
                 raise RuntimeError('Unsupported command: %r' % command)
             if DEBUG_INTROSPECTION:
                 logging.debug("received command: %r" % command)
         except:
             log_last_error(LOG_FILENAME, "notification thread")
         finally:
             try:
                 write_packet(self.notify_socket, output)
             except:
                 # The only reason why it should fail is that Spyder is
                 # closing while this thread is still alive
                 break
Ejemplo n.º 14
0
 def listen(self):
     """Listen for requests"""
     while True:
         try:
             conn, _addr = self._server_sock.accept()
         except socket.error as e:
             badfd = errno.WSAEBADF if os.name == 'nt' else errno.EBADF
             extra = errno.WSAENOTSOCK if os.name == 'nt' else badfd
             if e.args[0] in [errno.ECONNABORTED, badfd, extra]:
                 return
             # See Issue 1275 for details on why errno EINTR is
             # silently ignored here.
             eintr = errno.WSAEINTR if os.name == 'nt' else errno.EINTR
             if e.args[0] == eintr:
                 continue
             raise
         self.queue.put(read_packet(conn))
Ejemplo n.º 15
0
 def run(self):
     """Start server"""
     sock = socket.socket(socket.AF_INET)
     sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
     sock.bind( ("127.0.0.1", self.port) )
     
     while True:
         sock.listen(2)
         try:
             conn, _addr = sock.accept()
         except socket.error as e:
             # See Issue 1275 for details on why errno EINTR is
             # silently ignored here.
             eintr = errno.WSAEINTR if os.name == 'nt' else errno.EINTR
             if e.args[0] == eintr:
                 continue
             raise
         shell_id = read_packet(conn)
         if shell_id is not None:
             self.send_socket(shell_id, conn)
Ejemplo n.º 16
0
    def run(self):
        """Start server"""
        sock = socket.socket(socket.AF_INET)
        sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
        sock.bind(("127.0.0.1", self.port))

        while True:
            sock.listen(2)
            try:
                conn, _addr = sock.accept()
            except socket.error as e:
                # See Issue 1275 for details on why errno EINTR is
                # silently ignored here.
                eintr = errno.WSAEINTR if os.name == 'nt' else errno.EINTR
                if e.args[0] == eintr:
                    continue
                raise
            shell_id = read_packet(conn)
            if shell_id is not None:
                self.send_socket(shell_id, conn)
Ejemplo n.º 17
0
 def setenv(self):
     """Set os.environ"""
     env = read_packet(self.i_request)
     os.environ = env
Ejemplo n.º 18
0
    def run(self):
        self.ipython_shell = None
        while True:
            output = pickle.dumps(None, PICKLE_HIGHEST_PROTOCOL)
            glbs = self.mglobals()
            try:
                if DEBUG_MONITOR:
                    logging.debug("****** Introspection request /Begin ******")
                command = PACKET_NOT_RECEIVED
                try:
                    timeout = self.timeout if self.auto_refresh else None
                    command = read_packet(self.i_request, timeout=timeout)
                    if command is None:
                        continue
                    timed_out = False
                except socket.timeout:
                    timed_out = True
                except struct.error:
                    # This should mean that Spyder GUI has crashed
                    if DEBUG_MONITOR:
                        logging.debug("struct.error -> quitting monitor")
                    break
                if timed_out:
                    if DEBUG_MONITOR:
                        logging.debug("connection timed out -> updating remote view")
                    self.update_remote_view()
                    if DEBUG_MONITOR:
                        logging.debug("****** Introspection request /End ******")
                    continue
                if DEBUG_MONITOR:
                    logging.debug("command: %r" % command)
                lcls = self.mlocals()
                result = eval(command, glbs, lcls)
                if DEBUG_MONITOR:
                    logging.debug(" result: %r" % result)
                if self.pdb_obj is None:
                    lcls["_"] = result
                # old com implementation: (see solution (1) in Issue 434)
                output = pickle.dumps(result, PICKLE_HIGHEST_PROTOCOL)
            #                # new com implementation: (see solution (2) in Issue 434)
            #                output = pickle.dumps((command, result),
            #                                      PICKLE_HIGHEST_PROTOCOL)
            except SystemExit:
                break
            except:
                if DEBUG_MONITOR:
                    logging.debug("error!")
                log_last_error(LOG_FILENAME, command)
            finally:
                try:
                    if DEBUG_MONITOR:
                        logging.debug("updating remote view")
                    if self.refresh_after_eval:
                        self.update_remote_view()
                        self.refresh_after_eval = False
                    if DEBUG_MONITOR:
                        logging.debug("sending result")
                        logging.debug("****** Introspection request /End ******")
                    if command is not PACKET_NOT_RECEIVED:
                        if write_packet is None:
                            # This may happen during interpreter shutdown
                            break
                        else:
                            write_packet(self.i_request, output, already_pickled=True)
                except AttributeError as error:
                    if "'NoneType' object has no attribute" in str(error):
                        # This may happen during interpreter shutdown
                        break
                    else:
                        raise
                except TypeError as error:
                    if "'NoneType' object is not subscriptable" in str(error):
                        # This may happen during interpreter shutdown
                        break
                    else:
                        raise

        self.i_request.close()
        self.n_request.close()
Ejemplo n.º 19
0
 def setenv(self):
     """Set os.environ"""
     env = read_packet(self.i_request)
     os.environ = env
Ejemplo n.º 20
0
 def run(self):
     """Start notification thread"""
     while True:
         if self.notify_socket is None:
             continue
         output = None
         try:
             try:
                 cdict = read_packet(self.notify_socket)
             except:
                 # This except statement is intended to handle a struct.error
                 # (but when writing 'except struct.error', it doesn't work)
                 # Note: struct.error is raised when the communication has
                 # been interrupted and the received data is not a string
                 # of length 8 as required by struct.unpack (see read_packet)
                 break
             if cdict is None:
                 # Another notification thread has just terminated and
                 # then wrote 'None' in the notification socket
                 # (see the 'finally' statement below)
                 continue
             if not isinstance(cdict, dict):
                 raise TypeError("Invalid data type: %r" % cdict)
             command = cdict['command']
             data = cdict.get('data')
             if command == 'pdb_step':
                 fname, lineno = data
                 self.emit(SIGNAL('pdb(QString,int)'), fname, lineno)
                 self.emit(SIGNAL('refresh_namespace_browser()'))
             elif command == 'refresh':
                 self.emit(SIGNAL('refresh_namespace_browser()'))
             elif command == 'remote_view':
                 self.sig_process_remote_view.emit(data)
             elif command == 'ipykernel':
                 self.emit(SIGNAL('new_ipython_kernel(QString)'), data)
             elif command == 'open_file':
                 fname, lineno = data
                 self.emit(SIGNAL('open_file(QString,int)'), fname, lineno)
             elif command == 'layout':
                 #print('2.3.4 NotificationThread layout')
                 sbml = data
                 if sbml != '~::empty::~':
                     #print('2.3.4 NotificationThread emit layout signal')
                     self.layout.emit(sbml)
                 else:
                     #print('2.3.4 NotificationThread get sbml')
                     if hasattr(self, 'network_viewer_sbml_hook'):
                         output = self.network_viewer_sbml_hook()
                         #print('output = {}'.format(output))
                     #else:
                     #print('no attr network_viewer_sbml_hook')
             else:
                 raise RuntimeError('Unsupported command: %r' % command)
             if DEBUG_INTROSPECTION:
                 logging.debug("received command: %r" % command)
         except:
             log_last_error(LOG_FILENAME, "notification thread")
         finally:
             try:
                 write_packet(self.notify_socket, output)
             except:
                 # The only reason why it should fail is that Spyder is
                 # closing while this thread is still alive
                 break
Ejemplo n.º 21
0
    def run(self):
        self.ipython_shell = None
        while True:
            output = pickle.dumps(None, PICKLE_HIGHEST_PROTOCOL)
            glbs = self.mglobals()
            try:
                if DEBUG_MONITOR:
                    logging.debug("****** Introspection request /Begin ******")
                command = PACKET_NOT_RECEIVED
                try:
                    timeout = self.timeout if self.auto_refresh else None
                    command = read_packet(self.i_request, timeout=timeout)
                    if command is None:
                        continue
                    timed_out = False
                except socket.timeout:
                    timed_out = True
                except struct.error:
                    # This should mean that Spyder GUI has crashed
                    if DEBUG_MONITOR:
                        logging.debug("struct.error -> quitting monitor")
                    break
                if timed_out:
                    if DEBUG_MONITOR:
                        logging.debug(
                            "connection timed out -> updating remote view")
                    self.update_remote_view()
                    if DEBUG_MONITOR:
                        logging.debug(
                            "****** Introspection request /End ******")
                    continue
                if DEBUG_MONITOR:
                    logging.debug("command: %r" % command)
                lcls = self.mlocals()
                result = eval(command, glbs, lcls)
                if DEBUG_MONITOR:
                    logging.debug(" result: %r" % result)
                if self.pdb_obj is None:
                    lcls["_"] = result
                # old com implementation: (see solution (1) in Issue 434)
                output = pickle.dumps(result, PICKLE_HIGHEST_PROTOCOL)
#                # new com implementation: (see solution (2) in Issue 434)
#                output = pickle.dumps((command, result),
#                                      PICKLE_HIGHEST_PROTOCOL)
            except SystemExit:
                break
            except:
                if DEBUG_MONITOR:
                    logging.debug("error!")
                log_last_error(LOG_FILENAME, command)
            finally:
                try:
                    if DEBUG_MONITOR:
                        logging.debug("updating remote view")
                    if self.refresh_after_eval:
                        self.update_remote_view()
                        self.refresh_after_eval = False
                    if DEBUG_MONITOR:
                        logging.debug("sending result")
                        logging.debug(
                            "****** Introspection request /End ******")
                    if command is not PACKET_NOT_RECEIVED:
                        if write_packet is None:
                            # This may happen during interpreter shutdown
                            break
                        else:
                            write_packet(self.i_request,
                                         output,
                                         already_pickled=True)
                except AttributeError as error:
                    if "'NoneType' object has no attribute" in str(error):
                        # This may happen during interpreter shutdown
                        break
                    else:
                        raise
                except TypeError as error:
                    if "'NoneType' object is not subscriptable" in str(error):
                        # This may happen during interpreter shutdown
                        break
                    else:
                        raise

        self.i_request.close()
        self.n_request.close()
Ejemplo n.º 22
0
    def run(self):
        #print('run')
        """Start notification thread"""
        while True:
            #print('SBNWNotificationThread while True')

            # add layout signal if it doesn't already exist
            #if not hasattr(self, 'layout'):

            if self.notify_socket is None:
                continue
            output = None
            try:
                try:
                    cdict = read_packet(self.notify_socket)
                except:
                    # This except statement is intended to handle a struct.error
                    # (but when writing 'except struct.error', it doesn't work)
                    # Note: struct.error is raised when the communication has
                    # been interrupted and the received data is not a string
                    # of length 8 as required by struct.unpack (see read_packet)
                    break
                if cdict is None:
                    # Another notification thread has just terminated and
                    # then wrote 'None' in the notification socket
                    # (see the 'finally' statement below)
                    continue
                if not isinstance(cdict, dict):
                    raise TypeError("Invalid data type: %r" % cdict)
                command = cdict['command']
                data = cdict.get('data')
                if command == 'pdb_step':
                    fname, lineno = data
                    self.sig_pdb.emit(fname, lineno)
                    self.refresh_namespace_browser.emit()
                elif command == 'refresh':
                    self.refresh_namespace_browser.emit()
                elif command == 'remote_view':
                    self.sig_process_remote_view.emit(data)
                elif command == 'ipykernel':
                    self.new_ipython_kernel.emit(data)
                elif command == 'open_file':
                    fname, lineno = data
                    self.open_file.emit(fname, lineno)
                elif command == 'layout':
                    print('SBNWNotificationThread layout')
                    sbml = data
                    if sbml != '~::empty::~':
                      print('SBNWNotificationThread emit layout signal')
                      self.layout.emit(sbml)
                    else:
                      print('SBNWNotificationThread get sbml')
                      if hasattr(self, 'network_viewer_sbml_hook'):
                        output = self.network_viewer_sbml_hook()
                        print('output = {}'.format(output))
                      else:
                        print('no attr network_viewer_sbml_hook')
                else:
                    raise RuntimeError('Unsupported command: %r' % command)
                if DEBUG_INTROSPECTION:
                    logging.debug("received command: %r" % command)
            except:
                log_last_error(LOG_FILENAME, "notification thread")
            finally:
                try:
                    write_packet(self.notify_socket, output)
                except:
                    # The only reason why it should fail is that Spyder is
                    # closing while this thread is still alive
                    break