Skip to content

Commit

Permalink
Add documentation for string conversion and json_load functions
Browse files Browse the repository at this point in the history
  • Loading branch information
sambhav committed Apr 8, 2017
1 parent 76144e9 commit e64b79f
Showing 1 changed file with 24 additions and 9 deletions.
33 changes: 24 additions & 9 deletions picard/util/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import unicodedata
import builtins
if sys.platform == 'win32':
from ctypes import windll
from ctypes import windll

from time import time
from PyQt5 import QtCore
Expand Down Expand Up @@ -442,15 +442,14 @@ def union_sorted_lists(list1, list2):
return union


def htmlescape(string):
return cgi.escape(string)


def json_load(data):
return json.loads(bytes(data).decode())


def convert_to_string(obj):
"""
Appropriately converts the input `obj` to a string.
Args:
obj (QByteArray, bytes, bytearray, ...): The input object
Returns:
string: The appropriately decoded string
"""
if isinstance(obj, QtCore.QByteArray):
return bytes(obj).decode()
elif isinstance(obj, (bytes, bytearray)):
Expand All @@ -459,4 +458,20 @@ def convert_to_string(obj):
return str(obj)


def htmlescape(string):
return cgi.escape(string)


def json_load(data):
"""
Appropriately convert and returns a python dictionary from
json string.
Args:
data (QByteArray): The json response
Returns:
dict: Response data as a python dict
"""
return json.loads(convert_to_string(data))


builtins.__dict__['string_'] = convert_to_string

0 comments on commit e64b79f

Please sign in to comment.