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

Module common

source code

Common definitions for the GAVO VOTable modules.

Classes
  VOTableError
The base class of VOTable-related errors.
  BadVOTableLiteral
Raised when a literal in a VOTable is invalid.
  BadVOTableData
Raised when something is wrong with a value being inserted into a VOTable.
  VOTableParseError
Raised when something is grossly wrong with the document structure.
  NULLFlags
an interface to the BINARY2 NULL flags.
Functions
 
qmreplace(exc)
a dumb handler for decoder errors.
source code
 
validateTDComplex(val) source code
 
validateVOTInt(val)
raise an error if val is not a legal int for VOTables.
source code
 
indentList(lines, indent)
prepens indent to all elements in lines.
source code
 
getLoopifier(field)
returns a function to map code over arrays.
source code
 
getXtypeEncoderCode(field)
returns code that turns special internal representations for xtyped fields to what's serialised in VOTables.
source code
 
getXtypeDecoderCode(field)
returns code that turns generic VOTable arrays into special internal representations based on xtype.
source code
 
isMultiDim(arraysize)
returns True if the VOTable arraysize denotes a >1D-array.
source code
 
hasVarLength(arraysize)
returns True if the VOTable arraysize denotes a variable-length array.
source code
 
getLength(arraysize)
returns the number of elements expected for an array described with the VOTable attribute arraysize.
source code
 
getShape(datatype, arraysize)
returns a numpy-compatible shape for a VOTable arraysize.
source code
Variables
  NaN = nan
  __package__ = 'gavo.votable'
Function Details

qmreplace(exc)

source code 

a dumb handler for decoder errors.

This is like python's "replace" handler except that we'll always return question marks rather than ufffd. The latter makes sense in a unicode environment, but we need this for VOTable chars, and there that's just a nuisance.

validateVOTInt(val)

source code 

raise an error if val is not a legal int for VOTables.

Actually, this is for tabledata, and after the relaxed 1.3 rules, we allow the empty string ("NULL"), too.

getLoopifier(field)

source code 

returns a function to map code over arrays.

This is used by *XtypeEncoderCode functions below, and for now only deals with 1D arrays of xtyped things, which right now means 2D arrays of votable arrays.

This will return a callable accepting a list of lines (the xtype decoder for an elementary thing), nor None if the array is too complex.

getXtypeEncoderCode(field)

source code 

returns code that turns special internal representations for xtyped fields to what's serialised in VOTables.

For None or unknown xtypes, this will return an empty list. Otherwise, it expects the value in a local variable val and will leave the transformed value there.

This is currently only called for char and float arrays, as no xtypes are defined for other types. If that changes, you'll have to change the *_enc modules.

This will handle 1D arrays of xtyped things but nothing more deeply nested. More deeply nested structures will be left alone (which will only work under very special conditions and yield ugly error messages otherwise).

getXtypeDecoderCode(field)

source code 

returns code that turns generic VOTable arrays into special internal representations based on xtype.

This returns a list of lines or an empty list if no known xtype is found. The code is executed with the unpacked array seen as val, and it should set val to the special representation.

This will handle 1D arrays of xtyped things but nothing more deeply nested. More deeply nested structures will be left alone (which is ok for round-tripping but probably will fail when DaCHS components want to process stuff).

hasVarLength(arraysize)

source code 

returns True if the VOTable arraysize denotes a variable-length array.

This is, of course, False for None arraysizes,

getLength(arraysize)

source code 

returns the number of elements expected for an array described with the VOTable attribute arraysize.

A 1-element array isn't told apart from a scalar here. Both return 1. For variable-length arrays, this returns None.

Bad arraysize specs will give ValueErrors (perhaps not always with the most helpful messages).

>>> getLength(None)
1
>>> getLength("*")
>>> getLength("5")
5
>>> getLength("5x*")
>>> getLength("5x6*")
>>> getLength("7x5x6")
210
>>> getLength("7*x5x6")
Traceback (most recent call last):
ValueError: invalid literal for int() with base 10: '7*'

getShape(datatype, arraysize)

source code 

returns a numpy-compatible shape for a VOTable arraysize.

For variable length 1D arrays, this returns None; for 2+D arrrays, the last dimension is currently replaced by 1. Which doesn't sound smart.