コード例 #1
0
    def handle_close(self, header, payload):
        """
        Called when a close frame has been decoded from the stream.

        :param header: The decoded `Header`.
        :param payload: The bytestring payload associated with the close frame.
        """
        if not payload:
            self.close(1000, None)
            return
        if len(payload) < 2:
            raise WebSocketError('Invalid close frame: {0} {1}'.format(
                header, payload))
        rv = payload[:2]
        if six.PY2:
            code = struct.unpack('!H', str(rv))[0]
        else:
            code = struct.unpack('!H', bytes(rv))[0]
        payload = payload[2:]
        if payload:
            validator = Utf8Validator()
            val = validator.validate(payload)
            if not val[0]:
                raise UnicodeError
        if not self._is_valid_close_code(code):
            raise WebSocketError('Invalid close code {0}'.format(code))
        self.close(code, payload)
コード例 #2
0
 def __init__(self, wsgi_input):
     self._closed = False
     self.stream = Stream(wsgi_input)
     self.utf8validator = Utf8Validator()
コード例 #3
0
 def __init__(self, wsgi_input):
     self._closed = False
     self.stream = Stream(wsgi_input)
     self.utf8validator = Utf8Validator()
     self.utf8validate_last = None
     self.filter = {}