Exemplo n.º 1
0
    def change_para_html(self, html_cont, data):
        if data == "":
            return html_cont

        replace_data = self.html_replace_data(data)
        for data in replace_data:
            if "=" not in data:
                raise Exception("error format,not found =")
            try:
                if ":=" not in data:
                    raise Exception("error format")
                sval = get_var(data.split(":=")[1])
                name = data.split(":=")[0]
                # 对参数做num,str区分 数字:222222, str:'222222'
                if "," in sval:
                    sval = sval.split(",")
                if sval != "" and isinstance(sval, str):
                    if Core.is_numeric(sval):
                        sval = int(sval)
                    elif "\'" in sval:
                        sval = sval.replace("\'", "")
                    elif sval.startswith("[") or sval.startswith("{"):
                        sval = Core.eval_str(sval)
                # 对入参类型为bool, null的处理
                if sval == 'false':
                    sval = False
                elif sval == 'true':
                    sval = True
                elif sval == 'null' or sval == "":
                    sval = None
                scmd = '''html_cont[%s]="%s" ''' % (name, sval)
                html_cont[name] = sval
            except Exception, e:
                raise Exception("error after %s, %s" % (scmd, str(e)))
Exemplo n.º 2
0
    def change_para_json(self, json_cont, data):
        if data == "":
            return json_cont
        # try:
        #     t_js = json.loads(data)
        #     for ixe in t_js.keys():
        #         t_ixv = t_js.get(ixe)
        #         if isinstance(t_ixv, (basestring, dict, list)):
        #             t_ixv = get_var(t_ixv)
        #         json_cont[ixe] = t_ixv
        #     return json_cont
        # except:
        replace_data = self.json_replace_data(data)

        for data in replace_data:
            if "=" not in data:
                raise Exception("error format,not found =")
            try:
                if ":=" not in data:
                    raise Exception("error format")
                sval = get_var(data.split(":=")[1])
                name = data.split(":=")[0]
                # sval = sval.replace("'", "\"")
                # 对参数做num,str区分 数字:222222, str:'222222'
                if sval != "":
                    if sval.startswith("'") and sval.endswith("'"):
                        sval = str(sval[1:-1])
                    elif Core.is_numeric(sval):
                        if "." in sval:
                            sval = float(sval)
                        else:
                            sval = int(sval)
                    # 支持替换成空list或dict: a=[]; a={}
                    elif sval.startswith("[") or sval.startswith("{"):
                        # elif sval.replace(" ", "") == "[]" or sval.replace(" ", "") == "{}":
                        sval = Core.eval_str(sval)
                # 嵌套json替换
                obj = ""
                for i in name.split("."):
                    if Core.is_numeric(i):
                        obj = "%s[%s]" % (obj, i)
                    else:
                        obj = "%s['%s']" % (obj, i)
                # 对值为为bool, null的处理
                if sval == 'false':
                    sval = False
                elif sval == 'true':
                    sval = True
                elif sval == 'null' or sval == "":  # 若需要传  {"A":null}  则可以用默认参数或者 A:=null  或者 A:=
                    sval = None
                elif sval == "\"\"":  # 若需要传  {"A":""}  则替换值时需这样处理  A:=\"\"
                    sval = ""  # 字符串处理
                scmd = "%s%s = sval" % ("json_cont", obj)
                exec scmd
            except Exception, e:
                raise Exception("error occur %s" % scmd)
Exemplo n.º 3
0
def change_para_soup(soup, data):
    if data == "":
        return soup

    replace_data = xml_replace_data(data)
    for data in replace_data:
        if "=" not in data:
            raise Exception("error format,not found =")
        try:
            if ":=" not in data:
                raise Exception("error format")
            # sval = data.split(":=")[1]
            sval = get_var(data.split(":=")[1])
            name = sname = data.split(":=")[0]
            sflag = 0
            if "." in sname:
                name = sname.split(".")[0]
                sflag = sname.split(".")[1]
            scmd = '''soup.find_all("%s")[%s].string="%s" ''' % (name, sflag,
                                                                 sval)
            exec scmd
        except Exception, e:
            raise Exception("error cmd,%s" % scmd)
Exemplo n.º 4
0
def rh_soup_check_result(input, soup):
    data = str(input).strip().replace("\n", "").replace("”", "\"").replace(
        "‘", "\'").replace("’", "\'").replace(";", ";")
    if data == "":
        return "[success]"
    if ":=" not in data:
        raise Exception("error format,not found :=")

    svalue = get_var(data.split(":=")[1])
    name = sname = data.split(":=")[0]
    sflag = 0
    realval = ""
    if "." in sname:
        name = sname.split(".")[0]
        sflag = sname.split(".")[1]
    scmd = '''realval = soup.find_all("%s")[%s].string ''' % (name, sflag)
    try:
        exec(scmd)
    except:
        return "[Failed]:cmd change error,%s" % scmd
    svalue = str(svalue).decode("utf-8")
    realval = str(realval).decode("utf-8")
    if str(svalue).strip() == str(realval).strip():
        pass
    elif svalue == "不为空":
        if realval == "{}" or realval == "[]":
            return "[Failed]:%s expect is %s,real is %s." % (sname, svalue,
                                                             realval)
        else:
            return "[success]:%s expect is %s,real is %s." % (sname, svalue,
                                                              realval)
    elif svalue == "不为0":
        if realval == "0":
            return "[Failed]:%s expect is %s,real is %s." % (sname, svalue,
                                                             realval)
        else:
            return "[success]:%s expect is %s,real is %s." % (sname, svalue,
                                                              realval)
    elif svalue == "为空":
        if realval == "{}" or realval == "[]" or realval == '':
            return "[success]:%s expect is %s,real is %s." % (sname, svalue,
                                                              realval)
        else:
            return "[Failed]:%s expect is %s,real is %s." % (sname, svalue,
                                                             realval)
    elif svalue == "为0":
        if realval == "0":
            return "[success]:%s expect is %s,real is %s." % (sname, svalue,
                                                              realval)
        else:
            return "[Failed]:%s expect is %s,real is %s." % (sname, svalue,
                                                             realval)
    elif "<INCLUDE>" in svalue:
        svalue = svalue.split("<")[0]
        if str(svalue) in realval:
            return "[success]:%s expect is %s,real is %s." % (sname, svalue,
                                                              realval)
        else:
            return "[Failed]:%s expect is %s,real is %s." % (sname, svalue,
                                                             realval)
    elif "<EXCEPT>" in svalue:
        svalue = svalue.split("<")[0]
        if str(svalue) in realval:
            return "[Failed]:%s expect is %s,real is %s." % (sname, svalue,
                                                             realval)
        else:
            return "[success]:%s expect is %s,real is %s." % (sname, svalue,
                                                              realval)

    elif ".00" in str(realval):
        if str(svalue) == str(realval[:-3]):
            pass
        else:
            return "[Failed]:%s expect is %s,real is %s." % (sname, svalue,
                                                             realval)
    elif str(realval) == '0.0':
        if str(svalue) in ["0.0", "0.00"]:
            pass
        else:
            return "[Failed]:%s expect is %s,real is %s." % (sname, svalue,
                                                             realval)
    elif str(svalue) == "null":
        if realval == None:
            pass
        else:
            return "[Failed]:%s expect is %s,real is %s." % (sname, svalue,
                                                             realval)
    else:
        if str(svalue) == "" and (realval == "[]" or realval == "{}"):
            pass
        else:
            return "[Failed]:%s expect is %s,real is %s." % (sname, svalue,
                                                             realval)
    return "[success]:%s expect is %s,real is %s." % (sname, svalue, realval)