Ejemplo n.º 1
0
    def _test_outout(self, source_type):
        """Test all outputs"""

        self.assertEqual(source_type, self.iohandler.source_type,
                         'Source type properly set')

        self.assertEqual(self._value, self.iohandler.data, 'Data obtained')

        if self.iohandler.source_type == SOURCE_TYPE.STREAM:
            source = StringIO(text_type(self._value))
            self.iohandler.stream = source

        file_handler = open(self.iohandler.file)
        self.assertEqual(self._value, file_handler.read(), 'File obtained')
        file_handler.close()

        if self.iohandler.source_type == SOURCE_TYPE.STREAM:
            source = StringIO(text_type(self._value))
            self.iohandler.stream = source

        stream_val = self.iohandler.stream.read()
        if type(stream_val) == type(b''):
            self.assertEqual(str.encode(self._value), stream_val,
                             'Stream obtained')
        else:
            self.assertEqual(self._value, stream_val, 'Stream obtained')
        self.iohandler.stream.close()

        if self.iohandler.source_type == SOURCE_TYPE.STREAM:
            source = StringIO(text_type(self._value))
            self.iohandler.stream = source

        self.skipTest('Memory object not implemented')
        self.assertEqual(data, self.iohandler.memory_object,
                         'Memory object obtained')
Ejemplo n.º 2
0
    def set_data(self, data):
        """Set data value. input data are converted into target format
        """
        if self.data_type:
            # TODO: check datatypeabstract class somethings missing here
            # check if it is a valid data_type
            if self.data_type.lower() in LITERAL_DATA_TYPES:
                if self.data_type.lower() == "string":
                    data = text_type(data)
                elif self.data_type.lower() == "integer":
                    data = int(data)
                elif self.data_type.lower() == "float":
                    data = float(data)
                elif self.data_type.lower() == "boolean":
                    if data.lower() == "true":
                        data = True
                    else:
                        data = False
                # data = self.data_type.convert(data)

                _valid = self.validator(self, self.valid_mode)
                if not _valid:
                    raise InvalidParameterValue("Input data not valid using " "mode %s" % (self.valid_mode))

                IOHandler.set_data(self, data)
Ejemplo n.º 3
0
def get_inputs_from_xml(doc):
    the_inputs = {}
    for input_el in xpath_ns(doc, '/wps:Execute/wps:DataInputs/wps:Input'):
        [identifier_el] = xpath_ns(input_el, './ows:Identifier')
        identifier = identifier_el.text

        if identifier not in the_inputs:
            the_inputs[identifier] = []

        literal_data = xpath_ns(input_el, './wps:Data/wps:LiteralData')
        if literal_data:
            value_el = literal_data[0]
            inpt = {}
            inpt['identifier'] = identifier_el.text
            inpt['data'] = text_type(value_el.text)
            inpt['uom'] = value_el.attrib.get('uom', '')
            inpt['datatype'] = value_el.attrib.get('datatype', '')
            the_inputs[identifier].append(inpt)
            continue

        complex_data = xpath_ns(input_el, './wps:Data/wps:ComplexData')
        if complex_data:
            complex_data_el = complex_data[0]
            inpt = {}
            inpt['identifier'] = identifier_el.text
            if len(complex_data_el.getchildren()) > 0:
                value_el = complex_data_el[0]
                inpt['data'] = _get_dataelement_value(value_el)
            else:
                inpt['data'] = _get_rawvalue_value(complex_data_el.text)
            inpt['mimeType'] = complex_data_el.attrib.get('mimeType', '')
            inpt['encoding'] = complex_data_el.attrib.get('encoding', '')
            inpt['schema'] = complex_data_el.attrib.get('schema', '')
            inpt['method'] = complex_data_el.attrib.get('method', 'GET')
            the_inputs[identifier].append(inpt)
            continue

        reference_data = xpath_ns(input_el, './wps:Reference')
        if reference_data:
            reference_data_el = reference_data[0]
            inpt = {}
            inpt['identifier'] = identifier_el.text
            inpt[identifier_el.text] = reference_data_el.text
            inpt['href'] = reference_data_el.attrib.get(
                '{http://www.w3.org/1999/xlink}href', '')
            inpt['mimeType'] = reference_data_el.attrib.get('mimeType', '')
            the_inputs[identifier].append(inpt)
            continue

        # OWSlib is not python 3 compatible yet
        if PY2:
            from owslib.ows import BoundingBox
            bbox_datas = xpath_ns(input_el, './wps:Data/wps:BoundingBoxData')
            if bbox_datas:
                for bbox_data in bbox_datas:
                    bbox_data_el = bbox_data
                    bbox = BoundingBox(bbox_data_el)
                    the_inputs[identifier].append(bbox)

    return the_inputs
