import collections.abc
import ast
import attr
+import attrs
import markupsafe
import hashlib
# Upload processing
-class SQLCommand(object):
+@attrs.define(slots=False)
+class SQLCommand():
'''
An SQL command that returns nothing
Attributes:
stmt The statement, formatted for psycopg3 substitution
args Tuple of arguments used to substitute when executed.
+ ec(ex) Produces the exception to raise an instance of on failure
+ Input:
+ ex The exception raised by psycopg3
'''
- def __init__(self, stmt, args, ec=None):
- '''
- stmt The statement, formatted for psycopg3 substitution
- args Tuple of arguments used to substitute when executed.
- ec(ex) Produces the exception to raise an instance of on failure
- Input:
- ex The exception raised by psycopg3
- '''
- super(SQLCommand, self).__init__()
- self.stmt = stmt
- self.args = args
- self.ec = ec
+ stmt = attrs.field()
+ args = attrs.field()
+ ec = attrs.field(default=None)
def execute(self, cur):
'''
raise self.ec(ex)
+@attrs.define(slots=False)
class LogSQLCommand(SQLCommand):
- '''An SQL command that logs success or failure.'''
- def __init__(self, stmt, args, ec=None,
- log_success=None, log_failure=None):
- '''
- stmt The statement, formatted for psycopg3 substitution
- args Tuple of arguments used to substitute when executed.
- ec(ex) Produces the exception to raise an instance of on failure
- Input:
- ex The exception raised by psycopg3
- '''
- super(LogSQLCommand, self).__init__(stmt, args, ec)
- self.log_success = log_success
- self.log_failure = log_failure
+ '''An SQL command that logs success or failure.
+
+ Attributes:
+ stmt The statement, formatted for psycopg3 substitution
+ args Tuple of arguments used to substitute when executed.
+ ec(ex) Produces the exception to raise an instance of on failure
+ Input:
+ ex The exception raised by psycopg3
+ log_success
+ Logs success
+ log_failure(ex)
+ Logs failure
+ Input:
+ ex The exception to log
+ '''
+ log_success = attrs.field(default=None)
+ log_failure = attrs.field(default=None)
def execute(self, cur):
'''
Can raise a psycopg3 error
'''
try:
- super(LogSQLCommand, self).execute(cur)
+ super().execute(cur)
except (core_ex.UploadError, psycopg.DatabaseError) as ex:
if self.log_failure:
self.log_failure(ex)