Added errorcodes.lookup() function.

This commit is contained in:
Daniele Varrazzo 2010-02-15 01:38:49 +00:00
parent 3da7a33ffb
commit d08d9ab199
2 changed files with 20 additions and 0 deletions

View File

@ -1,3 +1,7 @@
2010-02-15 Daniele Varrazzo <daniele.varrazzo@gmail.com>
* lib/errorcodes.py: Updated to PostgreSQL 8.4; added lookup() function.
2010-02-12 Daniele Varrazzo <daniele.varrazzo@gmail.com>
* Stop the loop variable used to create __all__ leaking in the module.

View File

@ -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