Ejemplo n.º 4
0
    def execute_xml(self):
        doc = WPS.Output(
            OWS.Identifier(self.identifier),
            OWS.Title(self.title)
        )

        if self.abstract:
            doc.append(OWS.Abstract(self.abstract))

        data_doc = WPS.Data()

        literal_data_doc = WPS.LiteralData(text_type(self.data))
        literal_data_doc.attrib['dataType'] = self.data_type
        literal_data_doc.attrib['reference'] = XMLSCHEMA_2 + self.data_type
        if self.uom:
            default_uom_element = self.uom[0].describe_xml()
            supported_uom_elements = [u.describe_xml() for u in self.uom]

            literal_data_doc.append(
                E.UOMs(
                    E.Default(default_uom_element),
                    E.Supported(*supported_uom_elements)
                )
            )
        data_doc.append(literal_data_doc)

        doc.append(data_doc)

        return doc
Ejemplo n.º 5
0
    def set_data(self, data):
        """Set data value. input data are converted into target format
        """
        if self.data_type:
            # TODO: check datatypeabstract class somethings missing here
            # check if it is a valid data_type
            if self.data_type.lower() in LITERAL_DATA_TYPES:
                if self.data_type.lower() == 'string':
                    data = text_type(data)
                elif self.data_type.lower() == 'integer':
                    data = int(data)
                elif self.data_type.lower() == 'float':
                    data = float(data)
                elif self.data_type.lower() == 'boolean':
                    if data.lower() == 'true':
                        data = True
                    else:
                        data = False
                #data = self.data_type.convert(data)

                _valid = self.validator(self, self.valid_mode)
                if not _valid:
                    raise InvalidParameterValue('Input data not valid using '
                                                'mode %s' % (self.valid_mode))

                IOHandler.set_data(self, data)
Ejemplo n.º 6
0
def get_input_from_xml(doc):
    the_input = MultiDict()
    for input_el in xpath_ns(doc, '/wps:Execute/wps:DataInputs/wps:Input'):
        [identifier_el] = xpath_ns(input_el, './ows:Identifier')
        [value_el] = xpath_ns(input_el, './wps:Data/wps:LiteralData')
        the_input.update({identifier_el.text: text_type(value_el.text)})
    return the_input
Ejemplo n.º 7
0
def get_inputs_from_xml(doc):
    the_inputs = {}
    for input_el in xpath_ns(doc, '/wps:Execute/wps:DataInputs/wps:Input'):
        [identifier_el] = xpath_ns(input_el, './ows:Identifier')
        identifier = identifier_el.text

        if identifier not in the_inputs:
            the_inputs[identifier] = []

        literal_data = xpath_ns(input_el, './wps:Data/wps:LiteralData')
        if literal_data:
            value_el = literal_data[0]
            inpt = {}
            inpt['identifier'] = identifier_el.text
            inpt['data'] = text_type(value_el.text)
            inpt['uom'] = value_el.attrib.get('uom', '')
            inpt['datatype'] = value_el.attrib.get('datatype', '')
            the_inputs[identifier].append(inpt)
            continue

        complex_data = xpath_ns(input_el, './wps:Data/wps:ComplexData')
        if complex_data:
            complex_data_el = complex_data[0]
            inpt = {}
            inpt['identifier'] = identifier_el.text
            if len(complex_data_el.getchildren()) > 0:
                value_el = complex_data_el[0]
                inpt['data'] = _get_dataelement_value(value_el)
            else:
                inpt['data'] = _get_rawvalue_value(complex_data_el.text)
            inpt['mimeType'] = complex_data_el.attrib.get('mimeType', '')
            inpt['encoding'] = complex_data_el.attrib.get('encoding', '')
            inpt['schema'] = complex_data_el.attrib.get('schema', '')
            inpt['method'] = complex_data_el.attrib.get('method', 'GET')
            the_inputs[identifier].append(inpt)
            continue

        reference_data = xpath_ns(input_el, './wps:Reference')
        if reference_data:
            reference_data_el = reference_data[0]
            inpt = {}
            inpt['identifier'] = identifier_el.text
            inpt[identifier_el.text] = reference_data_el.text
            inpt['href'] = reference_data_el.attrib.get('{http://www.w3.org/1999/xlink}href', '')
            inpt['mimeType'] = reference_data_el.attrib.get('mimeType', '')
            the_inputs[identifier].append(inpt)
            continue

        # OWSlib is not python 3 compatible yet
        if PY2:
            from owslib.ows import BoundingBox
            bbox_datas = xpath_ns(input_el, './wps:Data/wps:BoundingBoxData')
            if bbox_datas:
                for bbox_data in bbox_datas:
                    bbox_data_el = bbox_data
                    bbox = BoundingBox(bbox_data_el)
                    the_inputs[identifier].append(bbox)

    return the_inputs
