From b8170a38eccb92400329e826fe1e73365d3dc1fe Mon Sep 17 00:00:00 2001 From: Seth Schoen Date: Tue, 18 Nov 2014 16:39:38 -0800 Subject: [PATCH] docstrings and add JSON pretty-printing code --- letsencrypt/client/acme.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/letsencrypt/client/acme.py b/letsencrypt/client/acme.py index 3a419c8f1..306ee9171 100755 --- a/letsencrypt/client/acme.py +++ b/letsencrypt/client/acme.py @@ -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)