Created
December 7, 2016 10:55
-
-
Save xychix/afd48164c5036ab579a7d5ad7fd303a9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
from flask import Flask, abort | |
import werkzeug.exceptions as ex | |
from flask import make_response | |
app = Flask(__name__) | |
@app.route('/ping') | |
@app.route('/test1') | |
@app.route('/') | |
def ping(): | |
return('OK') | |
#### duplicate this block for each call you want to emulate | |
@app.route('/Emulation.dll/somefolder/rest/<path:dummy>') | |
def call2(dummy): | |
fp = open('rest.reply', 'r') | |
## offcourse you get get your response from elsewhere or even use 'dummy' in there | |
ret = fp.read() | |
fp.close() | |
head, body = ret.split('\n\n',1) | |
c,h = head.split('\n',1) | |
headers_list = h.split('\n') | |
response = make_response(body) | |
response.status_code = int(c.split(' ')[1]) | |
for header in headers_list: | |
k,v = header.split(':',1) | |
response.headers[k.strip()] = v.strip() | |
return(response) | |
#### end block | |
@app.route('/static/') | |
def staticlst(): | |
from os import walk | |
lst = [] | |
for (a,b,c) in walk('static'): | |
lst.extend(c) | |
lst.extend(b) | |
html="<html>" | |
for i in lst: | |
html += "<a href='/static/%s'>%s</a><br>"%(i,i) | |
html += "</html>" | |
return(html) | |
if __name__ == '__main__': | |
app.run(host='0.0.0.0',port=8888,debug=True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment