This file is indexed.

/usr/lib/python3/dist-packages/pydap/responses/dds.py is in python3-pydap 3.2.2+ds1-1ubuntu1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
"""The DDS response.

The DDS response builds a representation of the structure of the dataset,
informing which variables are contained, their shape, type and dimensions.
Together with the DAS, the DDS describes all metadata associated with a given
dataset, allowing clients to introspect the variables and request data as
necessary.

"""

try:
    from functools import singledispatch
except ImportError:
    from singledispatch import singledispatch

from six.moves import map, zip

from ..model import (DatasetType, BaseType,
                     SequenceType, StructureType,
                     GridType)
from .lib import BaseResponse
from ..lib import __version__, NUMPY_TO_DAP2_TYPEMAP


INDENT = ' ' * 4


class DDSResponse(BaseResponse):

    """The DDS response."""

    __version__ = __version__

    def __init__(self, dataset):
        BaseResponse.__init__(self, dataset)
        self.headers.extend([
            ('Content-description', 'dods_dds'),
            ('Content-type', 'text/plain; charset=ascii'),
        ])

    def __iter__(self):
        for line in dds(self.dataset):
            yield line.encode('ascii')


@singledispatch
def dds(var, level=0, sequence=0):
    """Single dispatcher that generates the DDS response."""
    raise StopIteration


@dds.register(DatasetType)
def _(var, level=0, sequence=0):
    yield "{indent}Dataset {{\n".format(indent=level*INDENT)
    for child in var.children():
        for line in dds(child, level+1, sequence):
            yield line
    yield "{indent}}} {name};\n".format(indent=level*INDENT, name=var.name)


@dds.register(SequenceType)
def _sequencetype(var, level=0, sequence=0):
    yield "{indent}Sequence {{\n".format(indent=level*INDENT)
    for child in var.children():
        for line in dds(child, level+1, sequence+1):
            yield line
    yield "{indent}}} {name};\n".format(indent=level*INDENT, name=var.name)


@dds.register(StructureType)
def _structuretype(var, level=0, sequence=0):
    yield "{indent}Structure {{\n".format(indent=level*INDENT)
    for child in var.children():
        for line in dds(child, level+1, sequence):
            yield line
    yield "{indent}}} {name};\n".format(indent=level*INDENT, name=var.name)


@dds.register(GridType)
def _gridtype(var, level=0, sequence=0):
    yield '{indent}Grid {{\n'.format(indent=level*INDENT)

    yield '{indent}Array:\n'.format(indent=(level+1)*INDENT)
    for line in dds(var.array, level+2, sequence):
        yield line

    yield '{indent}Maps:\n'.format(indent=(level+1)*INDENT)
    for map_ in var.maps.values():
        for line in dds(map_, level+2, sequence):
            yield line

    yield '{indent}}} {name};\n'.format(indent=level*INDENT, name=var.name)


@dds.register(BaseType)
def _basetype(var, level=0, sequence=0):
    shape = var.shape[sequence:]

    if var.dimensions:
        shape = ''.join(
            map('[{0[0]} = {0[1]}]'.format, zip(var.dimensions, shape)))
    elif len(shape) == 1:
        shape = '[{0} = {1}]'.format(var.name, shape[0])
    else:
        shape = ''.join('[{0}]'.format(len) for len in shape)

    yield '{indent}{type} {name}{shape};\n'.format(
        indent=level*INDENT,
        type=NUMPY_TO_DAP2_TYPEMAP[var.dtype.char],
        name=var.name,
        shape=shape)