Package eoxserver :: Package services :: Package ows :: Package wcst :: Module wcst11Exception
[hide private]
[frames] | no frames]

Source Code for Module eoxserver.services.ows.wcst.wcst11Exception

  1  #----------------------------------------------------------------------- 
  2  # $Id: wcst11Exception.py 1031 2011-12-27 15:30:26Z meissls $ 
  3  # 
  4  # Description:  
  5  # 
  6  #   WCSt 1.1 Exceptions   
  7  # 
  8  #------------------------------------------------------------------------------- 
  9  # 
 10  # Project: EOxServer <http://eoxserver.org> 
 11  # Authors: Martin Paces <martin.paces@iguassu.cz> 
 12  # 
 13  #------------------------------------------------------------------------------- 
 14  # Copyright (C) 2011 Iguassu Software Systems, a.s  
 15  # 
 16  # Permission is hereby granted, free of charge, to any person obtaining a copy 
 17  # of this software and associated documentation files (the "Software"), to deal 
 18  # in the Software without restriction, including without limitation the rights 
 19  # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell  
 20  # copies of the Software, and to permit persons to whom the Software is  
 21  # furnished to do so, subject to the following conditions: 
 22  # 
 23  # The above copyright notice and this permission notice shall be included in all 
 24  # copies of this Software or works derived from this Software. 
 25  # 
 26  # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 
 27  # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 
 28  # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 
 29  # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 
 30  # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 
 31  # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 
 32  # THE SOFTWARE. 
 33  #------------------------------------------------------------------------------- 
 34   
 35  LANG="en" 
 36   
 37  #======================================================= 
 38  # base exception  
 39   
40 -class OWS11_Exception( Exception ) :
41 """ base WPS exception """
42 - def __init__( self , locator = None , message = None ) :
43 self.locator = locator 44 self.message = message 45 self.msg = unicode( self ) 46
47 - def getCode( self ) :
48 return self.__class__.__name__[2:] 49
50 - def __str__( self ) :
51 return unicode( self ).encode("UTF-8") 52
53 - def __unicode__( self ) :
54 t = [ u"code=%s" % self.getCode() ] 55 if self.locator is not None : t.append(u"locator=%s"%self.locator) 56 if self.message is not None : t.append(u"message=%s"%self.message) 57 return "OWS11_Exception{%s}"%(";".join(t) ) 58 59 #======================================================= 60 # specific WPS exceptions 61 62 # no locator exceptions
63 -class ExServerBusy( OWS11_Exception ):
64 - def __init__( self ): pass
65
66 -class ExNotEnoughStorage( OWS11_Exception ):
67 - def __init__( self ): pass
68 69 # locator holding exceptions 70
71 -class ExInvalidParameterValue( OWS11_Exception ):
72 - def __init__( self , locator ):
73 OWS11_Exception.__init__( self , locator = locator )
74
75 -class ExMissingParameterValue( OWS11_Exception ):
76 - def __init__( self , locator ):
77 OWS11_Exception.__init__( self , locator = locator )
78
79 -class ExInvalidURI( OWS11_Exception ):
80 - def __init__( self , locator , message = None ):
81 OWS11_Exception.__init__( self , locator = locator )
82
83 -class ExActionFailed( OWS11_Exception ):
84 - def __init__( self , locator ):
85 OWS11_Exception.__init__( self , locator = locator )
86
87 -class ExOperationNotSupported( OWS11_Exception ):
88 - def __init__( self , locator , message = None ):
89 OWS11_Exception.__init__( self , locator = locator , message = message )
90 91 # generic exception
92 -class ExNoApplicableCode( OWS11_Exception ):
93 - def __init__( self , message ):
94 OWS11_Exception.__init__( self , message = message )
95 96 97 #======================================================= 98 # forming the exception report 99
100 -def createXML_OWS11Exception( exception ) :
101 102 xml = ows11ExceptionReport( exception ) 103 xml.insert(0,u'<?xml version="1.0" encoding="UTF-8"?>\n') 104 105 return ( u"".join(xml) ).encode("UTF-8") 106
107 -def ows11ExceptionReport( exception ) :
108 109 xml = [] 110 111 # prepare exception 112 113 try : raise exception 114 except OWS11_Exception : pass # the exception is already a OWS11 exception 115 except : # conversion must be done 116 exception = ExNoApplicableCode( unicode( exception ) ) 117 118 # prepare report 119 code = exception.getCode() 120 loc = u' locator="%s"'%( exception.locator ) if exception.locator else "" 121 122 xml.append( u'<ows:ExceptionReport ' ) 123 xml.append( u'xmlns:ows="http://www.opengis.net/ows/1.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ' ) 124 xml.append( u'xsi:schemaLocation="http://www.opengis.net/ows/1.1 http://schemas.opengis.net/ows/1.1.0/owsExceptionReport.xsd" ' ) 125 xml.append( u'xml:lang="%s" version="1.0.0">\n' % LANG ) 126 127 xml.append( u'\t<ows:Exception exceptionCode="%s"%s' % ( code , loc ) ) 128 129 if exception.message : 130 msg = unicode( exception.message ).replace( "]]>" , "]]]]><![CDATA[>" ) 131 xml.append( u">\n\t\t<ows:ExceptionText><![CDATA[%s]]></ows:ExceptionText>\n\t</ows:Exception>\n" % msg ) 132 else : 133 xml.append( u"/>\n" ) 134 135 xml.append( u'</ows:ExceptionReport>' ) 136 137 return xml
138