docstrings and add JSON pretty-printing code

This commit is contained in:
Seth Schoen
2014-11-18 16:39:38 -08:00
parent 3ff20fbeb4
commit b8170a38ec
+8
View File
@@ -12,6 +12,10 @@ schemata = {schema: json.load(open("letsencrypt/client/schemata/%s.json" % schem
}
def acme_object_validate(j):
"""Validate a JSON object against the ACME protocol using JSON Schema.
Success will return None; failure to validate will raise a
jsonschema.ValidationError exception describing the reason that the
object could not be validated successfully."""
j = json.loads(j)
if not isinstance(j, dict):
raise jsonschema.ValidationError("this is not a dictionary object")
@@ -21,3 +25,7 @@ def acme_object_validate(j):
raise jsonschema.ValidationError("unknown type %s" % j["type"])
jsonschema.validate(j, schemata[j["type"]])
def pretty(s):
"""Return a pretty-printed version of any JSON string (useful when
printing out protocol messages for debugging purposes."""
return json.dumps(json.loads(s), indent=4)