def parse_line():
        if len(line_lst) not in (2, 3, 4, 5):
            raise mpp_exceptions.SyntaxError(line, line_number,
                                             "Неверное число параметров.")
        if len(line_lst) == 5:
            doc_name, url, width, height = line_lst[1:]
        elif len(line_lst) == 4:
            doc_name = "docx_document__default__"
            url, width, height = line_lst[1:]
        elif len(line_lst) == 3:
            doc_name, url = line_lst[1:]
            width, height = None, None
        else:
            doc_name, url = "docx_document__default__", line_lst[1]
            width, height = None, None

        if doc_name not in env:
            raise mpp_exceptions.UnknownVar(line, line_number, doc_name)

        if len(url) < 4 or url[:4] != "http":
            url = handle_text(line, line_number,
                              f'"{url}->get_attribute(\'src\')"', env)
        try:
            if not width is None:
                width, height = float(width), float(height)
            return doc_name, url, width, height
        except:
            raise mpp_exceptions.SyntaxError(
                line, line_number, "Некорректные параметры width и height.")
 def is_for_type(line, line_number):
     if line[:3] != "for":
         return False
     line_lst = line.split()
     if len(line_lst) != 4:
         raise mpp_exceptions.SyntaxError(
             line, line_number,
             "Неверное количество параметров в цикле for.")
     if line_lst[2] != "in":
         raise mpp_exceptions.SyntaxError(
             line, line_number, "Отсутствует параметр 'in' в цикле for.")
     return True
 def get_names():
     if len(line_lst) == 3:
         var_name, doc_name = line_lst[1], line_lst[2]
         if var_name in env:
             raise mpp_exceptions.DoubleVarUse(line, line_number)
     elif len(line_lst) == 2:
         var_name, doc_name = "docx_document__default__", line_lst[1]
     else:
         raise mpp_exceptions.SyntaxError(line, line_number,
                                          "Неверное число параметров.")
     if len(doc_name) < 6 or doc_name[-5:] != ".docx":
         raise mpp_exceptions.SyntaxError(line, line_number,
                                          "Неверное название файла docx")
     return var_name, doc_name
def com_save(line_lst, line, line_number, env):
    if len(line_lst) not in (1, 2):
        raise mpp_exceptions.SyntaxError(line, line_number,
                                         "Неверное число параметров.")
    if len(line_lst) == 2:
        doc_name = line_lst[1]
    else:
        doc_name = "docx_document__default__"
    if doc_name not in env:
        raise mpp_exceptions.UnknownVar(line, line_number, doc_name)
    env[doc_name][0].save(env[doc_name][1])
def com_load(line_lst, line, line_number, env):
    if len(line_lst) not in (2, 3):
        raise mpp_exceptions.SyntaxError(line, line_number,
                                         "Неверное число параметров.")
    if len(line_lst) == 3:
        driver_name, url = line_lst[1:]
    else:
        driver_name, url = "driver__default__", line_lst[1]

    if driver_name not in env or env[driver_name] is None:
        env[driver_name] = webdriver.Chrome()
    env[driver_name].get(url)
def com_add_A4(line_lst, line, line_number, env):
    if len(line_lst) > 2:
        raise mpp_exceptions.SyntaxError(line, line_number,
                                         "Неверное число параметров.")
    if len(line_lst) == 2:
        doc_name = line_lst[1]
        if doc_name not in env:
            raise mpp_exceptions.UnknownVar(line, line_number, doc_name)
    else:
        doc_name = "docx_document__default__"
    if env[doc_name][0] is None:
        raise mpp_exceptions.UseUnitiailizeVar(line, line_number, doc_name)

    env[doc_name][0].add_page_break()
