How to use the pyravendb.subscriptions.data.IncrementalJsonParser function in pyravendb

To help you get started, we’ve selected a few pyravendb examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ravendb / ravendb-python-client / pyravendb / subscriptions / subscription.py View on Github external
self._my_socket.settimeout(30)

        # TODO: wrap SSL
        if self._store.certificate:
            self._my_socket = ssl.wrap_socket(self._my_socket, certfile=self._store.certificate,
                                              ssl_version=ssl.PROTOCOL_TLSv1_2)
        try:
            self._my_socket.connect((host, port))
        except Exception as e:
            print(e)

        header = Utils.dict_to_bytes(
            {"Operation": "Subscription", "DatabaseName": self._database_name, "OperationVersion": 40})
        self._my_socket.sendall(header)

        parser = IncrementalJsonParser(self._my_socket)
        response = parser.next_object()

        if response['Status'] != "Ok":
            if response['Status'] == "AuthorizationFailed":
                raise ConnectionRefusedError(
                    "Cannot access database {0} because {1}".format(self._database_name, response['Message']))
            elif response['Status'] == "TcpVersionMismatch":
                raise InvalidOperationException(
                    "Cannot access database {0} because {1}".format(self._database_name, response['Message']))

        options = Utils.dict_to_bytes(self._options.to_json())
        self._my_socket.sendall(options)

        if self.request_executor:
            self.request_executor.close()
        self.request_executor = RequestsExecutor.create_for_single_node(command.requested_node.url,
github ravendb / ravendb-python-client / pyravendb / subscriptions / data.py View on Github external
def parse_object(lexer):
        yield ('start_map', None)
        try:
            pos, symbol = next(lexer)
            if symbol != '}':
                while True:
                    if symbol[0] != '"':
                        raise ijson.backend.UnexpectedSymbol(symbol, pos)
                    yield ('map_key', IncrementalJsonParser.unescape(symbol[1:-1]))
                    pos, symbol = next(lexer)
                    if symbol != ':':
                        raise ijson.backend.UnexpectedSymbol(symbol, pos)
                    for event in IncrementalJsonParser.parse_value(lexer, None, pos):
                        yield event
                    pos, symbol = next(lexer)
                    if symbol == '}':
                        break
                    if symbol != ',':
                        raise ijson.backend.UnexpectedSymbol(symbol, pos)
                    pos, symbol = next(lexer)
            yield ('end_map', None)
        except StopIteration:
            raise ijson.backend.common.IncompleteJSONError('Incomplete JSON data')
github ravendb / ravendb-python-client / pyravendb / subscriptions / data.py View on Github external
def parse_value(lexer, symbol=None, pos=0):
        try:
            if symbol is None:
                pos, symbol = next(lexer)
            if symbol == 'null':
                yield ('null', None)
            elif symbol == 'true':
                yield ('boolean', True)
            elif symbol == 'false':
                yield ('boolean', False)
            elif symbol == '[':
                for event in IncrementalJsonParser.parse_array(lexer):
                    yield event
            elif symbol == '{':
                for event in IncrementalJsonParser.parse_object(lexer):
                    yield event
            elif symbol[0] == '"':
                yield ('string', IncrementalJsonParser.unescape(symbol[1:-1]))
            else:
                # if we got a partial token for false / null / true we need to read from the network again
                while symbol[0] in ('t', 'n') and len(symbol) < 4 or symbol[0] == 'f' and len(symbol) < 5:
                    _, nextpart = next(lexer)
                    if symbol == 'null':
                        yield ('null', None)
                    elif symbol == 'true':
                        yield ('boolean', True)
                    elif symbol == 'false':
                        yield ('boolean', False)
                    return

                try:
github ravendb / ravendb-python-client / pyravendb / subscriptions / data.py View on Github external
def parse_object(lexer):
        yield ('start_map', None)
        try:
            pos, symbol = next(lexer)
            if symbol != '}':
                while True:
                    if symbol[0] != '"':
                        raise ijson.backend.UnexpectedSymbol(symbol, pos)
                    yield ('map_key', IncrementalJsonParser.unescape(symbol[1:-1]))
                    pos, symbol = next(lexer)
                    if symbol != ':':
                        raise ijson.backend.UnexpectedSymbol(symbol, pos)
                    for event in IncrementalJsonParser.parse_value(lexer, None, pos):
                        yield event
                    pos, symbol = next(lexer)
                    if symbol == '}':
                        break
                    if symbol != ',':
                        raise ijson.backend.UnexpectedSymbol(symbol, pos)
                    pos, symbol = next(lexer)
            yield ('end_map', None)
        except StopIteration:
            raise ijson.backend.common.IncompleteJSONError('Incomplete JSON data')
github ravendb / ravendb-python-client / pyravendb / subscriptions / data.py View on Github external
def parse_value(lexer, symbol=None, pos=0):
        try:
            if symbol is None:
                pos, symbol = next(lexer)
            if symbol == 'null':
                yield ('null', None)
            elif symbol == 'true':
                yield ('boolean', True)
            elif symbol == 'false':
                yield ('boolean', False)
            elif symbol == '[':
                for event in IncrementalJsonParser.parse_array(lexer):
                    yield event
            elif symbol == '{':
                for event in IncrementalJsonParser.parse_object(lexer):
                    yield event
            elif symbol[0] == '"':
                yield ('string', IncrementalJsonParser.unescape(symbol[1:-1]))
            else:
                # if we got a partial token for false / null / true we need to read from the network again
                while symbol[0] in ('t', 'n') and len(symbol) < 4 or symbol[0] == 'f' and len(symbol) < 5:
                    _, nextpart = next(lexer)
                    if symbol == 'null':
                        yield ('null', None)
                    elif symbol == 'true':
                        yield ('boolean', True)
                    elif symbol == 'false':
                        yield ('boolean', False)
github ravendb / ravendb-python-client / pyravendb / changes / database_changes.py View on Github external
def process_changes(self):
        parser = IncrementalJsonParser(self.client_websocket, is_websocket=True)
        while not self._closed:
            try:
                response = parser.next_object()
                if response:
                    response_type = response.get("Type", None)
                    if not response_type:
                        continue
                    if response_type == "Error":
                        exception = response["Exception"]
                        self.notify_about_error(Exception(exception))
                    elif response_type == "Confirm":
                        command_id = response.get("CommandId", None)
                        if command_id and command_id in self._confirmations:
                            with self._confirmations_lock:
                                future = self._confirmations.pop(command_id)
                                future.set_result("done complete future")