Package dap :: Package parsers :: Module das :: Class DASParser
[hide private]
[frames] | no frames]

Class DASParser

source code

shlex.shlex --+    
              |    
     BaseParser --+
                  |
                 DASParser

A parser for Dataset Attribute Structure.

First we create a dataset and get its DAS:
>>> from dap import dtypes
>>> dataset = dtypes.DatasetType(name='test', attributes={'GLOBAL': {'name': 'teste'}})
>>> dataset['a'] = dtypes.BaseType(name='a', data=1, type='Int32', attributes={'pi': 3.1415})
>>> from dap.server import SimpleHandler
>>> headers, output = SimpleHandler(dataset).das()
>>> das_ = ''.join(output)
>>> print das_
Attributes {
    GLOBAL {
        String name "teste";
    }
    a {
        Float32 pi 3.1415;
    }
}
<BLANKLINE>
Now we build a new dataset from the DDS:
>>> headers, output = SimpleHandler(dataset).dds()
>>> dds_ = ''.join(output)
>>> from dap.parsers.dds import DDSParser
>>> dataset2 = DDSParser(dds_, '').parse()
>>> headers, output = SimpleHandler(dataset2).dds()
>>> print ''.join(output)
Dataset {
    Int32 a;
} test;
<BLANKLINE>
The new dataset has no attributes, since it was built only from the DDS. We pass it to the DAS parser, together with the DAS:
>>> dataset2 = DASParser(das_, '', dataset2).parse()
>>> headers, output = SimpleHandler(dataset2).das()
>>> print ''.join(output)
Attributes {
    GLOBAL {
        String name "teste";
    }
    a {
        Float32 pi 3.1415;
    }
}
<BLANKLINE>
The parser should accept additional metadata:
>>> das_ = 'Attributes {\nGLOBAL {\nString name "teste";\n}\nMETADATA {\nMETAMETADATA {\nString foo "bar";\n}\n}\na {\nFloat32 pi 3.1415;\n}\n}'
>>> dataset2 = DASParser(das_, '', dataset2).parse()
>>> print dataset2.attributes
{'GLOBAL': {'name': ['teste']}, 'METADATA': {'METAMETADATA': {'foo': ['bar']}}}
>>> headers, output = SimpleHandler(dataset2).das()
>>> print ''.join(output)
Attributes {
    GLOBAL {
        String name "teste";
    }
    METADATA {
        METAMETADATA {
            String foo "bar";
        }
    }
    a {
        Float32 pi 3.1415;
    }
}
<BLANKLINE>
Checking a bug Rob Cermak found:
>>> dataset3 = dtypes.DatasetType(name='dataset')
>>> latLonCoordSys = dataset3['latLonCoordSys'] = dtypes.BaseType(name='latLonCoordSys', type='String', attributes={'_CoordinateAxes': "time lat long", 'DODS': {'strlen': 0}})
>>> headers, output = SimpleHandler(dataset3).das()
>>> das_ = ''.join(output)
>>> print das_
Attributes {
    latLonCoordSys {
        DODS {
            Int32 strlen 0;
        }
        String _CoordinateAxes "time lat long";
    }
}
<BLANKLINE>
>>> headers, output = SimpleHandler(dataset3).dds()
>>> dds_ = ''.join(output)
>>> dataset4 = DDSParser(dds_, '').parse()
>>> dataset4 = DASParser(das_, '', dataset4).parse()
>>> headers, output = SimpleHandler(dataset4).das()
>>> print  ''.join(output)
Attributes {
    latLonCoordSys {
        DODS {
            Int32 strlen 0;
        }
        String _CoordinateAxes "time lat long";
    }
}
<BLANKLINE>


Instance Methods [hide private]
  __init__(self, das, url, dataset)
  parse(self)
Parse the DAS and return a ``DatasetType`` object with the attributes populated.
  _attrconts(self)
  _attrcont(self)
  _container(self)
  _metadata(self)
  _attribute(self)

Inherited from BaseParser (private): _check, _consume, _peek

Inherited from shlex.shlex: __iter__, error_leader, get_token, next, pop_source, push_source, push_token, read_token, sourcehook


Method Details [hide private]

__init__(self, das, url, dataset)
(Constructor)

source code 
None
Overrides: shlex.shlex.__init__

parse(self)

source code 
Parse the DAS and return a ``DatasetType`` object with the attributes populated.

_attrconts(self)

source code 
None

_attrcont(self)

source code 
None

_container(self)

source code 
None

_metadata(self)

source code 
None

_attribute(self)

source code 
None