6
6
7
7
from attrs import evolve , field
8
8
from pyrsistent import m , pmap
9
- from pyrsistent .typing import PMap
10
9
11
10
from referencing ._attrs import frozen
12
11
from referencing .exceptions import CannotDetermineSpecification , Unresolvable
@@ -92,7 +91,7 @@ def opaque(cls, contents: D) -> Resource[D]:
92
91
93
92
See `Specification.OPAQUE` for details.
94
93
"""
95
- return cls (contents = contents , specification = Specification . OPAQUE )
94
+ return Specification . OPAQUE . create_resource (contents = contents )
96
95
97
96
def id (self ) -> URI | None :
98
97
"""
@@ -132,31 +131,31 @@ class Registry(Mapping[URI, Resource[D]]):
132
131
registry with the additional resources added to them.
133
132
"""
134
133
135
- _contents : PMap [URI , Resource [D ]] = field (default = m (), converter = pmap ) # type: ignore[reportUnknownArgumentType] # noqa: E501
134
+ _resources : Mapping [URI , Resource [D ]] = field (default = m (), converter = pmap ) # type: ignore[reportUnknownArgumentType] # noqa: E501
136
135
137
136
def __getitem__ (self , uri : URI ) -> Resource [D ]:
138
137
"""
139
138
Return the `Resource` identified by the given URI.
140
139
"""
141
- return self ._contents [uri ]
140
+ return self ._resources [uri ]
142
141
143
142
def __iter__ (self ) -> Iterator [URI ]:
144
143
"""
145
144
Iterate over all known URIs in the registry.
146
145
"""
147
- return iter (self ._contents )
146
+ return iter (self ._resources )
148
147
149
148
def __len__ (self ) -> int :
150
149
"""
151
150
Count the total number of (fully crawled) resources in this registry.
152
151
"""
153
- return len (self ._contents )
152
+ return len (self ._resources )
154
153
155
154
def contents (self , uri : URI ) -> D :
156
155
"""
157
156
Retrieve the contents identified by the given URI.
158
157
"""
159
- return self ._contents [uri ].contents
158
+ return self ._resources [uri ].contents
160
159
161
160
def crawl (self ) -> Registry [D ]:
162
161
"""
@@ -177,7 +176,7 @@ def with_resources(
177
176
r"""
178
177
Add the given `Resource`\ s to the registry, without crawling them.
179
178
"""
180
- return evolve (self , contents = self ._contents .update (pmap (pairs ))) # type: ignore[reportUnknownArgumentType] # noqa: E501
179
+ return evolve (self , resources = self ._resources .update (pmap (pairs ))) # type: ignore[reportUnknownArgumentType] # noqa: E501
181
180
182
181
def with_contents (
183
182
self ,
@@ -196,8 +195,8 @@ def combine(self, *registries: Registry[D]) -> Registry[D]:
196
195
"""
197
196
Combine together one or more other registries, producing a unified one.
198
197
"""
199
- contents = (registry ._contents for registry in registries )
200
- return evolve (self , contents = self ._contents .update (* contents )) # type: ignore[reportUnknownMemberType] # noqa: E501
198
+ contents = (registry ._resources for registry in registries )
199
+ return evolve (self , resources = self ._resources .update (* contents )) # type: ignore[reportUnknownMemberType] # noqa: E501
201
200
202
201
def resolver (self , base_uri : URI = "" ) -> Resolver [D ]:
203
202
"""
@@ -229,7 +228,8 @@ class Resolver(Generic[D]):
229
228
230
229
The process of resolving a reference may itself involve calculating
231
230
a *new* base URI for future reference resolution (e.g. if an
232
- intermediate resource sets a new base URI).
231
+ intermediate resource sets a new base URI), or may involve encountering
232
+ additional subresources and adding them to a new registry.
233
233
"""
234
234
235
235
_base_uri : str = field (alias = "base_uri" )
0 commit comments