コード例 #1
0
ファイル: commonTools.py プロジェクト: clytze1993/mserver
    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()