Ejemplo n.º 8
0
 def get_stream(self):
     """Get source as stream object"""
     if self.source_type == SOURCE_TYPE.FILE:
         from io import FileIO
         return FileIO(self.source, mode='r', closefd=True)
     elif self.source_type == SOURCE_TYPE.STREAM:
         return self.source
     elif self.source_type == SOURCE_TYPE.DATA:
         return StringIO(text_type(self.source))
Ejemplo n.º 9
0
 def get_stream(self):
     """Get source as stream object"""
     if self.source_type == SOURCE_TYPE.FILE:
         from io import FileIO
         return FileIO(self.source, mode='r', closefd=True)
     elif self.source_type == SOURCE_TYPE.STREAM:
         return self.source
     elif self.source_type == SOURCE_TYPE.DATA:
         return StringIO(text_type(self.source))
Ejemplo n.º 10
0
    def _test_outout(self, source_type, suffix=''):
        """Test all outputs"""

        self.assertEqual(source_type, self.iohandler.source_type,
                         'Source type properly set')

        self.assertEqual(self._value, self.iohandler.data, 'Data obtained')

        if self.iohandler.source_type == SOURCE_TYPE.URL:
            self.assertEqual('http', urlparse(self.iohandler.url).scheme)
        else:
            self.assertEqual('file', urlparse(self.iohandler.url).scheme)

        if self.iohandler.source_type == SOURCE_TYPE.STREAM:
            source = StringIO(text_type(self._value))
            self.iohandler.stream = source

        file_path = self.iohandler.file
        self.assertTrue(file_path.endswith(suffix))
        file_handler = open(file_path)
        self.assertEqual(self._value, file_handler.read(), 'File obtained')
        file_handler.close()

        if self.iohandler.source_type == SOURCE_TYPE.STREAM:
            source = StringIO(text_type(self._value))
            self.iohandler.stream = source

        stream_val = self.iohandler.stream.read()
        self.iohandler.stream.close()

        if PY2 and isinstance(stream_val, str):
            self.assertEqual(self._value, stream_val.decode('utf-8'),
                             'Stream obtained')
        elif not PY2 and isinstance(stream_val, bytes):
            self.assertEqual(self._value, stream_val.decode('utf-8'),
                             'Stream obtained')
        else:
            self.assertEqual(self._value, stream_val,
                             'Stream obtained')

        if self.iohandler.source_type == SOURCE_TYPE.STREAM:
            source = StringIO(text_type(self._value))
            self.iohandler.stream = source
Ejemplo n.º 11
0
    def _test_outout(self, source_type, suffix=''):
        """Test all outputs"""

        self.assertEqual(source_type, self.iohandler.source_type,
                         'Source type properly set')

        self.assertEqual(self._value, self.iohandler.data, 'Data obtained')

        if self.iohandler.source_type == SOURCE_TYPE.URL:
            self.assertEqual('http', urlparse(self.iohandler.url).scheme)
        else:
            self.assertEqual('file', urlparse(self.iohandler.url).scheme)

        if self.iohandler.source_type == SOURCE_TYPE.STREAM:
            source = StringIO(text_type(self._value))
            self.iohandler.stream = source

        file_path = self.iohandler.file
        self.assertTrue(file_path.endswith(suffix))
        file_handler = open(file_path)
        self.assertEqual(self._value, file_handler.read(), 'File obtained')
        file_handler.close()

        if self.iohandler.source_type == SOURCE_TYPE.STREAM:
            source = StringIO(text_type(self._value))
            self.iohandler.stream = source

        stream_val = self.iohandler.stream.read()
        self.iohandler.stream.close()

        if PY2 and isinstance(stream_val, str):
            self.assertEqual(self._value, stream_val.decode('utf-8'),
                             'Stream obtained')
        elif not PY2 and isinstance(stream_val, bytes):
            self.assertEqual(self._value, stream_val.decode('utf-8'),
                             'Stream obtained')
        else:
            self.assertEqual(self._value, stream_val,
                             'Stream obtained')

        if self.iohandler.source_type == SOURCE_TYPE.STREAM:
            source = StringIO(text_type(self._value))
            self.iohandler.stream = source
