예제 #1
0
    def convertUrlParamToJson(self, urlParam, tupeKey="goodsList"):
        pjson = {}
        params = parseRequestParam(urlParam)
        for k in params:
            v = params[k]
            tjson = pjson
            try:
                i = k.index("[")
                key, k = k[0:i], k[i + 1:]
            except:
                pjson[k] = v
                continue

            keys = [key] + k.replace("][", ",").replace("[", "").replace(
                "]", "").split(",")
            for i in range(len(keys)):
                key = keys[i]
                if i < len(keys) - 1:
                    try:
                        tjson = tjson[key]
                    except:
                        if type(tjson) == list:
                            key = int(key)
                            while len(tjson) <= key:
                                tjson.append({})
                            tjson = tjson[key]
                        else:
                            tjson[key] = [] if tupeKey.__contains__(
                                key) else {}
                            tjson = tjson[key]
                else:
                    tjson[key] = v
        return pjson
예제 #2
0
 def addUrlMock(self, url, param, resp, isdelete='false'):
     if self.urlmockdata is None: self.urlmockdata = {}
     if isdelete == "true":
         try:
             self.urlmockdata.__delitem__(url)
         except:
             pass
     else:
         self.urlmockdata[url] = {'p': parseRequestParam(param), 'd': resp}
     return self.urlmockdata.keys()
예제 #3
0
파일: logProxy.py 프로젝트: chinple/mserver
 def _getMockkey(self, reqPath, reqParam):
     reqPath = reqPath.split("?")[0]
     if self.urlmockdata.__contains__(reqPath):
         param = parseRequestParam(reqParam)
         urlmock = self.urlmockdata[reqPath]
         uparam = urlmock['p']
         isMatch = True
         for p in uparam.keys():
             if not (param.__contains__(p) and uparam[p] == param[p]):
                 isMatch = False
                 break
         if isMatch: return urlmock
예제 #4
0
파일: logProxy.py 프로젝트: chinple/mserver
 def addUrlMock(self,
                url,
                param,
                resp,
                status=200,
                wait=0,
                isdelete='false'):
     if self.urlmockdata is None: self.urlmockdata = {}
     if isdelete == "true":
         try:
             self.urlmockdata.__delitem__(url)
         except:
             pass
     else:
         self.urlmockdata[url] = {
             'p': parseRequestParam(param),
             'd': resp,
             's': int(status),
             'w': float(wait)
         }
     return self.urlmockdata.keys()