-
Notifications
You must be signed in to change notification settings - Fork 1
/
decorators.py
43 lines (34 loc) · 1.05 KB
/
decorators.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# -*- coding: utf-8 -*-
from datetime import datetime
from functools import wraps
FORMAT_EXT = {
"GPKG": '.gpkg',
"KML": '.kml',
"GeoJSON": '.json',
"GML": '.gml',
"GPX": '.gpx',
"GPSTrackMaker": ".gmt",
"ESRI Shapefile": ".shp"
}
class FormatException(Exception):
pass
def ensure_supported_format(func):
def wrap(*args, **kwargs):
format = kwargs.get('target_format', 'GPKG')
if format in FORMAT_EXT.keys():
return func(*args, **kwargs)
else:
raise FormatException("Unsupported Format")
return wrap
def time_it(function):
@wraps(function)
def wrap(request, *args, **kwargs):
start = datetime.now()
result = function(request, *args, **kwargs)
end = datetime.now()
print("{} took ------>{} seconds".format(
function.func.__name__, (end - start).total_seconds()))
print("{} took ------>{} milliseconds".format(
function.func.__name__, (end - start).total_seconds() * 1000))
return result
return wrap