Skip to content

Commit 4dc3668

Browse files
committed
Combine specification_for until it needs to be separate.
1 parent 1ba94dc commit 4dc3668

File tree

1 file changed

+22
-26
lines changed

1 file changed

+22
-26
lines changed

referencing/_core.py

+22-26
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,26 @@ class IdentifiedResource:
2222
resource: Schema
2323

2424
@classmethod
25-
def from_resource(cls, resource, **kwargs):
26-
return cls(
27-
resource=resource,
28-
specification=specification_for(resource, **kwargs),
29-
)
25+
def from_resource(
26+
cls,
27+
resource: Schema,
28+
default_specification: Specification = ..., # type: ignore
29+
):
30+
specification = default_specification
31+
32+
if resource is not True and resource is not False:
33+
jsonschema_schema_keyword = resource.get("$schema")
34+
if jsonschema_schema_keyword is not None:
35+
from referencing import jsonschema
36+
37+
specification = jsonschema.BY_ID.get(
38+
jsonschema_schema_keyword,
39+
default_specification,
40+
)
41+
42+
if specification is ...:
43+
raise UnidentifiedResource(resource)
44+
return cls(resource=resource, specification=specification)
3045

3146
def id(self):
3247
return self._specification.id_of(self.resource)
@@ -38,29 +53,10 @@ def subresources(self):
3853
for each in self._specification.subresources_of(self.resource):
3954
yield IdentifiedResource.from_resource(
4055
resource=each,
41-
default=self._specification,
56+
default_specification=self._specification,
4257
)
4358

4459

45-
def specification_for(
46-
resource: Schema,
47-
default: Specification = ..., # type: ignore
48-
) -> Specification:
49-
if resource is True or resource is False:
50-
pass
51-
else:
52-
jsonschema_schema_keyword = resource.get("$schema")
53-
if jsonschema_schema_keyword is not None:
54-
from referencing import jsonschema
55-
56-
specification = jsonschema.BY_ID.get(jsonschema_schema_keyword)
57-
if specification is not None:
58-
return specification
59-
if default is ...:
60-
raise UnidentifiedResource(resource)
61-
return default
62-
63-
6460
@frozen
6561
class Anchor:
6662

@@ -203,8 +199,8 @@ def resolver(self, root: Schema, specification: Specification) -> Resolver:
203199
registry = self.with_identified_resource(
204200
uri=uri,
205201
resource=IdentifiedResource(
206-
specification=specification,
207202
resource=root,
203+
specification=specification,
208204
),
209205
)
210206
return Resolver(base_uri=uri, registry=registry)

0 commit comments

Comments
 (0)