Ejemplo n.º 1
0
def prepare_operands(s1, s2):
    # First, we reload schemas using jsonref to resolve $ref
    # before starting canonicalization.
    # At the moment, we will get undefined behaviour for recursive/circual refs.

    # s1 = jsonref.loads(json.dumps(s1))
    # s2 = jsonref.loads(json.dumps(s2))
    # This is not very efficient, should be done lazily maybe?
    s1 = jsonref.JsonRef.replace_refs(s1)
    s2 = jsonref.JsonRef.replace_refs(s2)

    # Canonicalize and embed checkers for both lhs
    # and rhs schemas  before starting the subtype checking.
    # This also validates input schemas and canonicalized schemas.

    print_db("LHS", s1)
    print_db()
    s1 = simplify_schema_and_embed_checkers(canonicalize_schema(s1))
    print_db("LHS_canonical", s1)
    print_db()

    print_db("RHS", s2)
    print_db()
    s2 = simplify_schema_and_embed_checkers(canonicalize_schema(s2))
    print_db("RHS_canonical", s2)
    print_db()
    return s1, s2
Ejemplo n.º 2
0
def prepare_operands(s1, s2):
    # First, we load schemas using jsonref to resolve $ref
    # before starting canonicalization.

    # s1 = jsonref.loads(json.dumps(s1))
    # s2 = jsonref.loads(json.dumps(s2))
    # This is not very efficient, should be done lazily maybe?
    s1 = jsonref.JsonRef.replace_refs(s1)
    s2 = jsonref.JsonRef.replace_refs(s2)

    # Canonicalize and embed checkers for both lhs
    # and rhs schemas  before starting the subtype checking.
    # This also validates input schemas and canonicalized schemas.

    # At the moment, recursive/circual refs are not supported and hence, canonicalization
    # throws a RecursionError.
    try:
        _s1 = simplify_schema_and_embed_checkers(
            canonicalize_schema(s1))
    except RecursionError:
        # avoid cluttering output by unchaining the recursion error
        raise UnsupportedRecursiveRef(s1, 'LHS') from None

    try:
        _s2 = simplify_schema_and_embed_checkers(
            canonicalize_schema(s2))
    except RecursionError:
        # avoid cluttering output by unchaining the recursion error
        raise UnsupportedRecursiveRef(s2, 'RHS') from None

    return _s1, _s2
Ejemplo n.º 3
0
 def object_hook(self, d):
     return simplify_schema_and_embed_checkers(canonicalize_schema(d))