Ejemplo n.º 12
0
    def get_input_from_xml(doc):
        the_input = {}
        for input_el in xpath_ns(doc, '/wps:Execute/wps:DataInputs/wps:Input'):
            [identifier_el] = xpath_ns(input_el, './ows:Identifier')

            literal_data = xpath_ns(input_el, './wps:Data/wps:LiteralData')
            if literal_data:
                value_el = literal_data[0]
                inpt = {}
                inpt['identifier'] = identifier_el.text
                inpt['data'] = text_type(value_el.text)
                inpt['uom'] = value_el.attrib.get('uom', '')
                inpt['datatype'] = value_el.attrib.get('datatype', '')
                the_input[identifier_el.text] = inpt
                continue

            complex_data = xpath_ns(input_el, './wps:Data/wps:ComplexData')
            if complex_data:
                complex_data_el = complex_data[0]
                value_el = complex_data_el[0]
                inpt = {}
                inpt['identifier'] = identifier_el.text
                inpt['data'] = value_el
                inpt['mime_type'] = complex_data_el.attrib.get('mimeType', '')
                inpt['encoding'] = complex_data_el.attrib.get('encoding', '')
                inpt['schema'] = complex_data_el.attrib.get('schema', '')
                inpt['method'] = complex_data_el.attrib.get('method', 'GET')
                the_input[identifier_el.text] = inpt
                continue

            reference_data = xpath_ns(input_el, './wps:Reference')
            if reference_data:
                reference_data_el = reference_data[0]
                inpt = {}
                inpt['identifier'] = identifier_el.text
                inpt[identifier_el.text] = reference_data_el.text
                inpt['href'] = reference_data_el.attrib.get('href', '')
                if not inpt['href']:
                    inpt['href'] = reference_data_el.attrib.get('{http://www.w3.org/1999/xlink}href', '')
                inpt['mimeType'] = reference_data_el.attrib.get('mimeType', '')
                the_input[identifier_el.text] = inpt
                continue

            # OWSlib is not python 3 compatible yet
            if PY2:
                from owslib.ows import BoundingBox

                bbox_data = xpath_ns(input_el, './wps:Data/wps:BoundingBoxData')
                if bbox_data:
                    bbox_data_el = bbox_data[0]
                    bbox = BoundingBox(bbox_data_el)
                    the_input.update({identifier_el.text: bbox})
                    continue

        return the_input
Ejemplo n.º 13
0
 def get_stream(self):
     """Get source as stream object"""
     if self.source_type == SOURCE_TYPE.FILE:
         if self._stream and not self._stream.closed:
             self._stream.close()
         from io import FileIO
         self._stream = FileIO(self.source, mode='r', closefd=True)
         return self._stream
     elif self.source_type == SOURCE_TYPE.STREAM:
         return self.source
     elif self.source_type == SOURCE_TYPE.DATA:
         return StringIO(text_type(self.source))
Ejemplo n.º 14
0
 def get_stream(self):
     """Get source as stream object"""
     if self.source_type == SOURCE_TYPE.FILE:
         if self._stream and not self._stream.closed:
             self._stream.close()
         from io import FileIO
         self._stream = FileIO(self.source, mode='r', closefd=True)
         return self._stream
     elif self.source_type == SOURCE_TYPE.STREAM:
         return self.source
     elif self.source_type == SOURCE_TYPE.DATA:
         return StringIO(text_type(self.source))
