This commit is contained in:
Kenneth Reitz
2012-02-20 13:29:11 -05:00
parent 5da009e330
commit 9922fd76c9
2 changed files with 3 additions and 5 deletions
+1 -4
View File
@@ -13,7 +13,6 @@ from cStringIO import StringIO
from decimal import Decimal
from time import time as now
import omnijson
from decorator import decorator
from flask import Flask, Response
@@ -21,7 +20,6 @@ from flask import Flask, Response
app = Flask(__name__)
@decorator
def x_runtime(f, *args, **kwargs):
"""X-Runtime Flask Response Decorator."""
@@ -29,7 +27,7 @@ def x_runtime(f, *args, **kwargs):
_t0 = now()
r = f(*args, **kwargs)
_t1 = now()
r.headers['X-Runtime'] = '{0}s'.format(Decimal(str(_t1-_t0)))
r.headers['X-Runtime'] = '{0}s'.format(Decimal(str(_t1 - _t0)))
return r
@@ -38,7 +36,6 @@ def x_runtime(f, *args, **kwargs):
def gzip(f, *args, **kwargs):
"""GZip Flask Response Decorator."""
data = f(*args, **kwargs)
if isinstance(data, Response):
+2 -1
View File
@@ -10,6 +10,7 @@ Utility functions.
import random
import bisect
def weighted_choice(choices):
"""Returns a value from choices chosen by weighted random selection
@@ -26,4 +27,4 @@ def weighted_choice(choices):
cum_weights.append(total)
x = random.uniform(0, total)
i = bisect.bisect(cum_weights, x)
return values[i]
return values[i]