Esempio n. 1
0
    def _compile_error_catcher(self, node):
        if node.etype == 'missing':
            self._compile_missing_catcher_header(node)
        elif node.etype == 'failed':
            self._compile_failed_catcher_header(node)
        elif node.etype == 'generated':
            self._compile_generated_catcher_header(node)

        self._write("def _error_{}_(self, e):".format(self.errors))
        self._indent()
        if node.etype == 'generated':
            self._write(
                "return RaisedError('{}'.replace('%!', e.e_trigger), e.pos, e.ctx)"
                .format(
                    replaces(escape_quotes(node.msg), '{', '<LCB>', '}',
                             '<RCB>')))

        else:
            self._write("return RaisedError('{}', e.pos, e.ctx)".format(
                replaces(escape_quotes(node.msg), '{', '<LCB>', '}', '<RCB>')))

        self._dedent()

        self._skip_line(1)
        self.errors += 1
Esempio n. 2
0
def do_insert(host, port, total_request, interval, index_name, args, starting_number=0):
    file_name_key = 'fileName'
    logging.info("Starting Insert")

    for i in range(total_request):

        new_index_name = index_name + str(starting_number)
        starting_number += 1

        add_dict = {'url': "Test URL", file_name_key: new_index_name, 'fileSize': 1, 'language': 'English',
                    'category': 'Video', 'description': 'Test Desc'}
        args_dict = {}

        if args is not None:
            args_dict = json.loads(utils.escape_quotes(args))

        body_dict = dict(add_dict.items() + args_dict.items())

        logging.info("Inserting %s", body_dict[file_name_key])

        result = webservice.call(host, port, "PUT", "/add", body_dict)

        status = utils.get_webservice_call_result(result)

        if status[0]:
            logging.info("Returned data: %s", result)
        else:
            logging.info("FAILED with reason: %s", status[1])

        # don't sleep for the last iteration. All calls have been completed.
        if i != (total_request - 1):
            time.sleep(interval)

    logging.info("Ending Insert")
Esempio n. 3
0
    def _parse_init_or_end_block_part(self):

        imbrication_add = 0

        if self._cur().name == 'LBlock':
            imbrication_add = 1
        elif self._cur().name == 'RBlock':
            imbrication_add = -1

        if (self._cur().name, self._cur().value) == ('keyword', 'node'):
            return self._parse_node_keyword(), imbrication_add

        if self._cur().name == 'silcrow':
            name = self._tok(expected='ident').value
            self._tok()
            return GlobalVar(name, self._pos()), 0

        elif self._cur().name == 'newline':
            indentation = self._cur().value
            self._tok()
            return NewLine(self._pos(), indentation), 0

        elif self._cur().name == 'string':
            code = "'" + escape_quotes(self._cur().value) + "'"

        else:
            code = self._cur().value.strip()

        self._tok()
        return RawPythonCode(code, self._pos()), imbrication_add
Esempio n. 4
0
    def _parse_inspection_code_part(self):
        imbrication_add = 0

        if (self._cur().name, self._cur().value) == ('keyword', 'node'):
            return imbrication_add, self._parse_node_keyword()

        elif (self._cur().name, self._cur().value) == ('keyword', 'it'):
            pos = self._pos()
            self._tok()
            return imbrication_add, RawPythonCode("ast.get()", pos)

        elif self._cur().name == 'newline':
            indentation = self._cur().value
            self._tok()
            return imbrication_add, NewLine(self._pos(), indentation)

        elif self._cur().name == 'silcrow':
            name = self._tok(expected='ident').value
            self._tok()
            return imbrication_add, GlobalVar(name, self._pos())

        else:
            if self._cur().name == 'LBlock':
                imbrication_add = 1
            if self._cur().name == 'RBlock':
                imbrication_add = -1

            if self._cur().name == 'string':
                raw_code = "'" + escape_quotes(self._cur().value) + "'"
            else:
                raw_code = self._cur().value
            self._tok()

            return imbrication_add, RawPythonCode(raw_code, self._pos())