Ejemplo n.º 15
0
    def _test_outout(self, source_type, suffix=''):
        """Test all outputs"""

        self.assertEqual(source_type, self.iohandler.source_type,
                          'Source type properly set')

        self.assertEqual(self._value, self.iohandler.data, 'Data obtained')

        if self.iohandler.source_type == SOURCE_TYPE.STREAM:
            source = StringIO(text_type(self._value))
            self.iohandler.stream = source

        file_path = self.iohandler.file
        self.assertTrue(file_path.endswith(suffix))
        file_handler = open(file_path)
        self.assertEqual(self._value, file_handler.read(), 'File obtained')
        file_handler.close()

        if self.iohandler.source_type == SOURCE_TYPE.STREAM:
            source = StringIO(text_type(self._value))
            self.iohandler.stream = source

        stream_val = self.iohandler.stream.read()
        self.iohandler.stream.close()

        if type(stream_val) == type(b''):
            self.assertEqual(str.encode(self._value), stream_val,
                             'Stream obtained')
        else:
            self.assertEqual(self._value, stream_val,
                             'Stream obtained')

        if self.iohandler.source_type == SOURCE_TYPE.STREAM:
            source = StringIO(text_type(self._value))
            self.iohandler.stream = source

        self.skipTest('Memory object not implemented')
        self.assertEqual(stream_val, self.iohandler.memory_object,
                         'Memory object obtained')
Ejemplo n.º 16
0
    def execute_xml(self):
        doc = WPS.Output(OWS.Identifier(self.identifier),
                         OWS.Title(self.title))

        if self.abstract:
            doc.append(OWS.Abstract(self.abstract))

        data_doc = WPS.Data()

        literal_data_doc = WPS.LiteralData(text_type(self.data))
        literal_data_doc.attrib['dataType'] = OGCTYPE[self.data_type]
        if self.uom:
            literal_data_doc.attrib['uom'] = self.uom.execute_attribute()
        data_doc.append(literal_data_doc)

        doc.append(data_doc)

        return doc
Ejemplo n.º 17
0
    def execute_xml(self):
        doc = WPS.Output(
            OWS.Identifier(self.identifier),
            OWS.Title(self.title)
        )

        if self.abstract:
            doc.append(OWS.Abstract(self.abstract))

        data_doc = WPS.Data()

        literal_data_doc = WPS.LiteralData(text_type(self.data))
        literal_data_doc.attrib['dataType'] = OGCTYPE[self.data_type]
        if self.uom:
            literal_data_doc.attrib['uom'] = self.uom.execute_attribute()
        data_doc.append(literal_data_doc)

        doc.append(data_doc)

        return doc
Ejemplo n.º 18
0
    def set_data(self, data):
        """Set data value. input data are converted into target format
        """
        if self.data_type:
            # TODO: check datatypeabstract class somethings missing here
            # check if it is a valid data_type
            if self.data_type.lower() in LITERAL_DATA_TYPES:
                if self.data_type.lower() == 'string':
                    data = text_type(data)
                elif self.data_type.lower() == 'integer':
                    data = int(data)
                elif self.data_type.lower() == 'float':
                    data = float(data)
                elif self.data_type.lower() == 'boolean':
                    if data.lower() == 'true':
                        data = True
                    else:
                        data = False
                #data = self.data_type.convert(data)

                IOHandler.set_data(self, data)
Ejemplo n.º 19
0
def get_input_from_xml(doc):
    the_input = MultiDict()
    for input_el in xpath_ns(doc, '/wps:Execute/wps:DataInputs/wps:Input'):
        [identifier_el] = xpath_ns(input_el, './ows:Identifier')

        literal_data = xpath_ns(input_el, './wps:Data/wps:LiteralData')
        if literal_data:
            value_el = literal_data[0]
            the_input.update({identifier_el.text: text_type(value_el.text)})
            continue

        complex_data = xpath_ns(input_el, './wps:Data/wps:ComplexData')
        if complex_data:
            complex_data_el = complex_data[0]
            value_el = complex_data_el[0]
            tmp = StringIO(lxml.etree.tounicode(value_el))
            tmp.mime_type = complex_data_el.attrib.get('mimeType')
            the_input.update({identifier_el.text: tmp})
            continue

        # TODO bounding box data

    return the_input
