aboutsummaryrefslogtreecommitdiffstats
path: root/servo/lib
diff options
context:
space:
mode:
Diffstat (limited to 'servo/lib')
-rw-r--r--servo/lib/utils.py13
1 files changed, 11 insertions, 2 deletions
diff --git a/servo/lib/utils.py b/servo/lib/utils.py
index fa7c37c..6644a7e 100644
--- a/servo/lib/utils.py
+++ b/servo/lib/utils.py
@@ -23,15 +23,18 @@ def paginate(queryset, page, count=10):
return results
+
def text_response(data):
- return HttpResponse(data, content_type="text/plain; charset=utf-8")
-
+ return HttpResponse(data, content_type='text/plain; charset=utf-8')
+
+
def csv_response(data):
"""
Shortcut for sending a CSV response
"""
return HttpResponse(data, content_type='text/csv')
+
def send_csv(data, filename):
"""
Shortcut for sending CSV data as a file
@@ -40,12 +43,14 @@ def send_csv(data, filename):
response['Content-Disposition'] = 'attachment; filename="%s.txt"' % filename
return response
+
def json_response(data):
"""
Shortcut for sending a JSON response
"""
return HttpResponse(json.dumps(data), content_type='application/json')
+
def strip_keypass(keypass, infile, outfile):
"""
Strips a passphrase from a private key
@@ -53,12 +58,14 @@ def strip_keypass(keypass, infile, outfile):
subprocess.call(['openssl', 'rsa', '-passin', 'pass:' + keypass,
'-in', infile, '-out', outfile])
+
def multiprint(*args):
"""
Emulate JS console.log()
"""
print(', '.join(args))
+
def choices_to_dict(t):
"""
Converts a ChoiceField two-tuple to a dict (for JSON)
@@ -71,9 +78,11 @@ def choices_to_dict(t):
return d
+
def empty(v):
return v in ('', ' ', None,)
+
def cache_getset(k, v):
"""
Shortcut for getting and setting cache