forked from geopython/pywps
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Exceptions.py
159 lines (137 loc) · 5.56 KB
/
Exceptions.py
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
"""Exception classes of WPS """
# Author: Jachym Cepicky
# http://les-ejk.cz
# Lince:
#
# Web Processing Service implementation
# Copyright (C) 2006 Jachym Cepicky
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
from xml.dom.minidom import Document
import pywps
from re import escape
from pywps.Soap import SOAP
import pywps.Soap
import sys
from xml.sax.saxutils import escape as xml_text_escape
called = 0
class WPSException(Exception):
"""WPSException should be base class for all exceptions
"""
code = "NoApplicableCode"
value = None
locator = None
def _make_xml(self):
# formulate XML
self.document = Document()
self.ExceptionReport = self.document.createElementNS("http://www.opengis.net/ows","ExceptionReport")
self.ExceptionReport.setAttribute("xmlns","http://www.opengis.net/ows/1.1")
self.ExceptionReport.setAttribute("xmlns:xsi","http://www.w3.org/2001/XMLSchema-instance")
self.ExceptionReport.setAttribute("xsi:schemaLocation","http://www.opengis.net/ows/1.1 http://schemas.opengis.net/ows/1.1.0/owsExceptionReport.xsd")
self.ExceptionReport.setAttribute("version","1.0.0")
self.document.appendChild(self.ExceptionReport)
# make exception
self.Exception = self.document.createElement("Exception")
self.Exception.setAttribute("exceptionCode",self.code)
if self.locator:
self.Exception.setAttribute("locator",self.locator)
self.ExceptionReport.appendChild(self.Exception)
#self.value = None
def getResponse(self):
return self.document.toprettyxml(indent='\t', newl='\n', encoding="utf-8")
if pywps.Soap.soap == True:
soapCls = SOAP()
response = soapCls.getResponse(response)
def __str__(self):
error = "PyWPS %s: Locator: %s; Value: %s\n" % (self.code, self.locator, self.value)
try:
logFile.write(error)
except:
sys.stderr.write(error)
return self.document.toprettyxml(indent='\t', newl='\n', encoding="utf-8")
class MissingParameterValue(WPSException):
"""MissingParameterValue WPS Exception"""
def __init__(self, value):
self.code = "MissingParameterValue"
self.locator = str(value)
self._make_xml()
class InvalidParameterValue(WPSException):
"""InvalidParameterValue WPS Exception"""
def __init__(self,value):
self.code = "InvalidParameterValue"
self.locator = str(value)
self._make_xml()
class NoApplicableCode(WPSException):
"""NoApplicableCode WPS Exception"""
def __init__(self,value=None):
WPSException.__init__(self,value)
self.code = "NoApplicableCode"
self.value = None
self._make_xml()
self.message = value
if value:
self.ExceptionText = self.document.createElement("ExceptionText")
self.ExceptionText.appendChild(self.document.createTextNode(repr(value)))
self.Exception.appendChild(self.ExceptionText)
self.value = xml_text_escape(value)
class VersionNegotiationFailed(WPSException):
"""VersionNegotiationFailed WPS Exception"""
def __init__(self,value=None):
self.code = "VersionNegotiationFailed"
self.locator = None
self._make_xml()
if value:
self.ExceptionText = self.document.createElement("ExceptionText")
self.ExceptionText.appendChild(self.document.createTextNode(value))
self.Exception.appendChild(self.ExceptionText)
self.value = str(value)
class NotEnoughStorage(WPSException):
"""NotEnoughStorage WPS Exception"""
def __init__(self,value=None):
self.code = "NotEnoughStorage"
self.locator = value
self._make_xml()
class StorageNotSupported(WPSException):
"""StorageNotSupported WPS Exception"""
def __init__(self,value=None):
self.code = "StorageNotSupported"
self.locator = value
self._make_xml()
class ServerBusy(WPSException):
"""ServerBusy WPS Exception"""
def __init__(self,value=None):
self.code = "ServerBusy"
self.value = value
self._make_xml()
class FileSizeExceeded(WPSException):
"""FileSizeExceeded WPS Exception"""
def __init__(self,value=None):
self.code = "FileSizeExceeded"
self.locator = str(value)
self._make_xml()
class ServerError(WPSException):
"""ServerError WPS Exception
.. note:: This is custom PyWPS exception and should not be used."""
def __init__(self,value=None):
raise NoApplicableCode(value)
self.code = "ServerError"
try:
self.locator = str(value)
except:
self.locator = None
self._make_xml()
self.ExceptionText = self.document.createElement("ExceptionText")
self.ExceptionText.appendChild(self.document.createTextNode("General server error"))
self.Exception.appendChild(self.ExceptionText)