def check_deps(): try: output_deps = os.path.join(CONTEXT.get_variables('${OUTPUT_DIR}'), env.deps) if os.path.exists(output_deps): return else: Common.copyFiles(env.depsDir, output_deps) except Exception, e: print e
def Http_MeiTuan_Request(self, url, request, key="meituanhotelopen", **headers): u''' Examples: | Http MeiTuan Request | http://10.200.152.6:8080/hotel | request.xml | ''' if Common.check_file(CONTEXT.get_path(request)): message = open(CONTEXT.get_path(request), 'r').read() else: message = request newheards = {} for k, v in headers.items(): newheards[k.encode('utf-8')] = v.encode('utf-8') h = httplib2.Http() obj = AES.new(key, AES.MODE_ECB) x = AES.block_size - (len(message) % AES.block_size) if x != 0: message = message + chr(x) * x message = obj.encrypt(message) body = base64.urlsafe_b64encode(message).replace('=', '') resp, enStr = h.request(url.encode('utf-8'), 'POST', body, headers=newheards) try: cipher = AES.new(key, AES.MODE_ECB) enStr += (len(enStr) % 4) * "=" decryptByts = base64.urlsafe_b64decode(enStr) msg = cipher.decrypt(decryptByts) paddingLen = ord(msg[len(msg) - 1]) try: content = (msg[0:-paddingLen]).decode('gbk') except Exception: content = (msg[0:-paddingLen]) return content except Exception, e: return e, enStr, resp
def RunHttpClientELong(self, url, *requests): u''' Examples: | @{responses}= | Run Http Client E Long | url | ./request1.xml | ./request2.xml | ...... | | @{responses}= | Run Http Client E Long | url | <root>....</root> | ''' responses = [] for request in requests: dlog.write(request, level='DEBUG') if type(request) is unicode: request = request.encode('utf-8') if Common.check_file(CONTEXT.get_path(request)): message = ''.join(open(CONTEXT.get_path(request), 'rb').readlines()) message = urllib.quote(str(message)) else: message = urllib.quote(str(request)) dlog.write(message, level='DEBUG') h = httplib2.Http() resp, content = h.request(url, 'POST' , 'Message=%s' % message , headers={'content-type': 'application/x-www-form-urlencoded'}) responses.append(content) return responses
def _runhttpclient(self, hc, url, method, requests, myheaders): for myrequest in requests: request = None newheards = {} if type(myrequest) is unicode: request = myrequest.encode('utf-8') if Common.check_file(CONTEXT.get_path(myrequest)): request = open(CONTEXT.get_path(myrequest), 'rb').read() for k, v in myheaders.items(): newheards[k.encode('utf-8')] = v.encode('utf-8') if newheards.has_key('content-encoding'): if newheards['content-encoding'] == 'gzip': request = Common.Compress_gzip(myrequest) dlog.write(request, console=True) h = httplib2.Http() try: resp, content = h.request(url.encode('utf-8'), method.encode('utf-8'), request, headers=newheards) hc.responses.append(content) hc.headers = resp except Exception, e: hc.responses.append(e) dlog.write('Run http Client Error:%s' % e, level="WARN", console=True)
def Http_CNBooking_Request(self, url, request, key="U+qFnPhJbiOTkX+e", iv="U+qFnPhJbiOTkX+e"): u''' Examples: | Http CNBooking Request | http://10.200.152.6:8080/hotel | request.xml | ''' if Common.check_file(CONTEXT.get_path(request)): message = b''.join(open(CONTEXT.get_path(request), 'rb').read()) else: message = request h = httplib2.Http() obj = AES.new(key, AES.MODE_CBC, iv) if len(message) % 16 != 0: message += chr((16 - len(message) % 16)) * (16 - len(message) % 16) body = obj.encrypt(message).encode('hex') resp, content = h.request(url, 'POST', body) return content
import json import Doraemon.Common as Common import Doraemon.Environment as env """ type : types of variables range : value range list : value list format : value format ("yyyy-mm-dd") use re depend : other key depend on this key value for example: {"type":"str","range":[1,99]} {"type":"str","cs":"upper"} {"type":"str","list":["BOOK","Modify"]} {"type":"str","list":["Success","Fail"],"depend":{"Fail":["err.msg"]}} """ perflogdb = Common.get_path_from_pypath(env.project_name, r'applog\perflog.db') class Reuqest(object): def __init__(self, result): self.request = result[0] self.map = result[1] class Map(object): def __init__(self, result): self.key = result[0] self.value = self._todict(result[1]) self.required = result[2] def _todict(self, string):
def _get_request_path(self, Request): if not Common.check_file(CONTEXT.get_path(Request)): Request_path = Common.CreateTempFile(Request) else: Request_path = CONTEXT.get_path(Request) return Request_path