diff options
author | Daniele Varrazzo <daniele.varrazzo@gmail.com> | 2010-02-15 21:59:49 +0000 |
---|---|---|
committer | Daniele Varrazzo <daniele.varrazzo@gmail.com> | 2010-02-16 00:38:44 +0000 |
commit | a320f25a2acddb6fa22660de61fb8e69f7839a1a (patch) | |
tree | ec1f7d89fa64d777d9e26ccf730bcf4cda592a71 | |
parent | 96b7912bcf4f766719e51daa25273d5472018623 (diff) | |
download | psycopg2-a320f25a2acddb6fa22660de61fb8e69f7839a1a.tar.gz |
Completed documentation for errorcodes module.
-rw-r--r-- | doc/src/_static/psycopg.css | 4 | ||||
-rw-r--r-- | doc/src/errorcodes.rst | 41 | ||||
-rw-r--r-- | lib/errorcodes.py | 4 | ||||
-rwxr-xr-x | scripts/make_errorcodes.py | 5 |
4 files changed, 47 insertions, 7 deletions
diff --git a/doc/src/_static/psycopg.css b/doc/src/_static/psycopg.css index df52b32..5cb9284 100644 --- a/doc/src/_static/psycopg.css +++ b/doc/src/_static/psycopg.css @@ -1,5 +1,9 @@ @import url("default.css"); +blockquote { + font-style: italic; +} + div.admonition-todo { background-color: #ffa; border: 1px solid #ee2; diff --git a/doc/src/errorcodes.rst b/doc/src/errorcodes.rst index e1c76c0..a0c1033 100644 --- a/doc/src/errorcodes.rst +++ b/doc/src/errorcodes.rst @@ -3,13 +3,20 @@ .. sectionauthor:: Daniele Varrazzo <daniele.varrazzo@gmail.com> +.. index:: + single: Error; Codes + .. module:: psycopg2.errorcodes +.. testsetup:: * + + from psycopg2 import errorcodes + .. versionadded:: 2.0.6 -This module contains symbolic names for all PostgreSQL error codes. -Subclasses of :exc:`~psycopg2.Error` make the PostgreSQL error code available -in the :attr:`~psycopg2.Error.pgcode` attribute. +This module contains symbolic names for all PostgreSQL error codes and error +classes codes. Subclasses of :exc:`~psycopg2.Error` make the PostgreSQL error +code available in the :attr:`~psycopg2.Error.pgcode` attribute. From PostgreSQL documentation: @@ -30,12 +37,36 @@ From PostgreSQL documentation: recognize the specific error code can still be able to infer what to do from the error class. - .. seealso:: `PostgreSQL Error Codes table`__ .. __: http://www.postgresql.org/docs/8.4/static/errcodes-appendix.html#ERRCODES-TABLE -.. todo:: errors table +An example of the available constants defined in the module: + + >>> errorcodes.CLASS_SYNTAX_ERROR_OR_ACCESS_RULE_VIOLATION + '42' + >>> errorcodes.UNDEFINED_TABLE + '42P01' + +Constants representing all the error values documented by PostgreSQL versions +between 8.1 and 8.4 are included in the module. + + +.. autofunction:: lookup(code) + + .. doctest:: + + >>> try: + ... cur.execute("SELECT ouch FROM aargh;") + ... except Exception, e: + ... pass + ... + >>> errorcodes.lookup(e.pgcode[:2]) + 'CLASS_SYNTAX_ERROR_OR_ACCESS_RULE_VIOLATION' + >>> errorcodes.lookup(e.pgcode) + 'UNDEFINED_TABLE' + + .. versionadded:: 2.0.14 diff --git a/lib/errorcodes.py b/lib/errorcodes.py index 3720697..9567201 100644 --- a/lib/errorcodes.py +++ b/lib/errorcodes.py @@ -30,9 +30,9 @@ This module contains symbolic names for all PostgreSQL error codes. # def lookup(code, _cache={}): - """Lookup a code error and return its symbolic name. + """Lookup an error code or class code and return its symbolic name. - Raise KeyError if the code is not found. + Raise :exc:`KeyError` if the code is not found. """ if _cache: return _cache[code] diff --git a/scripts/make_errorcodes.py b/scripts/make_errorcodes.py index 3dad76a..64ebca3 100755 --- a/scripts/make_errorcodes.py +++ b/scripts/make_errorcodes.py @@ -71,6 +71,11 @@ def parse_errors(url): errcode = tr.tt.string.encode("ascii") assert len(errcode) == 5 errlabel = tr('td')[1].string.replace(" ", "_").encode("ascii") + + # double check the columns are equal + cond_name = tr('td')[2].string.upper().encode("ascii") + assert errlabel == cond_name, tr + errors[class_][errcode] = errlabel return classes, errors |