mirror of
https://github.com/psycopg/psycopg2.git
synced 2024-11-22 08:56:34 +03:00
Dropped duplicate classes in errors module
Also using a more compact class registration using a decorator
This commit is contained in:
parent
fae4284a64
commit
1bb3d5cfe2
713
lib/errors.py
713
lib/errors.py
File diff suppressed because it is too large
Load Diff
|
@ -114,11 +114,24 @@ def fetch_errors(versions):
|
||||||
def generate_module_data(classes, errors):
|
def generate_module_data(classes, errors):
|
||||||
tmpl = """
|
tmpl = """
|
||||||
|
|
||||||
|
@for_sqlstate(%(errcode)r)
|
||||||
class %(cls)s(%(base)s):
|
class %(cls)s(%(base)s):
|
||||||
pass
|
pass\
|
||||||
|
|
||||||
_by_sqlstate[%(errcode)r] = %(cls)s\
|
|
||||||
"""
|
"""
|
||||||
|
specific = {
|
||||||
|
'38002': 'ModifyingSqlDataNotPermittedExt',
|
||||||
|
'38003': 'ProhibitedSqlStatementAttemptedExt',
|
||||||
|
'38004': 'ReadingSqlDataNotPermittedExt',
|
||||||
|
'39004': 'NullValueNotAllowedExt',
|
||||||
|
'XX000': 'InternalError_',
|
||||||
|
}
|
||||||
|
|
||||||
|
seen = set("""
|
||||||
|
Error Warning InterfaceError DataError DatabaseError ProgrammingError
|
||||||
|
IntegrityError InternalError NotSupportedError OperationalError
|
||||||
|
QueryCanceledError TransactionRollbackError
|
||||||
|
""".split())
|
||||||
|
|
||||||
for clscode, clslabel in sorted(classes.items()):
|
for clscode, clslabel in sorted(classes.items()):
|
||||||
if clscode in ('00', '01'):
|
if clscode in ('00', '01'):
|
||||||
# success and warning - never raised
|
# success and warning - never raised
|
||||||
|
@ -127,7 +140,14 @@ _by_sqlstate[%(errcode)r] = %(cls)s\
|
||||||
yield "\n\n# %s" % clslabel
|
yield "\n\n# %s" % clslabel
|
||||||
|
|
||||||
for errcode, errlabel in sorted(errors[clscode].items()):
|
for errcode, errlabel in sorted(errors[clscode].items()):
|
||||||
clsname = errlabel.title().replace('_', '')
|
if errcode in specific:
|
||||||
|
clsname = specific[errcode]
|
||||||
|
else:
|
||||||
|
clsname = errlabel.title().replace('_', '')
|
||||||
|
if clsname in seen:
|
||||||
|
raise Exception("class already existing: %s" % clsname)
|
||||||
|
seen.add(clsname)
|
||||||
|
|
||||||
yield tmpl % {
|
yield tmpl % {
|
||||||
'cls': clsname,
|
'cls': clsname,
|
||||||
'base': get_base_class_name(errcode),
|
'base': get_base_class_name(errcode),
|
||||||
|
|
Loading…
Reference in New Issue
Block a user