source: cows/trunk/cows/model/exception_report.py @ 3553

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/cows/trunk/cows/model/exception_report.py@4060
Revision 3553, 1.5 KB checked in by spascoe, 12 years ago (diff)

Moved all the model classes into their own sub-module.

Line 
1# Copyright (C) 2007 STFC & NERC (Science and Technology Facilities Council).
2# This software may be distributed under the terms of the
3# Q Public License, version 1.0 or later.
4# http://ndg.nerc.ac.uk/public_docs/QPublic_license.txt
5"""
6Classes modelling the OWS Exception Report package v1.1.0.
7
8@author: Stephen Pascoe
9"""
10
11class ExceptionReport(object):
12    """
13    @ivar version
14    @type version: str
15    @ivar lang
16    @type lang: None or str, from RFC 4646
17    @ivar exceptions: Iterable of OWSException objects
18
19    """
20    def __init__(self, exceptions, version, lang=None):
21        self.version = version
22        self.exceptions = exceptions
23        self.lang = lang
24
25class OwsException(object):
26    """
27    @ivar code
28    @type code: str
29    @ivar text
30    @type text: None or str
31    @ivar locator
32    @type locator: None or str
33
34    """
35    def __init__(self, code, text=None, locator=None):
36        self.code = code
37        self.text = text
38        self.locator = locator
39
40class OwsError(Exception):
41    """Wrapper for triggering ExceptionReports via raise.
42
43    @todo: Design an elegant way of setting the version framework-wide.
44    @ivar report: The ExceptionReport describing the error.
45   
46    """
47    def __init__(self, code, text=None, locator=None, version='1.1.0', lang=None):
48        self.report = ExceptionReport([OwsException(code, text, locator)], version, lang)
49
50    def __str__(self):
51        """A concise non-XML representation of the error
52        """
53        e = self.report.exceptions[0]
54        return '%s: %s (%s)' % (e.code, e.text, e.locator)
Note: See TracBrowser for help on using the repository browser.