def setrequesturlorcookie_newvalue(self, param, method="w", text="", urlencode=True, source="url"): ''' param : accpept dict method : accept a w . a:append ,w:write text: accept bytes and str urlencode: bool source :accept url and cookie return dict ''' if isinstance(text, bytes): text = text.decode() if source == "url": params = self.getrequestparams_urlorcookie("url") else: params = self.getrequestparams_urlorcookie("cookie") if not params: return {} else: value = verify_param(param, text, method, self.getrequestbody(), self.request_bodyoffset) newparams_url = copy.deepcopy(params) newparams_url[param.get("name")] = value return newparams_url
def getreqfromparam(self, param, method="w", text=""): ''' param : accpept dict method : accept a w . a:append ,w:write text: accept str source :accept url and cookie return req ''' if param.get("type") == 0: #url参数 params_or_data = self.getrequestparams_urlorcookie("url") elif param.get("type") == 2: #cookie参数 params_or_data = self.getrequestparams_urlorcookie("cookie") else: params_or_data = self.getrequestbody() value = verify_param(param, text, method, self.getrequestbody(), self.request_bodyoffset) if param.get("type") == 2: newparams_url = copy.deepcopy(params_or_data) newparams_url[param.get("name")] = value return self.generaterequest({"cookies": newparams_url}) if param.get("type") == 0: newparams_url = copy.deepcopy(params_or_data) newparams_url[param.get("name")] = value return self.generaterequest({"params": newparams_url}) else: st = param.get("valuestart") - self.request_bodyoffset et = param.get("valueend") - self.request_bodyoffset bodyarray = bytearray(params_or_data) bodyarray[st:et] = value.encode() return self.generaterequest({"data": bodyarray})
def setrequestbody_newvalue(self, param, method="w", text="", urlencode=True): ''' param : accpept dict method : accept a w . a:append ,w:write text: accept bytes and str urlencode: bool setvalue: bool ,setkey or value return bytearray ''' if isinstance(text, str): text = text.encode() body = self.getrequestbody() if not body: return body else: value = verify_param(param, text, method, body, self.request_bodyoffset).encode() st = param.get("valuestart") - self.request_bodyoffset et = param.get("valueend") - self.request_bodyoffset bodyarray = bytearray(body) bodyarray[st:et] = value return bodyarray