mirror of
https://github.com/certbot/certbot.git
synced 2026-08-03 03:52:02 +02:00
docstrings and add JSON pretty-printing code
This commit is contained in:
@@ -12,6 +12,10 @@ schemata = {schema: json.load(open("letsencrypt/client/schemata/%s.json" % schem
|
|||||||
}
|
}
|
||||||
|
|
||||||
def acme_object_validate(j):
|
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)
|
j = json.loads(j)
|
||||||
if not isinstance(j, dict):
|
if not isinstance(j, dict):
|
||||||
raise jsonschema.ValidationError("this is not a dictionary object")
|
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"])
|
raise jsonschema.ValidationError("unknown type %s" % j["type"])
|
||||||
jsonschema.validate(j, schemata[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)
|
||||||
|
|||||||
Reference in New Issue
Block a user