gavo.base.valuemappers module

Serialising table rows.

The main class in this module is the SerManager, which knows about a target table and figures out how to turn the values in the table rows into strings.

This is used by formats.votablewrite and the HTML table serialisation.

utils.serializers has once been a part of this module. To save migration effort, for now it reproduces that module’s interface.

class gavo.base.valuemappers.SerManager(table, withRanges=True, acquireSamples=True, idManager=None, mfRegistry=<gavo.utils.serializers.ValueMapperFactoryRegistry object>)[source]

Bases: IdManagerMixin

A wrapper for the serialisation of table data.

SerManager instances keep information on what values certain columns can assume and how to map them to concrete values in VOTables, HTML or ASCII.

They are constructed with a BaseTable instance.

You can additionally give:

  • withRanges – ignored, going away

  • acquireSamples – ignored, going away

  • idManager – an object mixing in utils.IdManagerMixin. This is important

    if the ids we are assigning here end up in a larger document. In that case, pass in the id manager of that larger document. Default is the SerManager itself

  • mfRegistry – a map factory registry. Default is the defaltMFRegistry, which is suitable for VOTables.

Iterate over a SerManager to retrieve the annotated columns.

getColumnByName(name)[source]

returns an AnnotatedColumn element for name.

To help out in case name has gone through postgres, this will try name lowercased if it doesn’t match in normal case.

This will raise a KeyError if name can’t be found anyway.

getMappedTuples()[source]

iterates over the table’s rows as tuples with mapped values.

getMappedValues()[source]

iterates over the table’s rows as dicts with mapped values.

class gavo.base.valuemappers.VOTNameMaker[source]

Bases: object

A class for generating db-unique names from VOTable fields.

This is important to avoid all kinds of weird names the remaining infrastructure will not handle. “Normal” TableDefs assume unquoted SQL identifiers as names, and want all names unique.

Using this class ensures these expectations are met in a reproducible way (i.e., given the same table, the same names will be assigned).

makeName(field)[source]
gavo.base.valuemappers.getADQLReservedWords()[source]
gavo.base.valuemappers.getNameBlacklist(forRowmaker=False)[source]

returns a set of names not suitable for table column names.

This comprises SQL reserved words in lower case and, if forRowmaker is true, also some names damaging row makers (e.g. python reserved words).

gavo.base.valuemappers.needsQuoting(identifier, forRowmaker=False)[source]

returns True if identifier needs quoting in an SQL statement. >>> needsQuoting(“RA(J2000)”) True >>> needsQuoting(“ABS”) True >>> needsQuoting(“r”) False