File: error.py

package info (click to toggle)
python-django 1.7.7-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie-kfreebsd
  • size: 44,872 kB
  • sloc: python: 170,757; xml: 713; makefile: 199; sh: 170; sql: 11
file content (55 lines) | stat: -rw-r--r-- 1,430 bytes parent folder | download | duplicates (3)
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
"""
 This module houses the OGR & SRS Exception objects, and the
 check_err() routine which checks the status code returned by
 OGR methods.
"""


#### OGR & SRS Exceptions ####
class GDALException(Exception):
    pass


class OGRException(Exception):
    pass


class SRSException(Exception):
    pass


class OGRIndexError(OGRException, KeyError):
    """
    This exception is raised when an invalid index is encountered, and has
    the 'silent_variable_feature' attribute set to true.  This ensures that
    django's templates proceed to use the next lookup type gracefully when
    an Exception is raised.  Fixes ticket #4740.
    """
    silent_variable_failure = True

#### OGR error checking codes and routine ####

# OGR Error Codes
OGRERR_DICT = {
    1: (OGRException, 'Not enough data.'),
    2: (OGRException, 'Not enough memory.'),
    3: (OGRException, 'Unsupported geometry type.'),
    4: (OGRException, 'Unsupported operation.'),
    5: (OGRException, 'Corrupt data.'),
    6: (OGRException, 'OGR failure.'),
    7: (SRSException, 'Unsupported SRS.'),
    8: (OGRException, 'Invalid handle.'),
}
OGRERR_NONE = 0


def check_err(code):
    "Checks the given OGRERR, and raises an exception where appropriate."

    if code == OGRERR_NONE:
        return
    elif code in OGRERR_DICT:
        e, msg = OGRERR_DICT[code]
        raise e(msg)
    else:
        raise OGRException('Unknown error code: "%s"' % code)