def com_add_head(line_lst, line, line_number, env):
    if len(line_lst) < 3:
        raise mpp_exceptions.SyntaxError(line, line_number,
                                         "Неверное число параметров.")

    if len(line_lst) >= 4 and line_lst[2][0] == '"':
        doc_name, text, level = line_lst[1], " ".join(
            line_lst[2:-1]), line_lst[-1]
    else:
        doc_name, text, level = "docx_document__default__", " ".join(
            line_lst[1:-1]), line_lst[-1]

    if doc_name not in env:
        raise mpp_exceptions.UnknownVar(line, line_number, doc_name)
    try:
        level = int(level)
        if not (level >= 0 and level <= 9):
            raise ""
    except:
        raise mpp_exceptions.SyntaxError(
            line, line_number, "Некорректный параметр уровня level.")

    text = handle_text(line, line_number, text, env)
    env[doc_name][0].add_heading(text, level=level)
def com_add_paragraph(line_lst, line, line_number, env):
    if len(line_lst) < 2:
        raise mpp_exceptions.SyntaxError(line, line_number,
                                         "Неверное число параметров.")

    if len(line_lst) >= 3 and line_lst[2][0] == '"':
        doc_name, text = line_lst[1], " ".join(line_lst[2:])
    else:
        doc_name, text = "docx_document__default__", " ".join(line_lst[1:])

    if doc_name not in env:
        raise mpp_exceptions.UnknownVar(line, line_number, doc_name)

    text = handle_text(line, line_number, text, env)
    env[doc_name][0].add_paragraph(text)
 def parse_for_expr():
     line_list = line.split()
     var_name = line_list[1]
     if var_name in env:
         raise mpp_exceptions.DoubleVarUse(line, line_number)
     lst = line_list[3].strip().split("->")
     if len(lst) == 1:
         driver = "driver__default__"
         xpath = lst[0]
     elif len(lst) == 2:
         driver = lst[0]
         if driver not in env:
             raise mpp_exceptions.DriverNotFound(line, line_number)
         xpath = lst[1]
     else:
         raise mpp_exceptions.SyntaxError(line, line_number)
     return var_name, driver, xpath
Esempio n. 10
0
    def get_varname_driver_rel_path():
        if len(line_lst) < 3:
            raise mpp_exceptions.SyntaxError(line, line_number,
                                             "Неверное число параметров.")
        if len(line_lst) >= 4:
            if line_lst[2][0] != '/':
                var_name, driver, rel_path = line_lst[1:]
            else:
                var_name = line_lst[1]
                driver = "driver__default__"
                rel_path = " ".join(line_lst[2:])
        else:
            var_name, rel_path = line_lst[1:]
            driver = "driver__default__"

        if driver not in env:
            raise mpp_exceptions.UnknownVar(line, line_number, driver)
        return var_name, driver, rel_path
Esempio n. 11
0
def com_get(line_lst, line, line_number, env):
    def get_varname_driver_rel_path():
        if len(line_lst) < 3:
            raise mpp_exceptions.SyntaxError(line, line_number,
                                             "Неверное число параметров.")
        if len(line_lst) >= 4:
            if line_lst[2][0] != '/':
                var_name, driver, rel_path = line_lst[1:]
            else:
                var_name = line_lst[1]
                driver = "driver__default__"
                rel_path = " ".join(line_lst[2:])
        else:
            var_name, rel_path = line_lst[1:]
            driver = "driver__default__"

        if driver not in env:
            raise mpp_exceptions.UnknownVar(line, line_number, driver)
        return var_name, driver, rel_path

    var_name, driver, rel_path = get_varname_driver_rel_path()

    tokens = rel_path.split('->')
    if len(tokens) > 2:
        raise mpp_exceptions.SyntaxError(
            line, line_number,
            "Неверно задан параметр relative-xpath(количество символов '->' больше 1)"
        )
    if len(tokens) == 2:
        var, xpath = tokens
        if var not in env:
            raise mpp_exceptions.UnknownVar(line, line_number, var)
        tmp = env[var].find_elements_by_xpath(xpath)
    else:
        xpath = tokens[0]
        tmp = env[driver].find_elements_by_xpath(xpath)
    if len(tmp) == 0:
        raise mpp_exceptions.RuntimeError(
            line, line_number,
            "Количество найденных элементов в относительном xpath = 0")

    env[var_name] = tmp[0]