Package gavo :: Package votable :: Module coding
[frames] | no frames]

Module coding

source code

Common code for coding and decoding VOTable data.

Functions
 
getRowEncoderSource(tableDefinition, encoderModule)
returns the source for a function encoding rows of tableDefition in the format implied encoderModule
source code
 
buildCodec(source, env)
returns a compiled function for source in env.
source code
 
buildEncoder(tableDefinition, encoderModule) source code
 
buildDecoder(tableDefinition, decoderModule) source code
 
getNullvalue(field, validator, default=None)
returns None or the nullvalue defined for field.
source code
 
unravelArray(arraysize, seq)
turns a flat sequence into an n-dim array as specfied by the votable arraysize spec arraysize.
source code
 
parseVOTableArraysizeEl(spec, fieldName)
parses a single VOTable arraysize number to (flexible, length).
source code
 
makeShapeValidator(field)
returns code lines to validate an an array shape against a flat sequence in row.
source code
 
ravel(seq)
expands flattens out any sub-sequences (lists or tuples) in seq recursively.
source code
 
trim(seq, arraysize, padder)
returns seq with length arraysize.
source code
 
trimString(val, arraysize, padChar=' ')
returns val flattened and padded with padChar/cropped to length.
source code
Variables
  __package__ = 'gavo.votable'
Function Details

getRowEncoderSource(tableDefinition, encoderModule)

source code 

returns the source for a function encoding rows of tableDefition in the format implied encoderModule

tableDefinition is a VOTable.TABLE instance, encoderModule is one of the enc_whatever modules (this function needs getLinesFor and getPostamble from them).

buildCodec(source, env)

source code 

returns a compiled function for source in env.

Source is the result of one of the makeXXX functions in this module, env typically the result of a getGlobals() on the codec module.

getNullvalue(field, validator, default=None)

source code 

returns None or the nullvalue defined for field.

validator is a function that raises some exception if the nullvalue is inappropriate. It should do so in particular on everything that contains quotes and such; the nullvalues are included in source code and thus might be used to inject code if not validated.

unravelArray(arraysize, seq)

source code 

turns a flat sequence into an n-dim array as specfied by the votable arraysize spec arraysize.

arraysize is <int>{"x"<int>}*?|*.

No padding or cropping will take place. This means that the last row(s) may have improper sizes if seq is incompatible with arraysize.

>>> unravelArray("2x3", "012345")
['01', '23', '45']
>>> unravelArray("2x*", "012345")
['01', '23', '45']
>>> unravelArray("3x2x*", "012345012345")
[['012', '345'], ['012', '345']]

parseVOTableArraysizeEl(spec, fieldName)

source code 

parses a single VOTable arraysize number to (flexible, length).

This will accept single numbers (returns False, number), number* (returns True, number) and just * (returns 0, number).

This is used to parse the last part of an ND array spec. Everything before that must be an integer only.

makeShapeValidator(field)

source code 

returns code lines to validate an an array shape against a flat sequence in row.

This is used by the array decoders.

ravel(seq)

source code 

expands flattens out any sub-sequences (lists or tuples) in seq recursively.

This is used by the array encoders.

trim(seq, arraysize, padder)

source code 

returns seq with length arraysize.

arraysize is an int; you should just use field.getLength() when trimming VOTable arraysizes since the arraysize attribute is rather complex. Arraysize may be None for convenience; trim is a no-op then.

If seq is shorter, padder*missing will be appended, if it is longer, seq will be shortened from the end.

This is intended as a helper for array encoders.

trimString(val, arraysize, padChar=' ')

source code 

returns val flattened and padded with padChar/cropped to length.

field is a V.FIELD or V.PARAM instance for which val should be prepared.

val can also be a sequence of strings (or nested more deeply. In that case, trimString will flatten the value(s), padding and cropping as neccessary.

If val is None, then as many padChars will be returned as arraysize wants (which is 0 for variable-length fields).

For chars, arraysize None is equivalent to arraysize 1.

>>> trimString("abc", "4")
'abc '
>>> trimString(["abc", "de", "f"], "2x*")
'abdef '
>>> trimString([["abc", "cd", "e"], ["", "fgh", "i"]], "2x4x3")
'abcde     fgi           '
>>> trimString(None, "4x2", 'z')
'zzzzzzzz'
>>> trimString(None, "4x2*", 'z')
''
>>> trimString("abc", None)
'a'