(self, eio_sid, namespace, data)
Handle a client connection request.
Handle a client connection request.
Handle a client connection request .
def _handle_connect(self, eio_sid, namespace, data):
        """Handle a client connection request."""
        namespace = namespace or '/'
        sid = self.manager.connect(eio_sid, namespace)
        if sid is None:
            self._send_packet(eio_sid, self.packet_class(
                packet.CONNECT_ERROR, data='Unable to connect',
                namespace=namespace))
            return

        if self.always_connect:
            self._send_packet(eio_sid, self.packet_class(
                packet.CONNECT, {'sid': sid}, namespace=namespace))
        fail_reason = exceptions.ConnectionRefusedError().error_args
        try:
            if data:
                success = self._trigger_event(
                    'connect', namespace, sid, self.environ[eio_sid], data)
            else:
                try:
                    success = self._trigger_event(
                        'connect', namespace, sid, self.environ[eio_sid])
                except TypeError:
                    success = self._trigger_event(
                        'connect', namespace, sid, self.environ[eio_sid], None)
        except exceptions.ConnectionRefusedError as exc:
            fail_reason = exc.error_args
            success = False

        if success is False:
            if self.always_connect:
                self.manager.pre_disconnect(sid, namespace)
                self._send_packet(eio_sid, self.packet_class(
                    packet.DISCONNECT, data=fail_reason, namespace=namespace))
            else:
                self._send_packet(eio_sid, self.packet_class(
                    packet.CONNECT_ERROR, data=fail_reason,
                    namespace=namespace))
            self.manager.disconnect(sid, namespace)
        elif not self.always_connect:
            self._send_packet(eio_sid, self.packet_class(
                packet.CONNECT, {'sid': sid}, namespace=namespace))
def _handle_connect ( self , eio_sid , namespace , data ) : namespace = namespace or '/' sid = self . manager . connect ( eio_sid , namespace ) if sid is None : self . _send_packet ( eio_sid , self . packet_class ( packet . CONNECT_ERROR , data = 'Unable to connect' , namespace = namespace ) ) return if self . always_connect : self . _send_packet ( eio_sid , self . packet_class ( packet . CONNECT , { 'sid' : sid } , namespace = namespace ) ) fail_reason = exceptions . ConnectionRefusedError ( ) . error_args try : if data : success = self . _trigger_event ( 'connect' , namespace , sid , self . environ [ eio_sid ] , data ) else : try : success = self . _trigger_event ( 'connect' , namespace , sid , self . environ [ eio_sid ] ) except TypeError : success = self . _trigger_event ( 'connect' , namespace , sid , self . environ [ eio_sid ] , None ) except exceptions . ConnectionRefusedError as exc : fail_reason = exc . error_args success = False if success is False : if self . always_connect : self . manager . pre_disconnect ( sid , namespace ) self . _send_packet ( eio_sid , self . packet_class ( packet . DISCONNECT , data = fail_reason , namespace = namespace ) ) else : self . _send_packet ( eio_sid , self . packet_class ( packet . CONNECT_ERROR , data = fail_reason , namespace = namespace ) ) self . manager . disconnect ( sid , namespace ) elif not self . always_connect : self . _send_packet ( eio_sid , self . packet_class ( packet . CONNECT , { 'sid' : sid } , namespace = namespace ) )