errors.py 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. """Error classes for PostgreSQL error codes
  2. """
  3. # psycopg/errors.py - SQLSTATE and DB-API exceptions
  4. #
  5. # Copyright (C) 2018-2019 Daniele Varrazzo <daniele.varrazzo@gmail.com>
  6. # Copyright (C) 2020-2021 The Psycopg Team
  7. #
  8. # psycopg2 is free software: you can redistribute it and/or modify it
  9. # under the terms of the GNU Lesser General Public License as published
  10. # by the Free Software Foundation, either version 3 of the License, or
  11. # (at your option) any later version.
  12. #
  13. # In addition, as a special exception, the copyright holders give
  14. # permission to link this program with the OpenSSL library (or with
  15. # modified versions of OpenSSL that use the same license as OpenSSL),
  16. # and distribute linked combinations including the two.
  17. #
  18. # You must obey the GNU Lesser General Public License in all respects for
  19. # all of the code used other than OpenSSL.
  20. #
  21. # psycopg2 is distributed in the hope that it will be useful, but WITHOUT
  22. # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  23. # FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
  24. # License for more details.
  25. #
  26. # NOTE: the exceptions are injected into this module by the C extention.
  27. #
  28. def lookup(code):
  29. """Lookup an error code and return its exception class.
  30. Raise `!KeyError` if the code is not found.
  31. """
  32. from psycopg2._psycopg import sqlstate_errors # avoid circular import
  33. return sqlstate_errors[code]