Package gavo :: Package formats :: Module common :: Class FORMATS_REGISTRY
[frames] | no frames]

Class FORMATS_REGISTRY

source code

object --+
         |
        FORMATS_REGISTRY

a registry for data formats that can be produced by DaCHS.

This works by self-registration of the respective modules on their input; hence, if you want to rely on some entry here, be sure there's an import somewhere.

Instance Methods

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __init__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Class Methods
 
registerDataWriter(cls, key, writer, mainMime, label, extension, *aliases)
adds a writer to the formats registry.
source code
 
getMIMEFor(cls, formatName, orderedFormat=None)
returns a simple MIME type for our formatName (some incoming MIME or an alias).
source code
 
getWriterFor(cls, formatName)
returns a writer for formatName.
source code
 
getLabelFor(cls, formatName)
returns a label for formatName (DaCHS key or MIME type).
source code
 
getKeyFor(cls, formatName)
returns a DaCHS format key for formatName (DaCHS key or MIME).
source code
 
getTypeForExtension(cls, extension)
returns the media type first registered for extension.
source code
 
iterFormats(cls)
iterates over the short names of the available formats.
source code
Class Variables
  writerRegistry = {'csv': <__builtin__.function object>, 'csv_h...
  formatToMIME = {'csv': 'text/csv', 'csv_header': 'text/csv;hea...
  formatToLabel = {'csv': 'CSV without column labels', 'csv_head...
  mimeToKey = {('application', 'fits', frozenset([])): 'fits', (...
  extensionToKey = {'.csv': 'csv', '.fits': 'fits', '.geojson': ...
  keyToExtension = {'csv': '.csv', 'fits': '.fits', 'geojson': '...
Properties

Inherited from object: __class__

Method Details

registerDataWriter(cls, key, writer, mainMime, label, extension, *aliases)
Class Method

source code 

adds a writer to the formats registry.

Key is a short, unique handle for the format, writer is a writer function(data, outputFile) -> None (where data can be an rsc.Data or an rsc.Table instance), mainMime is the preferred media type, label is a human-readable designation for the format (shown in selection widgets and the like), extension is a suggested extension for the format (lower-case only), and aliases are other strings that can be used to select the format in DALI FORMAT or similar.

Where keys, mainMime, and aliases clash, previous entries are silently overwritten. For extensions, the first registred format wins.

getMIMEFor(cls, formatName, orderedFormat=None)
Class Method

source code 

returns a simple MIME type for our formatName (some incoming MIME or an alias).

Some magic, reserved mimes that need to be preserved from the input are recognised and returned in orderedFormat. This is for TAP and related DALI hacks.

getWriterFor(cls, formatName)
Class Method

source code 

returns a writer for formatName.

writers are what's registred via registerDataWriter; formatName is a MIME type or a format alias. This raises CannotSerializeIn if no writer is available.

getKeyFor(cls, formatName)
Class Method

source code 

returns a DaCHS format key for formatName (DaCHS key or MIME).

If formatName is a mime type with parameters, we'll also try to get a format with the parameters stripped and silently succeed if that works.

getTypeForExtension(cls, extension)
Class Method

source code 

returns the media type first registered for extension.

extension must begin with a dot. None is returned for extensions no format has (yet) claimed.


Class Variable Details

writerRegistry

Value:
{'csv': <__builtin__.function object>,
 'csv_header': <__builtin__.function object>,
 'fits': <__builtin__.function object>,
 'geojson': <__builtin__.function object>,
 'html': <__builtin__.function object>,
 'json': <__builtin__.function object>,
 'tsv': <__builtin__.function object>,
 'txt': <__builtin__.function object>,
...

formatToMIME

Value:
{'csv': 'text/csv',
 'csv_header': 'text/csv;header=present',
 'fits': 'application/fits',
 'geojson': 'application/geo+json',
 'html': 'text/html',
 'json': 'application/json',
 'tsv': 'text/tab-separated-values',
 'txt': 'text/plain',
...

formatToLabel

Value:
{'csv': 'CSV without column labels',
 'csv_header': 'CSV with column labels',
 'fits': 'FITS Binary Table',
 'geojson': 'GeoJSON',
 'html': 'HTML',
 'json': 'JSON',
 'tsv': 'Tab separated values',
 'txt': 'Fixed-column plain text',
...

mimeToKey

Value:
{('application', 'fits', frozenset([])): 'fits',
 ('application', 'geo+json', frozenset([])): 'geojson',
 ('application', 'json', frozenset([])): 'json',
 ('application', 'x-votable+xml', frozenset([])): 'votable',
 ('application',
  'x-votable+xml',
  frozenset([('serialization', 'TABLEDATA')])): 'votabletd',
 ('application', 'x-votable+xml', frozenset([('serialization', 'TABLED\
...

extensionToKey

Value:
{'.csv': 'csv',
 '.fits': 'fits',
 '.geojson': 'geojson',
 '.html': 'html',
 '.json': 'json',
 '.tsv': 'tsv',
 '.txt': 'txt',
 '.vot': 'votable',
...

keyToExtension

Value:
{'csv': '.csv',
 'fits': '.fits',
 'geojson': '.geojson',
 'html': '.html',
 'json': '.json',
 'tsv': '.tsv',
 'txt': '.txt',
 'vodml': '.vot4',
...