gavo.rscdef.common module

Common items used by resource definition objects.

class gavo.rscdef.common.ColumnList(*args)[source]

Bases: list

A list of column.Columns (or derived classes) that takes care that no duplicates (in name) occur.

If you add a field with the same dest to a ColumnList, the previous instance will be overwritten. The idea is that you can override ColumnList in, e.g., interfaces later on.

Also, two ColumnLists are considered equal if they contain the same names.

After construction, you should set the withinId attribute to something that will help make sense of error messages.

append(item)[source]

adds the Column item to the data field list.

It will overwrite a Column of the same name if such a thing is already in the list. Indices are updated.

deepcopy(newParent)[source]

returns a deep copy of self.

This means that all child structures are being copied. In that process, they receive a new parent, which is why you need to pass one in.

extend(seq)[source]

Extend list by appending elements from the iterable.

getColumnById(id)[source]

returns the column with id.

It will raise a NotFoundError if no such column exists.

getColumnByName(name)[source]

returns the column with name.

It will raise a NotFoundError if no such column exists.

getColumnByUCD(ucd)[source]

returns the single, unique column having ucd.

It raises a StructureError if there is no such column or more than one.

getColumnByUCDs(*ucds)[source]

returns the single, unique column having one of ucds.

This method has a confusing interface. It sole function is to help when there are multiple possible UCDs that may be interesting (like pos.eq.ra;meta.main and POS_EQ_RA_MAIN). It should only be used for such cases.

getColumnByUtype(utype)[source]

returns the column having utype.

This should be unique, but this method does not check for uniqueness.

getColumnsByUCD(ucd)[source]

returns all columns having ucd.

getIdIndex()[source]
redoIndex()[source]

creates a mapping of names to list indexes.

You must call this when you dare to munge this manually (which you shouldn’t).

remove(col)[source]

Remove first occurrence of value.

Raises ValueError if the value is not present.

replace(oldCol, newCol)[source]
class gavo.rscdef.common.ColumnListAttribute(name, childFactory, description='Undocumented', **kwargs)[source]

Bases: StructListAttribute

An adapter from a ColumnList to a structure attribute.

property default_
feedObject(instance, obj)[source]
getCopy(instance, newParent, ctx)[source]
replace(instance, oldStruct, newStruct)[source]
class gavo.rscdef.common.IVOMetaMixin[source]

Bases: StructCallbacks

A mixin for resources aspiring to have IVO ids.

All those need to have an RDAttribute. In return, we’re filling in sensible defaults for the referenceURL, identifier, and status meta items (which, as usual for the computed metas, are overridable by normal setMetas).

class gavo.rscdef.common.NamePathAttribute(**kwargs)[source]

Bases: AtomicAttribute

defines an attribute NamePath used for resolution of “original” attributes.

The NamePathAttribute provides a resolveName method as expected by base.OriginalAttribute.

iterParentMethods()[source]

returns an iterator over (name, method) pairs that should be inserted in the parent class.

parse(value)[source]

returns a typed python value for the string representation value.

value can be expected to be a unicode string.

typeDesc_ = 'id reference'
unparse(value)[source]

returns a typed python value for the string representation value.

value can be expected to be a unicode string.

class gavo.rscdef.common.PrivilegesMixin[source]

Bases: StructCallbacks

A mixin for structures declaring access to database objects (tables, schemas).

Access is managed on the level of database profiles. Thus, the names here are not directly role names in the database.

We have two types of privileges: “All” means at least read and write, and “Read” meaning at least read and lookup.

class gavo.rscdef.common.ProfileListAttribute(name, default, description, defaultSource)[source]

Bases: AtomicAttribute

An attribute containing a comma separated list of profile names.

There’s the special role name “defaults” for whatever default this profile list was constructed with.

property default_
makeUserDoc()[source]
parse(value)[source]

returns a typed python value for the string representation value.

value can be expected to be a unicode string.

typeDesc_ = 'Comma separated list of profile names'
unparse(value)[source]

returns a typed python value for the string representation value.

value can be expected to be a unicode string.

class gavo.rscdef.common.RDAttribute[source]

Bases: AttributeDef

an attribute that gives access to the current rd.

The attribute is always called rd. There is no default, but on the first access, we look for an ancestor with an rd attribute and use that if it exists, otherwise rd will be None. There currently is no way to reset the rd.

These attributes cannot (yet) be fed, so rd=”xxx” won’t work. If we need this, the literal would probably be an id.

