1 """
2 Parsing identifiers, getting res tuples and resobs from them.
3
4 The DC-internal identifiers are, by default, formed as
5 ivo://<authority-from-config>/<sourceRD path>/<id within path>.
6
7 Thus, all renderers of a given service have the same ivo-id, which is
8 to say, they are all just capabilities on the same record.
9 """
10
11
12
13
14
15
16
17 import re
18
19 from gavo import base
20 from gavo.registry import common
21 from gavo.registry import nonservice
22 from gavo.registry import servicelist
23
24
26 """returns an identifier from a res tuple.
27 """
28 return restup["ivoid"]
29
30
31 _idPattern = re.compile("ivo://(\w[^!;:@%$,/]+)(/[^?#]*)?")
32
34 """returns a pair of authority, resource key for identifier.
35
36 Identifier has to be an ivo URI.
37
38 In the context of the gavo DC, the resource key either starts with
39 static/ or consists of an RD id and a service ID.
40 """
41 mat = _idPattern.match(identifier)
42 if not mat:
43 raise common.IdDoesNotExist(identifier)
44 return mat.group(1), (mat.group(2) or "")[1:]
45
46
56
57
59 """returns a resob for a res tuple.
60
61 restup at least has to contain the sourceRD and resId fields.
62
63 The item that is being returned is either a service or a
64 NonServiceResource (including DeletedResource). All of these have
65 a getMeta method and should be able to return the standard DC
66 metadata.
67 """
68 if restup["deleted"]:
69 return base.makeStruct(nonservice.DeletedResource,
70 resTuple=restup)
71 sourceRD, resId = restup["sourceRD"], restup["resId"]
72 try:
73 return base.caches.getRD(sourceRD).getById(resId)
74 except KeyError:
75 raise base.ui.logOldExc(base.NotFoundError(resId, what="service",
76 within="RD %s"%sourceRD, hint="This usually happens when you"
77 " forgot to run gavopublish %s"%sourceRD))
78
79
84