Ejemplo n.º 20
0
def get_input_from_xml(doc):
    the_input = MultiDict()
    for input_el in xpath_ns(doc, '/wps:Execute/wps:DataInputs/wps:Input'):
        [identifier_el] = xpath_ns(input_el, './ows:Identifier')

        literal_data = xpath_ns(input_el, './wps:Data/wps:LiteralData')
        if literal_data:
            value_el = literal_data[0]
            the_input.update({identifier_el.text: text_type(value_el.text)})
            continue

        complex_data = xpath_ns(input_el, './wps:Data/wps:ComplexData')
        if complex_data:
            complex_data_el = complex_data[0]
            value_el = complex_data_el[0]
            tmp = StringIO(lxml.etree.tounicode(value_el))
            tmp.mime_type = complex_data_el.attrib.get('mimeType')
            the_input.update({identifier_el.text: tmp})
            continue

        # TODO bounding box data

    return the_input
Ejemplo n.º 21
0
 def stream(self):
     """Return a stream representation of the data."""
     if not PY2 and isinstance(self.data, bytes):
         return BytesIO(self.data)
     else:
         return StringIO(text_type(self.data))
Ejemplo n.º 22
0
def get_inputs_from_xml(doc):
    the_inputs = {}
    version = get_version_from_ns(doc.nsmap[doc.prefix])
    xpath_ns = get_xpath_ns(version)
    for input_el in xpath_ns(doc, '/wps:Execute/wps:DataInputs/wps:Input'):
        [identifier_el] = xpath_ns(input_el, './ows:Identifier')
        identifier = identifier_el.text

        if identifier not in the_inputs:
            the_inputs[identifier] = []

        literal_data = xpath_ns(input_el, './wps:Data/wps:LiteralData')
        if literal_data:
            value_el = literal_data[0]
            inpt = {}
            inpt['identifier'] = identifier_el.text
            inpt['data'] = text_type(value_el.text)
            inpt['uom'] = value_el.attrib.get('uom', '')
            inpt['datatype'] = value_el.attrib.get('datatype', '')
            the_inputs[identifier].append(inpt)
            continue

        complex_data = xpath_ns(input_el, './wps:Data/wps:ComplexData')
        if complex_data:

            complex_data_el = complex_data[0]
            inpt = {}
            inpt['identifier'] = identifier_el.text
            inpt['mimeType'] = complex_data_el.attrib.get('mimeType', '')
            inpt['encoding'] = complex_data_el.attrib.get(
                'encoding', '').lower()
            inpt['schema'] = complex_data_el.attrib.get('schema', '')
            inpt['method'] = complex_data_el.attrib.get('method', 'GET')
            if len(complex_data_el.getchildren()) > 0:
                value_el = complex_data_el[0]
                inpt['data'] = _get_dataelement_value(value_el)
            else:
                inpt['data'] = _get_rawvalue_value(
                    complex_data_el.text, inpt['encoding'])
            the_inputs[identifier].append(inpt)
            continue

        reference_data = xpath_ns(input_el, './wps:Reference')
        if reference_data:
            reference_data_el = reference_data[0]
            inpt = {}
            inpt['identifier'] = identifier_el.text
            inpt[identifier_el.text] = reference_data_el.text
            inpt['href'] = reference_data_el.attrib.get(
                '{http://www.w3.org/1999/xlink}href', '')
            inpt['mimeType'] = reference_data_el.attrib.get('mimeType', '')
            inpt['method'] = reference_data_el.attrib.get('method', 'GET')
            header_element = xpath_ns(reference_data_el, './wps:Header')
            if header_element:
                inpt['header'] = _get_reference_header(header_element)
            body_element = xpath_ns(reference_data_el, './wps:Body')
            if body_element:
                inpt['body'] = _get_reference_body(body_element[0])
            bodyreference_element = xpath_ns(reference_data_el,
                                             './wps:BodyReference')
            if bodyreference_element:
                inpt['bodyreference'] = _get_reference_bodyreference(
                    bodyreference_element[0])
            the_inputs[identifier].append(inpt)
            continue

        # Using OWSlib BoundingBox
        from owslib.ows import BoundingBox
        bbox_datas = xpath_ns(input_el, './wps:Data/wps:BoundingBoxData')
        if bbox_datas:
            for bbox_data in bbox_datas:
                bbox_data_el = bbox_data
                bbox = BoundingBox(bbox_data_el)
                the_inputs[identifier].append(bbox)
                LOGGER.debug("parse bbox: {},{},{},{}".format(bbox.minx, bbox.miny, bbox.maxx, bbox.maxy))
    return the_inputs
