Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
except Exception as e:
# This ensure that logged request get terminated in case of exception while the request is not
# accepted
store_status(request_uuid, WPS_STATUS.FAILED, u'Request rejected due to exception', 100)
raise e
else:
raise RuntimeError("Unknown operation %r"
% wps_request.operation)
except NoApplicableCode as e:
return e
except HTTPException as e:
return NoApplicableCode(e.description, code=e.code)
except Exception:
msg = "No applicable error code, please check error log."
return NoApplicableCode(msg, code=500)
"""HTTP GET request parser
"""
# check if input file size was not exceeded
maxsize = configuration.get_config_value('server', 'maxrequestsize')
maxsize = configuration.get_size_mb(maxsize) * 1024 * 1024
if self.http_request.content_length > maxsize:
raise FileSizeExceeded('File size for input exceeded.'
' Maximum request size allowed: %i megabytes' % (maxsize / 1024 / 1024))
try:
doc = lxml.etree.fromstring(self.http_request.get_data())
except Exception as e:
if PY2:
raise NoApplicableCode(e.message)
else:
raise NoApplicableCode(e.msg)
operation = doc.tag
version = get_version_from_ns(doc.nsmap[doc.prefix])
self.set_version(version)
request_parser = self._post_request_parser(operation)
request_parser(doc)
def __call__(self, request):
# This function must return a valid response.
try:
doc = self.get_response_doc()
return xml_response(doc)
except NoApplicableCode as e:
return e
except Exception as e:
return NoApplicableCode(str(e))
response = self.execute(
wps_request.identifier,
wps_request,
request_uuid
)
return response
except Exception as e:
# This ensure that logged request get terminated in case of exception while the request is not
# accepted
store_status(request_uuid, WPS_STATUS.FAILED, u'Request rejected due to exception', 100)
raise e
else:
raise RuntimeError("Unknown operation %r"
% wps_request.operation)
except NoApplicableCode as e:
return e
except HTTPException as e:
return NoApplicableCode(e.description, code=e.code)
except Exception:
msg = "No applicable error code, please check error log."
return NoApplicableCode(msg, code=500)
def __init__(self, http_request):
self.http_request = http_request
if http_request.method == 'GET':
# WSDL request
wsdl = self._get_get_param('WSDL')
if wsdl is not None:
# TODO: fix #57 then remove the exception
raise NoApplicableCode('WSDL not implemented')
# service shall be WPS
service = self._get_get_param('service', aslist=False)
if service:
if str(service).lower() != 'wps':
raise OperationNotSupported(
'parameter SERVICE [%s] not supported' % service)
else:
raise MissingParameterValue('service', 'service')
# operation shall be one of GetCapabilities, DescribeProcess,
# Execute
self.operation = self._get_get_param('request',
aslist=False)
if not self.operation:
return self.get_capabilities()
elif wps_request.operation == 'describeprocess':
return self.describe(wps_request.identifiers)
elif wps_request.operation == 'execute':
return self.execute(wps_request.identifier, wps_request)
else:
raise RuntimeError("Unknown operation %r"
% wps_request.operation)
except HTTPException as e:
# transform HTTPException to OWS NoApplicableCode exception
if not isinstance(e, NoApplicableCode):
e = NoApplicableCode(e.description, code=e.code)
return e
def __call__(self, request):
if self.wps_request.raw:
if self.status == WPS_STATUS.FAILED:
return NoApplicableCode(self.message)
else:
wps_output_identifier = next(iter(self.wps_request.outputs)) # get the first key only
wps_output_value = self.outputs[wps_output_identifier]
if wps_output_value.source_type is None:
return NoApplicableCode("Expected output was not generated")
return Response(wps_output_value.data,
mimetype=self.wps_request.outputs[wps_output_identifier].get('mimetype', None))
else:
if not self.doc:
return NoApplicableCode("Output was not generated")
return Response(self.doc, mimetype='text/xml')
if wps_request.operation == 'getcapabilities':
return self.get_capabilities()
elif wps_request.operation == 'describeprocess':
return self.describe(wps_request.identifiers)
elif wps_request.operation == 'execute':
return self.execute(wps_request.identifier, wps_request)
else:
raise RuntimeError("Unknown operation %r"
% wps_request.operation)
except HTTPException as e:
# transform HTTPException to OWS NoApplicableCode exception
if not isinstance(e, NoApplicableCode):
e = NoApplicableCode(e.description, code=e.code)
return e
}
)
class FileURLNotSupported(NoApplicableCode):
"""File URL not supported exception implementation
"""
code = 400
description = 'File URL not supported as input.'
def __init__(self, description="", locator="", code=400):
description = description or self.description
NoApplicableCode.__init__(self, description=description, locator=locator, code=code)
class SchedulerNotAvailable(NoApplicableCode):
"""Job scheduler not available exception implementation
"""
code = 400
dbase = os.path.dirname(self.grass_location)
location = os.path.basename(self.grass_location)
grass.run_command('g.gisenv', set="GISDBASE={}".format(dbase))
grass.run_command('g.gisenv', set="LOCATION_NAME=%s" % location)
while os.path.isdir(os.path.join(dbase, location, mapset_name)):
mapset_name = 'pywps_ms_{}'.format(
''.join(random.sample(string.ascii_letters, 5)))
make_mapset(mapset=mapset_name, location=location,
gisdbase=dbase)
grass.run_command('g.gisenv', set="MAPSET=%s" % mapset_name)
else:
raise NoApplicableCode('Location does exists or does not seem '
'to be in "EPSG:XXXX" form nor is it existing directory: {}'.format(location))
# set _grass_mapset attribute - will be deleted once handler ends
self._grass_mapset = mapset_name
# final initialization
LOGGER.debug('GRASS Mapset set to {}'.format(mapset_name))
LOGGER.debug('GRASS environment initialised')
LOGGER.debug('GISRC {}, GISBASE {}, GISDBASE {}, LOCATION {}, MAPSET {}'.format(
os.environ.get('GISRC'), os.environ.get('GISBASE'),
dbase, location, os.path.basename(mapset_name)))