Skip to content

Commit

Permalink
JSON renaming
Browse files Browse the repository at this point in the history
  • Loading branch information
joamag committed Mar 21, 2020
1 parent 5a6e06b commit 54d927e
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/quorum/base.py
Expand Up @@ -583,7 +583,7 @@ def load_bundles(app, offset = 2):
for path in paths:
# joins the current (base) bundles path with the current path
# in iteration to create the full path to the file and opens
# it trying to read its json based contents
# it trying to read its JSON based contents
path_f = os.path.join(bundles_path, path)
file = open(path_f, "rb")
try: data_j = json.load(file)
Expand Down
4 changes: 2 additions & 2 deletions src/quorum/exceptions.py
Expand Up @@ -310,10 +310,10 @@ class JSONError(HTTPError):

data = None
""" The deserialized version of the response information
provided by the json request """
provided by the JSON request """

def __init__(self, data):
HTTPError.__init__(self, "Problem requesting json data")
HTTPError.__init__(self, "Problem requesting JSON data")
self.data = data

def __str__(self):
Expand Down
4 changes: 2 additions & 2 deletions src/quorum/export.py
Expand Up @@ -152,7 +152,7 @@ def export_data(self, file_path):
self._create_zip(file_path, temporary_path)

def _import_single(self, collection, data, key, policy = IGNORE):
# loads the provided json data as a sequence of key value items
# loads the provided JSON data as a sequence of key value items
# and then starts loading all the values into the data source
data = data.decode("utf-8")
data_s = json.loads(data)
Expand Down Expand Up @@ -196,7 +196,7 @@ def _import_single(self, collection, data, key, policy = IGNORE):

def _import_multiple(self, collection, data, key, policy = IGNORE):
# iterates over the complete set of data element to load
# the json contents and then load the corresponding entity
# the JSON contents and then load the corresponding entity
# value into the data source
for _value, _data in data:
# loads the current data in iteration from the file
Expand Down
6 changes: 3 additions & 3 deletions src/quorum/httpc.py
Expand Up @@ -627,7 +627,7 @@ def _parse_url(url):

def _result(data, info = {}, force = False, strict = False):
# tries to retrieve the content type value from the headers
# info and verifies if the current data is json encoded, so
# info and verifies if the current data is JSON encoded, so
# that it gets automatically decoded for such cases
content_type = info.get("Content-Type", None) or ""
is_json = util.is_content_type(
Expand All @@ -639,8 +639,8 @@ def _result(data, info = {}, force = False, strict = False):
)
) or force

# verifies if the current result set is json encoded and in
# case it's decodes it and loads it as json otherwise returns
# verifies if the current result set is JSON encoded and in
# case it's decodes it and loads it as JSON otherwise returns
# the "raw" data to the caller method as expected, note that
# the strict flag is used to determine if the exception should
# be re-raised to the upper level in case of value error
Expand Down
8 changes: 4 additions & 4 deletions src/quorum/route.py
Expand Up @@ -50,20 +50,20 @@

def route(*args, **kwargs):
# verifies if the request decorator should be of type
# json serializer in case it should not returns the old
# JSON serializer in case it should not returns the old
# route decorator (default behavior)
is_json = kwargs.get("json", False)
if not is_json: return common.base().APP.old_route(*args, **kwargs)

# removes the json keyword argument from the list of arguments
# removes the JSON keyword argument from the list of arguments
# (to avoid errors) and then calls the old route method to obtain
# the "normal" decorator
del kwargs["json"]
decorator = common.base().APP.old_route(*args, **kwargs)

# creates the "new" route decorator maker method that should
# override the old one and create a new decorator that
# serializes all the unhandled exceptions as json
# serializes all the unhandled exceptions as JSON
def _route(function):
def _decorator(*args, **kwargs):
try: result = function(*args, **kwargs)
Expand Down Expand Up @@ -138,7 +138,7 @@ def _decorator(*args, **kwargs):

# retrieves the type for the result that was returned from the
# concrete method and in case the result is either a mongo object,
# a dictionary or a sequence it's serialized as json, then returns
# a dictionary or a sequence it's serialized as JSON, then returns
# the result to the caller method
result_t = type(result)
if isinstance(result, model.Model):
Expand Down
10 changes: 5 additions & 5 deletions src/quorum/util.py
Expand Up @@ -156,7 +156,7 @@ def is_iterable(object):
def request_json(request = None, encoding = "utf-8"):
# retrieves the proper request object, either the provided
# request or the default flask request object and then in
# case the the json data is already in the request properties
# case the the JSON data is already in the request properties
# it is used (cached value) otherwise continues with the parse
request = request or flask.request
try:
Expand All @@ -165,7 +165,7 @@ def request_json(request = None, encoding = "utf-8"):
except RuntimeError: pass

# retrieves the current request data and tries to
# "load" it as json data, in case it fails gracefully
# "load" it as JSON data, in case it fails gracefully
# handles the failure setting the value as an empty map
data = request.data
try:
Expand All @@ -176,12 +176,12 @@ def request_json(request = None, encoding = "utf-8"):
data_j = {}
request.properties["_data_j"] = data_j

# returns the json data object to the caller method so that it
# returns the JSON data object to the caller method so that it
# may be used as the parsed value (post information)
return data_j

def get_field(name, default = None, cast = None, strip = False):
# tries to retrieve the json based representation of the provided
# tries to retrieve the JSON based representation of the provided
# request from all the possible sources, this is required because
# it's going to be used to try to retrieve a field from it
data_j = request_json()
Expand Down Expand Up @@ -224,7 +224,7 @@ def get_object(
object = object and copy.copy(object) or {}

# retrieves the current request data and tries to
# "load" it as json data, in case it fails gracefully
# "load" it as JSON data, in case it fails gracefully
# handles the failure setting the value as an empty map
try: data_j = request_json()
except RuntimeError: data_j = dict()
Expand Down
2 changes: 1 addition & 1 deletion src/quorum/validation.py
Expand Up @@ -89,7 +89,7 @@ def validate(method = None, methods = [], object = None, ctx = None, build = Tru
# to correctly retrieve populate the object from it
if build:
# retrieves the current request data and tries to
# "load" it as json data, in case it fails gracefully
# "load" it as JSON data, in case it fails gracefully
# handles the failure setting the value as an empty map
data_j = util.request_json()

Expand Down

0 comments on commit 54d927e

Please sign in to comment.