Ejemplo n.º 23
0
 def stream(self):
     """Return a stream representation of the data."""
     if not PY2 and isinstance(self.data, bytes):
         return BytesIO(self.data)
     else:
         return StringIO(text_type(self.data))
Ejemplo n.º 24
0
def get_inputs_from_xml(doc):
    the_inputs = {}
    version = get_version_from_ns(doc.nsmap[doc.prefix])
    xpath_ns = get_xpath_ns(version)
    for input_el in xpath_ns(doc, '/wps:Execute/wps:DataInputs/wps:Input'):
        [identifier_el] = xpath_ns(input_el, './ows:Identifier')
        identifier = identifier_el.text

        if identifier not in the_inputs:
            the_inputs[identifier] = []

        literal_data = xpath_ns(input_el, './wps:Data/wps:LiteralData')
        if literal_data:
            value_el = literal_data[0]
            inpt = {}
            inpt['identifier'] = identifier_el.text
            inpt['data'] = text_type(value_el.text)
            inpt['uom'] = value_el.attrib.get('uom', '')
            inpt['datatype'] = value_el.attrib.get('datatype', '')
            the_inputs[identifier].append(inpt)
            continue

        complex_data = xpath_ns(input_el, './wps:Data/wps:ComplexData')
        if complex_data:

            complex_data_el = complex_data[0]
            inpt = {}
            inpt['identifier'] = identifier_el.text
            inpt['mimeType'] = complex_data_el.attrib.get('mimeType', '')
            inpt['encoding'] = complex_data_el.attrib.get('encoding',
                                                          '').lower()
            inpt['schema'] = complex_data_el.attrib.get('schema', '')
            inpt['method'] = complex_data_el.attrib.get('method', 'GET')
            if len(complex_data_el.getchildren()) > 0:
                value_el = complex_data_el[0]
                inpt['data'] = _get_dataelement_value(value_el)
            else:
                inpt['data'] = _get_rawvalue_value(complex_data_el.text,
                                                   inpt['encoding'])
            the_inputs[identifier].append(inpt)
            continue

        reference_data = xpath_ns(input_el, './wps:Reference')
        if reference_data:
            reference_data_el = reference_data[0]
            inpt = {}
            inpt['identifier'] = identifier_el.text
            inpt[identifier_el.text] = reference_data_el.text
            inpt['href'] = reference_data_el.attrib.get(
                '{http://www.w3.org/1999/xlink}href', '')
            inpt['mimeType'] = reference_data_el.attrib.get('mimeType', '')
            inpt['method'] = reference_data_el.attrib.get('method', 'GET')
            header_element = xpath_ns(reference_data_el, './wps:Header')
            if header_element:
                inpt['header'] = _get_reference_header(header_element)
            body_element = xpath_ns(reference_data_el, './wps:Body')
            if body_element:
                inpt['body'] = _get_reference_body(body_element[0])
            bodyreference_element = xpath_ns(reference_data_el,
                                             './wps:BodyReference')
            if bodyreference_element:
                inpt['bodyreference'] = _get_reference_bodyreference(
                    bodyreference_element[0])
            the_inputs[identifier].append(inpt)
            continue

        # Using OWSlib BoundingBox
        from owslib.ows import BoundingBox
        bbox_datas = xpath_ns(input_el, './wps:Data/wps:BoundingBoxData')
        if bbox_datas:
            for bbox_data in bbox_datas:
                bbox_data_el = bbox_data
                bbox = BoundingBox(bbox_data_el)
                the_inputs[identifier].append(bbox)
                LOGGER.debug("parse bbox: {},{},{},{}".format(
                    bbox.minx, bbox.miny, bbox.maxx, bbox.maxy))
    return the_inputs
Ejemplo n.º 25
0
 def test_stream(self):
     """Test stream input IOHandler"""
     source = StringIO(text_type(self._value))
     self.iohandler.stream = source
     self._test_outout(SOURCE_TYPE.STREAM)
Ejemplo n.º 26
0
 def test_stream(self):
     """Test stream input IOHandler"""
     source = StringIO(text_type(self._value))
     self.iohandler.stream = source
     self._test_outout(SOURCE_TYPE.STREAM)