summaryrefslogtreecommitdiff
path: root/lib/errorcodes.py
diff options
context:
space:
mode:
Diffstat (limited to 'lib/errorcodes.py')
-rw-r--r--lib/errorcodes.py16
1 files changed, 16 insertions, 0 deletions
diff --git a/lib/errorcodes.py b/lib/errorcodes.py
index 30110fd..3720697 100644
--- a/lib/errorcodes.py
+++ b/lib/errorcodes.py
@@ -29,6 +29,22 @@ This module contains symbolic names for all PostgreSQL error codes.
# http://www.postgresql.org/docs/8.4/static/errcodes-appendix.html
#
+def lookup(code, _cache={}):
+ """Lookup a code error and return its symbolic name.
+
+ Raise KeyError if the code is not found.
+ """
+ if _cache:
+ return _cache[code]
+
+ # Generate the lookup map at first usage.
+ for k, v in globals().iteritems():
+ if isinstance(v, str) and len(v) in (2, 5):
+ _cache[v] = k
+
+ return lookup(code)
+
+
# autogenerated data: do not edit below this point.
# Error classes