import os from weppy import App app = App(__name__) @app.route('/') def welcome_index(): return 'Hello World test' if __name__ == "__main__": # important !!!!!!! 5000 or PORT env of Heroku port = os.getenv('PORT', 5000) app.run(host='0.0.0.0', port=int(port), debug=True)
@app.route('/api/v1.1/book/<int:bookid>') @vjson(version='1.1') def book_v2_v1(isbn=None, bookid=None): if isbn: url = isbn_url(isbn) elif bookid: url = id_url(bookid) result = bookinfo_v2(url) if result['code'] != const.SUCCESS: return result bookid = result['data']['id'] return bookinfo_v1(bookid) @app.route('/api/v2.0/book/isbn/<int:isbn>') @app.route('/api/v2.0/book/<int:bookid>') @vjson(version='2.0') def book_v2(isbn=None, bookid=None): if isbn: url = isbn_url(isbn) elif bookid: url = id_url(bookid) return bookinfo_v2(url) if __name__ == '__main__': app.run(host=const.ALLOW_HOST, port=const.PORT)
from weppy import App, request app = App(__name__) @app.route('/') def welcome(): # request.params 작동이 좀 특이함. 다른 건 빡빡한데 얘는 왜 그냥 None 주지? return dict(name=request.params.name or 'world') @app.route('/posts', methods='get') def post_list(): return '왜 methods가 옵션인 거죠? JAX-RS보다 나쁘잖아요?' @app.route('/posts/<int:post_id>', methods='get') def post_detail(post_id): # 1. post_id가 int 타입이 아니면 “Invalid action” 에러가 난다. # 2. int라고 했지만 post_id는 결국 문자열로 들어온다. return 'Post - %s' % post_id if __name__ == '__main__': app.run()
@service.json def updates(): num_queries = get_qparam() worlds = [] rp = partial(randint, 1, 10000) ids = [rp() for _ in xrange(num_queries)] ids.sort() # To avoid deadlock for id in ids: world = World.get(id) world.update_record(randomnumber=rp()) worlds.append(world.serialize()) return worlds @app.route() def plaintext(): response.headers["Content-Type"] = "text/plain" return 'Hello, World!' try: import meinheld meinheld.server.set_access_logger(None) meinheld.set_keepalive(120) except ImportError: pass # entry point for debugging if __name__ == "__main__": app.run(debug=True)
auth.add_membership('member', user) isRegister = False if user.id > 0: isRegister = True db.commit() data = [{'success': isRegister}] return dict(data=data) @app.route('/v1/login', methods=['post']) @service.json def login_service(): user_email = request.params.user_email password = request.params.password user = auth.login(user_email, password) if user: current.session.auth.expiration = 604800 # seconds in a week return dict(data=user) if __name__ == '__main__': app.run()
@service.json def model(): example = ExampleModel.get(foo='bar') return {'foo': example.foo, 'bar': example.bar} @app.route("/model-mongo") @service.json def model_mongo(): foo = foos.find_one({'foo': 'bar'}) return json.dumps({'foo': foo['foo'], 'bar': foo['bar']}) @app.route("/load") def load(): return generate_load() @app.command('setup') def setup(): # create the ExampleModel object example = ExampleModel.create( foo="bar", bar="foo", ) db.commit() if __name__ == "__main__": app.run(host='0.0.0.0', port=8080, debug=False)
def scans_new(): attrs = scans.parse_params() resp = Scan.create(**attrs) if resp.errors: response.status = 422 return scans.error_422(resp.errors) # success, proceed with scan serialized_scan = scans.serialize_one(resp.id) async_result = increase_progress.delay(resp.id) # pool = Pool() # pool.apply_async(begin_scan, args=[resp.id], callback=scan_finished_callback) # pool.close() return serialized_scan @results.read() def get_result(row): print(type(row.x_results)) rows = row.x_results() return list(map(lambda x: serialize(x, ResultSerializer), rows)) # return results.serialize_one(row) # @mat_results.read() # def get_mat_result(row): if __name__ == "__main__": app.run(host='0.0.0.0', port=8000, debug=True)
isBenchmark = True if len(sys.argv) > 2 and sys.argv[2] == "-l": isLoop = True try: ncycle = int(sys.argv[3]) except Exception: ncycle = 500 print "\nEseguo il programma in modalita' BENCHMARK LOOP, numero cicli", (ncycle), "...\n" else: print "\nEseguo il programma in modalita' BENCHMARK...\n" main() elif sys.argv[1] == "-w": if len(sys.argv) > 2 and sys.argv[2] == "-t": isTest = True print "\nEseguo il programma in modalita' SERVER TEST...\n" app.run() else: print "\nEseguo il programma in modalita' SERVER...\n" app.run(host="0.0.0.0") else: print "Eseguire il programma con una delle seguenti modalita':" print "'python run.py -t' per la modalita' test" print "'python run.py -t -l n' per la modalita' test in modalita' loop dove n e' il numero di iterazioni" print "'python run.py -b' per la modalita' benchmark" print "'python run.py -b -l n' per la modalita' benchmark in modalita' loop dove n e' il numero di iterazioni" print "'python run.py -w' per la modalita' server" print "'python run.py -w -t' per la modalita' server test" else: print "Eseguire il programma con una delle seguenti modalita':" print "'python run.py -t' per la modalita' test"