password = ''
class AuthInitialPost():
- db = ''
+ db = ''
user = ''
password = ''
password = PasswordField('Password:')
ivals = UserInitialPost
-
+
class AuthWTForm(UserWTForm):
'''The wtform used to connect to any db and authenticate.'''
db = StringField('Database:')
ivals = AuthInitialPost
-
+
class UploadFileWTForm(AuthWTForm):
'''The wtform used for uploading files.'''
Input:
key The key
value The value
-
+
Returns:
Side effects:
of the session.
'''
self.uh.session[key] = value
-
+
def read(self):
'''
if self.data != '':
out = '{0}: data ({1})'.format(out, self.data)
return out
-
+
class Error(UploadError):
'''
Module exceptions rasied while setting up to read data lines
class DBDataLineError(DBError):
'''Database generated an error while the processor was running.'''
-
+
def __init__(self, udl, pgexc):
'''
udl An UploadDataLine instance
def execute(self, cur):
'''
Execute the sql statement.
-
+
Input:
cur A psycopg2 cursor
def execute(self, cur):
'''
Execute the sql statement.
-
+
Input:
cur A psycopg2 cursor
'''
Put string in double quotes escaping according to sql's
requirements for an identifier.
-
+
Note that this does not work for unicode identifiers.
'''
out = '"'
class DBData(object):
'''Data that is to modify the db.
-
+
It is iterable, consisting of thunks which make an UploadedLine instance.
lineno Number of lines processed (including header line)
'''
stmts List of SQLCommand instances
'''
- super(SQLData,self).__init__()
+ super(SQLData, self).__init__()
self.stmts = stmts
def gen(stmts):
class UploadData(DBData):
'''Uploaded data file
-
+
It is iterable, consisting of thunks which make an UploadedLine instance.
headers UploadedHeaders instance
def _extend(self, line, seq):
'''Give the list as many elements as there are in the header.
-
+
line line as string
seq line as sequence
-
+
If there's too many elements, raise an error.
'''
if len(seq) > self.cols:
'Line has too many columns',
'More columns than column headings',
data=line)
- return seq + [ '' for i in range(len(seq)+1, self.cols)]
+ return seq + ['' for i in range(len(seq) + 1, self.cols)]
if uf['filename'] == '':
errors.append(NoFileError('No file supplied'))
-
+
return errors
def double_validator(self, errors):
class DBConnector(object):
'''Abstract class supporting db connection and execution of a
processor function that alters the db content.
-
+
Responsible for connecting to the db, transaction management,
and running the DataLineProcessor instances produced by the
DBConnector's (the UploadHandler's) factory.
Reserved keys:
havecreds Boolean. Supplied credentials can connect to db.
'''
- return {'havecreds' : False}
+ return {'havecreds': False}
def nodberror_factory(self):
return NoDBError('No database name supplied')
havecreds = True
errors = self.call_alter_db(func, conn)
- response.update({'havecreds' : havecreds
+ response.update({'havecreds': havecreds
})
return (errors, response)
class NoTransactionEngine(DBConnector):
'''An engine that does not run things in a transaction.
-
+
It also does not do CSRF checking.
-
+
Attributes:
uh An UploadHandler instance.
data An UploadData instance of the uploaded data
class UnsafeUploadEngine(DBConnector):
'''Abstract class supporting repeatedly running a processer to put
uploaded data into db.
-
+
Attributes:
uh An UploadHandler instance.
data An UploadData instance of the uploaded data
'''Abstract class supporting repeatedly running a processor
to alter db content. Adds cross-site request forgery checking
to the UnsafeUploadEngine class.
-
+
Attributes:
uh An UploadHandler instance.
cur A psycopg2 cursor instance
'Your request failed and you are now logged out',
('This is a security measure. '
'Some possible causes are:'),
- ('<ul>'
+ ('<ul>'
'<li>Cookies are off in the browser</li> '
'<li>Reload of an expired page</li> '
' <ul>'
session.invalidate()
response = self.no_connection_response()
response['session_expired'] = True
- return([self.csrferror_factory()]
- , response)
+ return([self.csrferror_factory()],
+ response)
else:
(errors, response) = (super(UploadEngine, self)
.call_with_connection(func))