From c41b43e173c6b1415e9d030f3b63d67304b7153e Mon Sep 17 00:00:00 2001 From: "Karl O. Pinc" Date: Fri, 23 Feb 2024 14:25:46 -0600 Subject: [PATCH] Upgrade from psycopg2 to psycopg3; drop python <= v3.5, add v3.8-v3.11 --- setup.py | 8 +++-- src/pgwui_upload_core/views/upload.py | 42 ++++++++++++--------------- tox.ini | 8 +++-- 3 files changed, 29 insertions(+), 29 deletions(-) diff --git a/setup.py b/setup.py index 83aa618..7ed85db 100644 --- a/setup.py +++ b/setup.py @@ -115,10 +115,12 @@ setup( # Specify the Python versions you support here. In particular, ensure # that you indicate whether you support Python 2, Python 3 or both. 'Programming Language :: Python :: 3', - 'Programming Language :: Python :: 3.4', - 'Programming Language :: Python :: 3.5', 'Programming Language :: Python :: 3.6', 'Programming Language :: Python :: 3.7', + 'Programming Language :: Python :: 3.8', + 'Programming Language :: Python :: 3.9', + 'Programming Language :: Python :: 3.10', + 'Programming Language :: Python :: 3.11', ], # What does your project relate to? @@ -159,7 +161,7 @@ setup( 'attrs', 'markupsafe', 'pgwui_common', - 'psycopg2', + 'psycopg', 'pyramid', ], diff --git a/src/pgwui_upload_core/views/upload.py b/src/pgwui_upload_core/views/upload.py index 97459ad..47042cf 100644 --- a/src/pgwui_upload_core/views/upload.py +++ b/src/pgwui_upload_core/views/upload.py @@ -1,4 +1,4 @@ -# Copyright (C) 2015, 2018, 2020, 2021 The Meme Factory, Inc. +# Copyright (C) 2015, 2018, 2020, 2021, 2024 The Meme Factory, Inc. # http://www.karlpinc.com/ # This file is part of PGWUI_Upload_Core. @@ -27,8 +27,7 @@ import attr import logging import markupsafe -import psycopg2.errorcodes -from psycopg2 import ProgrammingError +import psycopg.errors from pgwui_core.core import ( UploadNullFileInitialPost, @@ -89,7 +88,7 @@ class SaveLine(DataLineProcessor, ParameterExecutor): ue UploadEngine instance uh UploadHandler instance insert_stmt Statement used to insert into db. - (psycopg2 formatted for substituion) + (psycopg3 formatted for substituion) ''' super(SaveLine, self).__init__(ue, uh) self.insert_stmt = insert_stmt @@ -157,25 +156,22 @@ class BaseTableUploadHandler(TabularFileUploadHandler): ' ON (pg_namespace.oid = pg_class.relnamespace)' ' WHERE pg_class.oid = %s::REGCLASS::OID'), (qualified_table,)) - except ProgrammingError as err: - pgcode = err.pgcode - if pgcode == psycopg2.errorcodes.INVALID_SCHEMA_NAME: - raise upload_ex.MissingSchemaError( - 'No such schema', - err.diag.message_primary,) - elif pgcode == psycopg2.errorcodes.UNDEFINED_TABLE: - raise upload_ex.MissingTableError( - 'No such table or view', - err.diag.message_primary, - ('

Hint: Check spelling, database permissions, ' - ' or try qualifying the' - ' table name with a schema name

')) - elif pgcode == psycopg2.errorcodes.INSUFFICIENT_PRIVILEGE: - raise upload_ex.InsufficientPrivilegeError( - 'Your PostgreSQL login has insufficient privileges', - err.diag.message_primary) - else: - raise + except psycopg.errors.INVALID_SCHEMA_NAME as err: + raise upload_ex.MissingSchemaError( + 'No such schema', + err.diag.message_primary,) + except psycopg.errors.UNDEFINED_TABLE as err: + raise upload_ex.MissingTableError( + 'No such table or view', + err.diag.message_primary, + ('

Hint: Check spelling, database permissions, ' + ' or try qualifying the' + ' table name with a schema name

')) + except psycopg.errors.INSUFFICIENT_PRIVILEGE as err: + raise upload_ex.InsufficientPrivilegeError( + 'Your PostgreSQL login has insufficient privileges', + err.diag.message_primary) + return self.cur.fetchone() def resolve_table(self, qualified_table): diff --git a/tox.ini b/tox.ini index 1ea296a..0bbee65 100644 --- a/tox.ini +++ b/tox.ini @@ -1,12 +1,14 @@ [tox] -envlist = py{34,35,36,37} +envlist = py{36,37,38,39,310,311} [testenv] basepython = - py34: python3.4 - py35: python3.5 py36: python3.6 py37: python3.7 + py38: python3.8 + py39: python3.9 + py310: python3.10 + py311: python3.11 deps = check-manifest cmarkgfm -- 2.34.1