mirror of
https://github.com/psycopg/psycopg2.git
synced 2025-02-07 12:50:32 +03:00
Added errorcodes.lookup() function.
This commit is contained in:
parent
3da7a33ffb
commit
d08d9ab199
|
@ -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.
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue
Block a user