def ensure_format(doc, format):
assert format in ('<STR_LIT>', '<STR_LIT>')<EOL>if getattr(doc, '<STR_LIT>', None) == '<STR_LIT>':<EOL><INDENT>if format == '<STR_LIT>':<EOL><INDENT>return xml_to_json(doc)<EOL><DEDENT><DEDENT>elif isinstance(doc, dict) and '<STR_LIT>' in doc:<EOL><INDENT>if format == '<STR_LIT>':<EOL><INDENT>return json_doc_to_xml(doc)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>return doc<EOL>
Ensures that the provided document is an lxml Element or json dict.