예제 #1
0
    def handle_error(self):
        """
python.org: Called when an exception is raised and not otherwise handled.

:since: v0.2.00
        """

        if (self.log_handler is None): TracedException.print_current_stack_trace()
        else: self.log_handler.error(traceback.format_exc(), context = "pas_server")
예제 #2
0
    def handle_read(self):
        """
python.org: Called when the asynchronous loop detects that a "read()" call
on the channel's socket will succeed.

:since: v0.2.00
        """

        # pylint: disable=broad-except

        if ((not self.listener_handle_connections) and self.active):
            try:
                if (self._active_queue(self.listener_socket)): self._active_activate(self.listener_socket)
            except ShutdownException as handled_exception:
                exception = handled_exception.get_cause()

                if (exception is None and self.log_handler is not None): self.log_handler.error(handled_exception, context = "pas_server")
                else: handled_exception.print_stack_trace()
            except Exception as handled_exception:
                if (self.log_handler is None): TracedException.print_current_stack_trace()
                else: self.log_handler.error(handled_exception, context = "pas_server")
예제 #3
0
    def run(self):
        """
Run the main loop for this server instance.

:since: v0.2.00
        """

        # pylint: disable=broad-except

        if (self.log_handler is not None): self.log_handler.debug("#echo(__FILEPATH__)# -{0!r}.run()- (#echo(__LINE__)#)", self, context = "pas_server")

        self._ensure_thread_local()

        try:
            if (not self.active):
                with self._lock:
                    # Thread safety
                    if (not self.active):
                        self.active = True
                        self._init()
                    #
                #
            #

            if (self.listener_handle_connections): self._start_listening()

            self.add_channel(self.local.sockets)
            asyncore.loop(5, map = self.local.sockets)
        except ShutdownException as handled_exception:
            if (self.active):
                exception = handled_exception.get_cause()
                if (exception is not None and self.log_handler is not None): self.log_handler.error(exception, context = "pas_server")
            #
        except Exception as handled_exception:
            if (self.active):
                if (self.log_handler is None): TracedException.print_current_stack_trace()
                else: self.log_handler.error(handled_exception, context = "pas_server")
            #
        finally: self.stop()
예제 #4
0
    def handle_accepted(self, sock, addr):
        """
python.org: Called on listening channels (passive openers) when a connection
has been established with a new remote endpoint that has issued a connect()
call for the local endpoint.

:since: v0.2.00
        """

        # pylint: disable=broad-except

        if (self.active and self.listener_handle_connections):
            try:
                if (self._active_queue(sock)): self._active_activate(sock)
            except ShutdownException as handled_exception:
                exception = handled_exception.get_cause()

                if (exception is None and self.log_handler is not None): self.log_handler.error(handled_exception, context = "pas_server")
                else: handled_exception.print_stack_trace()
            except Exception as handled_exception:
                if (self.log_handler is None): TracedException.print_current_stack_trace()
                else: self.log_handler.error(handled_exception, context = "pas_server")
예제 #5
0
    def handle_accept(self):
        """
python.org: Called on listening channels (passive openers) when a connection
can be established with a new remote endpoint that has issued a connect()
call for the local endpoint.

Deprecated since version 3.2.

:since: v0.2.00
        """

        # pylint: disable=broad-except

        if (self.active and self.listener_handle_connections):
            socket_data = None

            try: socket_data = self.accept()
            except Exception as handled_exception:
                if (self.log_handler is None): TracedException.print_current_stack_trace()
                else: self.log_handler.error(handled_exception, context = "pas_server")
            #

            if (socket_data is not None): self.handle_accepted(socket_data[0], socket_data[1])