This file is indexed.

/usr/lib/python2.7/dist-packages/pywps/inout/formats/__init__.py is in python-pywps 4.0.0-3.

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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
##################################################################
# Copyright 2016 OSGeo Foundation,                               #
# represented by PyWPS Project Steering Committee,               #
# licensed under MIT, Please consult LICENSE.txt for details     #
##################################################################


"""List of know mimetypes"""

# List of known complex data formats
# you can use any other, but thise are widly known and supported by popular
# software packages
# based on Web Processing Service Best Practices Discussion Paper, OGC 12-029
# http://opengeospatial.org/standards/wps

from lxml.builder import ElementMaker
from collections import namedtuple
import mimetypes
from pywps.validator.mode import MODE
from pywps.validator.base import emptyvalidator

_FORMAT = namedtuple('FormatDefintion', 'mime_type,'
                     'extension, schema')
_FORMATS = namedtuple('FORMATS', 'GEOJSON, JSON, SHP, GML, GEOTIFF, WCS,'
                                 'WCS100, WCS110, WCS20, WFS, WFS100,'
                                 'WFS110, WFS20, WMS, WMS130, WMS110,'
                                 'WMS100,'
                                 'TEXT, NETCDF')
FORMATS = _FORMATS(
    _FORMAT('application/vnd.geo+json', '.geojson', None),
    _FORMAT('application/json', '.json', None),
    _FORMAT('application/x-zipped-shp', '.zip', None),
    _FORMAT('application/gml+xml', '.gml', None),
    _FORMAT('image/tiff; subtype=geotiff', '.tiff', None),
    _FORMAT('application/xogc-wcs', '.xml', None),
    _FORMAT('application/x-ogc-wcs; version=1.0.0', '.xml', None),
    _FORMAT('application/x-ogc-wcs; version=1.1.0', '.xml', None),
    _FORMAT('application/x-ogc-wcs; version=2.0', '.xml', None),
    _FORMAT('application/x-ogc-wfs', '.xml', None),
    _FORMAT('application/x-ogc-wfs; version=1.0.0', '.xml', None),
    _FORMAT('application/x-ogc-wfs; version=1.1.0', '.xml', None),
    _FORMAT('application/x-ogc-wfs; version=2.0', '.xml', None),
    _FORMAT('application/x-ogc-wms', '.xml', None),
    _FORMAT('application/x-ogc-wms; version=1.3.0', '.xml', None),
    _FORMAT('application/x-ogc-wms; version=1.1.0', '.xml', None),
    _FORMAT('application/x-ogc-wms; version=1.0.0', '.xml', None),
    _FORMAT('text/plain', '.txt', None),
    _FORMAT('application/x-netcdf', '.nc', None),
)


def _get_mimetypes():
    """Add FORMATS to system wide mimetypes
    """
    mimetypes.init()
    for pywps_format in FORMATS:
        mimetypes.add_type(pywps_format.mime_type, pywps_format.extension, True)


_get_mimetypes()


class Format(object):
    """Input/output format specification

    Predefined Formats are stored in :class:`pywps.inout.formats.FORMATS`

    :param str mime_type: mimetype definition
    :param str schema: xml schema definition
    :param str encoding: base64 or not
    :param function validate: function, which will perform validation. e.g.
    :param number mode: validation mode
    :param str extension: file extension
    """

    def __init__(self, mime_type,
                 schema=None, encoding=None,
                 validate=emptyvalidator, mode=MODE.SIMPLE,
                 extension=None):
        """Constructor
        """

        self._mime_type = None
        self._encoding = None
        self._schema = None

        self.mime_type = mime_type
        self.encoding = encoding
        self.schema = schema
        self.validate = validate
        self.extension = extension

    @property
    def mime_type(self):
        """Get format mime type
        :rtype: String
        """

        return self._mime_type

    @mime_type.setter
    def mime_type(self, mime_type):
        """Set format mime type
        """
        try:
            # support Format('GML')
            formatdef = getattr(FORMATS, mime_type)
            self._mime_type = formatdef.mime_type
        except AttributeError:
            # if we don't have this as a shortcut, assume it's a real mime type
            self._mime_type = mime_type

    @property
    def encoding(self):
        """Get format encoding
        :rtype: String
        """

        if self._encoding:
            return self._encoding
        else:
            return ''

    @encoding.setter
    def encoding(self, encoding):
        """Set format encoding
        """

        self._encoding = encoding

    @property
    def schema(self):
        """Get format schema
        :rtype: String
        """
        if self._schema:
            return self._schema
        else:
            return ''

    @schema.setter
    def schema(self, schema):
        """Set format schema
        """
        self._schema = schema

    def same_as(self, frmt):
        """Check input frmt, if it seems to be the same as self
        """
        return all([frmt.mime_type == self.mime_type,
                    frmt.encoding == self.encoding,
                    frmt.schema == self.schema])

    def describe_xml(self):
        """Return describe process response element
        """

        elmar = ElementMaker()
        doc = elmar.Format(
            elmar.MimeType(self.mime_type)
        )

        if self.encoding:
            doc.append(elmar.Encoding(self.encoding))

        if self.schema:
            doc.append(elmar.Schema(self.schema))

        return doc

    @property
    def json(self):
        """Get format as json
        :rtype: dict
        """
        return {
            'mime_type': self.mime_type,
            'encoding': self.encoding,
            'schema': self.schema,
            'extension': self.extension
        }

    @json.setter
    def json(self, jsonin):
        """Set format from json
        :param jsonin:
        """

        self.mime_type = jsonin['mime_type']
        self.encoding = jsonin['encoding']
        self.schema = jsonin['schema']
        self.extension = jsonin['extension']


def get_format(frmt, validator=None):
    """Return Format instance based on given pywps.inout.FORMATS keyword
    """
    # TODO this should be probably removed, it's used only in tests

    outfrmt = None

    if frmt in FORMATS._asdict():
        formatdef = FORMATS._asdict()[frmt]
        outfrmt = Format(**formatdef._asdict())
        outfrmt.validate = validator
        return outfrmt
    else:
        return Format('None', validate=validator)