gavo.base.typesystems module¶
Conversions between type systems.
The DC software has to deal with a quite a few type systems:
Python
SQL
Postgres pg_type
VOTable
XSD
Twisted formal
numpy
Based on the (stinking) framework of utils.typeconversions, this module contains converters between them as necessary. The linuga franca of our type systems is SQL+extensions as laid down in utils.typeconversions.
- exception gavo.base.typesystems.ConversionError(msg: str = '', hint: Optional[str] = None)[source]¶
Bases:
Error
- class gavo.base.typesystems.FromSQLConverter[source]¶
Bases:
object
is an abstract base class for type converters from the SQL type system.
Implementing classes have to provide a dict simpleMap mapping sql type strings to target types, and a method mapComplex that receives a type and a length (both strings, derived from SQL array types) and either returns None (no matching type) or the target type.
Implementing classes should also provide a typeSystem attribute giving a short name of the type system they convert to.
- gavo.base.typesystems.pythonToLiteral(type)¶
- gavo.base.typesystems.sqltypeToNumpy(sqlType)¶
- gavo.base.typesystems.sqltypeToPG(type)[source]¶
returns a postgres type for one of our internal SQL types.
This is really only because of VOTable’s terrible string features. For one, we map UNICODE to TEXT as long as VOTable char can’t be UTF-8. And then, VOTable needs fixed-length strings in string arrays, whereas postgres doesn’t accept char(something) as a stand-in for text in such arrays. We hence map any char() in the first place to text.
Actual char arrays of >1d can still be done with square brackets. Yeah… it would be nice if we could do this better.
>>> sqltypeToPG("INT[23, 42]") 'INT[23, 42]' >>> sqltypeToPG("uniCode[23]") 'TEXT[23]' >>> sqltypeToPG("char(5)[4][7]") 'TEXT[4][7]' >>>
- gavo.base.typesystems.sqltypeToPgValidator(sqlType)¶
- gavo.base.typesystems.sqltypeToPython(sqlType)¶
- gavo.base.typesystems.sqltypeToPythonCode(sqlType)¶
- gavo.base.typesystems.sqltypeToVOTable(sqlType)¶
- gavo.base.typesystems.sqltypeToXSD(sqlType)¶
- gavo.base.typesystems.voTableToSQLType(type, arraysize, xtype=None)¶