Esempio n. 5
0
def do_search(host, port, total_request, interval, index_name, args, append_number_to_index_name=True):
    file_name_key = 'fileNamePattern'

    logging.info("Starting Search")

    for i in range(total_request):

        new_index_name = index_name
        if append_number_to_index_name:
            new_index_name += str(i)

        name_dict = {file_name_key: new_index_name, 'category': 'Video'}
        args_dict = {}

        if args is not None:
            args_dict = json.loads(utils.escape_quotes(args))

        body_dict = dict(name_dict.items() + args_dict.items())

        logging.info("Searching %s", body_dict[file_name_key])

        result = webservice.call(host, port, "PUT", "/search", body_dict)

        status = utils.get_webservice_call_result(result)

        if status[0]:
            logging.info("%d items Returned: %s", len(result), result)
        else:
            logging.info("FAILED with reason: %s", status[1])

        # don't sleep for the last iteration. All calls have been completed.
        if i != (total_request - 1):
            time.sleep(interval)

    logging.info("Ending Search")
Esempio n. 6
0
    def _compile_warning_catcher(self, node):
        self._write("@warning('{}', {})".format(node.ctx_rule, node.nb))
        self._write("def _warning_{}_(self, w):".format(self.warnings))
        self._indent()
        self._write(
            "return 'Warning : At <LCB><RCB> : {}'.format(w.pos)".format(
                replaces(escape_quotes(node.msg), '{', '<LCB>', '}', '<RCB>')))
        self._dedent()

        self._skip_line(1)
        self.warnings += 1
Esempio n. 7
0
    def _compile_warning_trigger(self, node):
        if node.group_name is None:
            group_name = 'None'
        else:
            group_name = "'" + escape_quotes(node.group_name) + "'"

        self._write("with self._error_trigger({}, group_name={}, warn=True):".format(node.nb, group_name))
        self._indent()
        for subnode in node.link.definition:
            self._compile_node(subnode)
        self._dedent()
Esempio n. 8
0
    def _compile_error_trigger(self, node):
        if node.group_name is None:
            group_name = 'None'
        else:
            group_name = "'" + escape_quotes(node.group_name) + "'"

        self._write("with self._error_trigger({}, group_name={}, warn=False):".format(node.nb, group_name))
        self._indent()
        self._compile_node(node.link)
        self._dedent()
        self._skip_line(1)
Esempio n. 9
0
    def _find_recursion_guards(self, node, base_rule=None):
        self._checker.code.ast = self._ast

        if type(node) is RuleDefinition:
            definition = get_rule(Code(self._ast), node.whole_name).definition
            guards = None
            i = 1
            while not guards == '{!ARR}' and not guards and i <= len(definition):
                guards = self._find_recursion_guards(definition[-i], base_rule=node.whole_name if not base_rule else base_rule)
                i += 1
            if guards != '{!ARR}':
                return guards
            else:
                return ""

        elif type(node) is Match:
            return escape_quotes(node.string)

        elif type(node) is RegexMatch:
            return 'REGEX~' + node.regex

        elif type(node) is Choices:
            guards = []
            for option in node.options:
                for subnode in option.definition:
                    option_guards = self._find_recursion_guards(subnode, base_rule=base_rule)
                    if type(option_guards) is list:
                        guards += option_guards
                    elif type(option_guards) is str and option_guards != '{!ARR}':
                        guards.append(option_guards)
            return guards

        elif type(node) is RuleCall:
            # If there is left recursives calls, it means this rule'll need recursions guards and cannot be used
            # To set recursions guards for the father rule.
            left_calls = self._checker.left_calls(get_rule(Code(self._ast), node.whole_name))
            if not common(left_calls, self._calls_loops[node.whole_name]) and base_rule not in self._calls_loops[node.whole_name]:
                # Use this recursions guards.
                return self._find_recursion_guards(get_rule(Code(self._ast), node.whole_name))
            else:
                return '{!ARR}'  # Already Recursive Rulecall.
Esempio n. 10
0
 def _compile_group(self, node):
     self._write("with self._group(name='{}'):".format(escape_quotes(node.group_name)))
     self._indent()
     for subnode in node.definition:
         self._compile_node(subnode)
     self._dedent()
Esempio n. 11
0
 def _compile_regex_match(self, node):
     self._write("self._regex_match('{}'".format(escape_quotes(node.regex)).replace('{', '<LCB>').replace('}', '<RCB>')+(", name='"+node.group_name+"')" if node.group_name else ')'))
Esempio n. 12
0
 def _compile_string_match(self, node):
     self._write(("self._match('{}'".format(escape_quotes(node.string)).replace('{', '<LCB>').replace('}', '<RCB>')+(", name='"+node.group_name+"')" if node.group_name else ")"))
                 )