computed_ = True
iterParentMethods()[source]

returns an iterator over (name, method) pairs that should be inserted in the parent class.

makeUserDoc()[source]
typeDesc_ = 'reference to a resource descriptor'
class gavo.rscdef.common.Registration(parent, **kwargs)[source]

Bases: Structure, MetaMixin

A request for registration of a data or table item.

This is much like publish for services, just for data and tables; since they have no renderers, you can only have one register element per such element.

Data registrations may refer to published services that make their data available.

aliases = ['register']
attrSeq = [<gavo.base.parsecontext.IdAttribute object>, <gavo.base.meta.MetaAttribute object>, <gavo.base.parsecontext.ReferenceListAttribute object>, <gavo.base.attrdef.StringSetAttribute object>]
auxiliary = True
completeElement(ctx)[source]
completedCallbacks = []
docName_ = 'publish (data)'
managedAttrs = {'id': <gavo.base.parsecontext.IdAttribute object>, 'meta': <gavo.base.meta.MetaAttribute object>, 'meta_': <gavo.base.meta.MetaAttribute object>, 'services': <gavo.base.parsecontext.ReferenceListAttribute object>, 'sets': <gavo.base.attrdef.StringSetAttribute object>}
name_ = 'publish'
publishedForADQL()[source]

returns true if at least one table published is available for TAP/ADQL.

register()[source]

adds isServiceFor and isServedBy metadata to data, service pairs in this registration.

class gavo.rscdef.common.ResdirRelativeAttribute(name, default=None, description='Undocumented', **kwargs)[source]

Bases: FunctionRelativePathAttribute

is a path that is interpreted relative to the current RD’s resdir.

The parent needs an RDAttribute.

getResdir(instance)[source]
gavo.rscdef.common.getAccrefFromStandardPubDID(pubdid, authBase='ivo://org.gavo.dc/~?')[source]

returns an accref from a standard DaCHS PubDID.

This is basically the inverse of getStandardPubDID. It will raise NotFound if pubdid “looks like a URI” (implementation detail: has a colon in the first 10 characters) and does not start with ivo://<authority>/~?. If it’s not a URI, we assume it’s a local accref and just return it.

The function does not check if the remaining characters are a valid accref, much less whether it can be resolved.

authBase’s default will reflect you system’s settings on your installation, which probably is not what’s given in this documentation.

returns a datalink URL for the product referenced through accref with the datalink service dlSvc.

This assumes that dlSvc uses the standard DaCHS pubDIDs. dlSvc needs to be the service element.

A typical use is in a metaMaker and would look like this:

getDatalinkMetaLink(rd.getById("dl"), descriptor.accref)
gavo.rscdef.common.getInputsRelativePath(absPath, liberalChars=True)[source]

returns absath relative to the DaCHS inputsDir.

If absPath is not below inputsDir, a ValueError results. On liberalChars, we see the `function getRelativePath`_.

In rowmakers and rowfilters, you’ll usually use the macro \inputRelativePath that inserts the appropriate code.

gavo.rscdef.common.getReferencedElement(refString, forceType=None, **kwargs)[source]

returns the element for the DaCHS reference refString.

refString has the form rdId[#subRef]; rdId can be filesystem-relative, but the RD referenced must be below inputsDir anyway.

You can pass a structure class into forceType, and a StructureError will be raised if what’s pointed to by the id isn’t of that type.

You should usually use base.resolveCrossId instead of this from within DaCHS. This is intended for code handling RD ids from users.

This supports further keyword arguments to getRD.

gavo.rscdef.common.getStandardPubDID(path)[source]

returns the standard DaCHS PubDID for path.

The publisher dataset identifier (PubDID) is important in protocols like SSAP and obscore. If you use this function, the PubDID will be your authority, the path component ~, and the inputs-relative path of the input file as the parameter.

path can be relative, in which case it is interpreted relative to the DaCHS inputsDir.

You can define your PubDIDs in a different way, but you’d then need to provide a custom descriptorGenerator to datalink services (and might need other tricks). If your data comes from plain files, use this function.

In a rowmaker, you’ll usually use the standardPubDID macro.

gavo.rscdef.common.replaceProcDefAt(src, dictName='vars')[source]

replaces @<identifier> with <dictName>[“<identifier>”] in src.

We do this to support this shortcut in the vicinity of rowmakers (i.e., there and in procApps).