Created
April 4, 2011 05:20
-
-
Save RichardBronosky/901165 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| from functools import wraps | |
| from flask import request | |
| import os | |
| print 'TEST 1' | |
| def cached(timeout=5 * 60, key='view/%s'): | |
| print 'TEST 2' | |
| def decorator(f): | |
| print 'TEST 3' | |
| @wraps(f) | |
| def decorated_function(*args, **kwargs): | |
| print 'TEST 4' | |
| cache_key = key % request.path | |
| os.execv(('/bin/echo %s > /tmp/out.log' % cache_key, ['test']), 'a', 0) | |
| print 'cache_key: ', cache_key | |
| rv = cache.get(cache_key) | |
| if rv is not None: | |
| return rv | |
| rv = f(*args, **kwargs) | |
| cache.set(cache_key, rv, timeout=timeout) | |
| print 'TEST 5' | |
| return rv | |
| print 'TEST 6' | |
| return decorated_function | |
| print 'TEST 7' | |
| return decorator | |
| print 'TEST 8' |
This file contains hidden or 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
| from flask import Flask, abort, redirect, url_for | |
| from werkzeug.contrib.cache import SimpleCache | |
| import atlassian | |
| app = Flask(__name__) | |
| bridge = atlassian.bridge() | |
| cache = SimpleCache() | |
| import atlassian, cache_decorator | |
| cached = cache_decorator.cached() | |
| #from cache_decorator import cached | |
| print 'TEST 10' | |
| @cached | |
| @app.route("/browse/<path>") | |
| def browse(path): | |
| print 'TEST 11' | |
| href = '%s/%s' % (bridge.jira_pattern, path) | |
| image = bridge.jira_status_image_from_href(href) | |
| return redirect(image) | |
| @app.route("/hello/<path>") | |
| def hello(path): | |
| return "<h2>Hello World,</h2> from %s!" % path | |
| if __name__ == "__main__": | |
| app.debug = True | |
| app.run(host='0.0.0.0', port=5150) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment