# Karl O. Pinc <kop@karlpinc.com>
-from pgwui_common import exceptions as common_ex
from pgwui_common import checkset
+from . import exceptions as upload_ex
PGWUI_COMPONENT = 'pgwui_upload'
BOOLEAN_SETTINGS = []
-class UploadError(common_ex.Error):
- pass
-
-
-class BadLiteralColumnHeadingsError(UploadError):
- def __init__(self, value):
- super().__init__(
- 'The "pgwui.literal_column_headings" PGWUI setting must be'
- '"on", "off", "ask", or not present')
-
-
def validate_literal_column_headings(errors, settings):
'''Make sure the values are those allowed
'''
if value is None:
return
if value not in ('on', 'off', 'ask'):
- errors.append(BadLiteralColumnHeadingsError(value))
+ errors.append(upload_ex.BadLiteralColumnHeadingsError(value))
def check_settings(component_config):
--- /dev/null
+# Copyright (C) 2020 The Meme Factory, Inc. http://www.karlpinc.com/
+
+# This file is part of PGWUI_Upload.
+#
+# This program is free software: you can redistribute it and/or
+# modify it under the terms of the GNU Affero General Public License
+# as published by the Free Software Foundation, either version 3 of
+# the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public
+# License along with this program. If not, see
+# <http://www.gnu.org/licenses/>.
+#
+
+# Karl O. Pinc <kop@karlpinc.com>
+
+from pgwui_common import exceptions as common_ex
+from pgwui_core import exceptions as core_ex
+
+
+# PGWUI setting related exceptions
+
+class UploadError(common_ex.Error):
+ pass
+
+
+class BadLiteralColumnHeadingsError(UploadError):
+ def __init__(self, value):
+ super().__init__(
+ 'The "pgwui.literal_column_headings" PGWUI setting must be'
+ '"on", "off", "ask", or not present')
+
+
+# Upload related exceptions
+
+class NoTableError(core_ex.PGWUIError):
+ '''No table uploaded'''
+ def __init__(self, e, descr='', detail=''):
+ super(NoTableError, self).__init__(e, descr, detail)
+
+
+class BadTableError(core_ex.PGWUIError):
+ '''Supplied name does not work for a table or view'''
+ def __init__(self, e, descr='', detail=''):
+ super(BadTableError, self).__init__(e, descr, detail)
+
+
+class MissingTableError(BadTableError):
+ '''The supplied table or view does not exist'''
+ def __init__(self, e, descr='', detail=''):
+ super(MissingTableError, self).__init__(e, descr, detail)
+
+
+class MissingSchemaError(BadTableError):
+ '''The schema portion of the supplied table or view does not exist'''
+ def __init__(self, e, descr='', detail=''):
+ super(MissingSchemaError, self).__init__(e, descr, detail)
+
+
+class CannotInsertError(BadTableError):
+ '''Cannot insert into the supplied table or view'''
+ def __init__(self, e, descr='', detail=''):
+ super(CannotInsertError, self).__init__(e, descr, detail)
+
+
+class BadHeadersError(core_ex.PGWUIError):
+ '''The headers in the uploaded file are bad.'''
+ def __init__(self, e, descr='', detail=''):
+ super(BadHeadersError, self).__init__(e, descr, detail)
from psycopg2 import ProgrammingError
from pgwui_common import auth_base_view
-from pgwui_core.exceptions import PGWUIError
from pgwui_core.core import (
UploadEngine,
DataLineProcessor,
is_checked,
)
-log = logging.getLogger(__name__)
-
-
-class NoTableError(PGWUIError):
- '''No table uploaded'''
- def __init__(self, e, descr='', detail=''):
- super(NoTableError, self).__init__(e, descr, detail)
-
-
-class BadTableError(PGWUIError):
- '''Supplied name does not work for a table or view'''
- def __init__(self, e, descr='', detail=''):
- super(BadTableError, self).__init__(e, descr, detail)
-
+from pgwui_upload import exceptions as upload_ex
-class MissingTableError(BadTableError):
- '''The supplied table or view does not exist'''
- def __init__(self, e, descr='', detail=''):
- super(MissingTableError, self).__init__(e, descr, detail)
-
-class MissingSchemaError(BadTableError):
- '''The schema portion of the supplied table or view does not exist'''
- def __init__(self, e, descr='', detail=''):
- super(MissingSchemaError, self).__init__(e, descr, detail)
-
-
-class CannotInsertError(BadTableError):
- '''Cannot insert into the supplied table or view'''
- def __init__(self, e, descr='', detail=''):
- super(CannotInsertError, self).__init__(e, descr, detail)
-
-
-class BadHeadersError(PGWUIError):
- '''The headers in the uploaded file are bad.'''
- def __init__(self, e, descr='', detail=''):
- super(BadHeadersError, self).__init__(e, descr, detail)
+log = logging.getLogger(__name__)
class SaveLine(DataLineProcessor):
qualified_table = uf['table']
if qualified_table == '':
- errors.append(NoTableError('No table or view name supplied'))
+ errors.append(upload_ex.NoTableError(
+ 'No table or view name supplied'))
self.double_validator(errors)
except ProgrammingError as err:
pgcode = err.pgcode
if pgcode == psycopg2.errorcodes.INVALID_SCHEMA_NAME:
- raise MissingSchemaError(
+ raise upload_ex.MissingSchemaError(
'No such schema',
err.diag.message_primary,)
elif pgcode == psycopg2.errorcodes.UNDEFINED_TABLE:
- raise MissingTableError(
+ raise upload_ex.MissingTableError(
'No such table or view',
err.diag.message_primary,
('<p>Hint: Check spelling or try qualifying the'
schema, table = self.resolve_table(qualified_table)
if not self.good_table(schema, table):
- raise CannotInsertError(
+ raise upload_ex.CannotInsertError(
'Cannot insert into supplied table or view',
('({0}) is either is a view'
' that cannot be inserted into'
for bad_col in bad_cols:
detail += '<li>{0}</li>'.format(markupsafe.escape(bad_col))
detail += '</ul>'
- raise BadHeadersError(
+ raise upload_ex.BadHeadersError(
'Header line contains unknown column names',
detail=detail)
from pgwui_common import checkset
from pgwui_testing import testing
+from pgwui_upload import exceptions as upload_ex
# Activiate our pytest plugin
pytest_plugins = ("pgwui",)
assert errors
assert isinstance(
- errors[0], check_settings.BadLiteralColumnHeadingsError)
+ errors[0], upload_ex.BadLiteralColumnHeadingsError)
literal_err = 'literal column headings error'