Spaces Data

Minimal test - lines (868, 929)

path: .spaces[15].spaces[15].metrics.loc.sloc
old: 60.0
new: 62.0

path: .spaces[15].spaces[15].metrics.loc.cloc
old: 26.0
new: 28.0

path: .spaces[15].spaces[15].metrics.mi.mi_sei
old: 67.09259615173966
new: 66.87378087104976

path: .spaces[15].spaces[15].metrics.mi.mi_original
old: 68.67228217748936
new: 68.1410870477569

path: .spaces[15].spaces[15].metrics.mi.mi_visual_studio
old: 40.15922934356103
new: 39.8485889168169

Code

    def close_connection(self,
                         code=common.STATUS_NORMAL_CLOSURE,
                         reason='',
                         wait_response=True):
        """Closes a WebSocket connection. Note that this method blocks until
        it receives acknowledgement to the closing handshake.

        Args:
            code: Status code for close frame. If code is None, a close
                frame with empty body will be sent.
            reason: string representing close reason.
            wait_response: True when caller want to wait the response.
        Raises:
            BadOperationException: when reason is specified with code None
            or reason is not an instance of both str and unicode.
        """

        if self._request.server_terminated:
            self._logger.debug(
                'Requested close_connection but server is already terminated')
            return

        # When we receive a close frame, we call _process_close_message().
        # _process_close_message() immediately acknowledges to the
        # server-initiated closing handshake and sets server_terminated to
        # True. So, here we can assume that we haven't received any close
        # frame. We're initiating a closing handshake.

        if code is None:
            if reason is not None and len(reason) > 0:
                raise BadOperationException(
                    'close reason must not be specified if code is None')
            reason = ''
        else:
            if not isinstance(reason, bytes) and not isinstance(
                    reason, six.text_type):
                raise BadOperationException(
                    'close reason must be an instance of bytes or unicode')

        self._send_closing_handshake(code, reason)
        self._logger.debug('Initiated closing handshake (code=%r, reason=%r)',
                           code, reason)

        if (code == common.STATUS_GOING_AWAY
                or code == common.STATUS_PROTOCOL_ERROR) or not wait_response:
            # It doesn't make sense to wait for a close frame if the reason is
            # protocol error or that the server is going away. For some of
            # other reasons, it might not make sense to wait for a close frame,
            # but it's not clear, yet.
            return

        # TODO(ukai): 2. wait until the /client terminated/ flag has been set,
        # or until a server-defined timeout expires.
        #
        # For now, we expect receiving closing handshake right after sending
        # out closing handshake.
        message = self.receive_message()
        if message is not None:
            raise ConnectionTerminatedException(
                'Didn\'t receive valid ack for closing handshake')
        # TODO: 3. close the WebSocket connection.
        # note: mod_python Connection (mp_conn) doesn't have close method.