WebApp

Check-in [384da38890]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Rest of exception handling has been implemented
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256:384da38890b244f5bb7bf0debef5fc5a8fb5ebe24b41d89712f6eb9b79e357e1
User & Date: sebpc 2018-05-28 15:59:23
Context
2018-05-30
17:49
Thread implemented Leaf check-in: 07372acec1 user: sebpc tags: trunk
2018-05-28
15:59
Rest of exception handling has been implemented check-in: 384da38890 user: sebpc tags: trunk
2018-05-27
16:25
Exceptions partially implemented check-in: d98be4905c user: sebpc tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to DBcm.py.

1
2
3
4







5
6
7
8
9
10
11
12
13
14
15


16
17
18
19




import sqlite3

class ConnectionError(Exception):
    pass








class UseDatabase:
    def __init__(self, database) -> None:
        self.database = database
    def __enter__(self):
        try:
            self.conn = sqlite3.connect(self.database)
            self.cursor = self.conn.cursor()
            return self.cursor
        except sqlite3.InterfaceError as err:
            raise ConnectionError(err)


    def __exit__(self, exc_type, exc_value, exc_trace) -> None:
        self.conn.commit()
        self.cursor.close()
        self.conn.close()








>
>
>
>
>
>
>











>
>




>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import sqlite3

class ConnectionError(Exception):
    pass

class CredentialsError(Exception):
    pass

class SQLError(Exception):
    pass


class UseDatabase:
    def __init__(self, database) -> None:
        self.database = database
    def __enter__(self):
        try:
            self.conn = sqlite3.connect(self.database)
            self.cursor = self.conn.cursor()
            return self.cursor
        except sqlite3.InterfaceError as err:
            raise ConnectionError(err)
        except sqlite3.ProgrammingError as err:
            raise CredentialsError(err)
    def __exit__(self, exc_type, exc_value, exc_trace) -> None:
        self.conn.commit()
        self.cursor.close()
        self.conn.close()
        if exc_type is sqlite3.ProgrammingError:
            raise SQLError(exc_value)
        elif exc_type:
            raise exc_type(exc_value)

Changes to vsearch4web.py.

1
2
3
4
5
6
7
8
9
10

11
12
13
14
15

16
17
18
19
20
21
22
..
50
51
52
53
54
55
56

57
58
59
60
61
62
63
..
66
67
68
69
70
71
72
73







74

75
76
from flask import Flask, render_template, request, escape, session
from vsearch import search4letters
from DBcm import UseDatabase, ConnectionError
from checker import check_logged_in

app = Flask(__name__)

app.secret_key = 'Moj$3kret'

db = 'vsearchlog.db'


@app.route('/login')
def login():
    session['logged_in'] = True
    return 'Jestes teraz zalogowany'


@app.route('/logout')
def logout():
    session.pop('logged_in')
    return 'Zostales wylogowany'


................................................................................
		the_results = result,)


@app.route('/')
@app.route('/entry')
def entry_page() -> 'html':
	return render_template('entry.html', the_title='Welcome to search4letters on the web')


@app.route('/viewlog')
@check_logged_in
def view_the_log() -> str:
    try:
        with UseDatabase(db) as cursor:
            _SQL = """select phrase, letters, ip, browser_string, results
................................................................................
            contents = cursor.fetchall()
        titles = ('Phraise', 'Letters', 'Remote addr', 'User_agent', 'Results')
        return render_template('viewlog.html',
                                   the_title = 'View Log',
                                   the_row_titles = titles,
                                   the_data = contents,)
    except ConnectionError as err:
        print('Is your database switched on? Error: ' + str(err))









#if '__name__' == '__main__':
app.run(debug=True)


|







>





>







 







>







 







|
>
>
>
>
>
>
>

>
|

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
..
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
..
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
from flask import Flask, render_template, request, escape, session
from vsearch import search4letters
from DBcm import UseDatabase, ConnectionError, CredentialsError, SQLError
from checker import check_logged_in

app = Flask(__name__)

app.secret_key = 'Moj$3kret'

db = 'vsearchlog.db'


@app.route('/login')
def login():
    session['logged_in'] = True
    return 'Jestes teraz zalogowany'


@app.route('/logout')
def logout():
    session.pop('logged_in')
    return 'Zostales wylogowany'


................................................................................
		the_results = result,)


@app.route('/')
@app.route('/entry')
def entry_page() -> 'html':
	return render_template('entry.html', the_title='Welcome to search4letters on the web')


@app.route('/viewlog')
@check_logged_in
def view_the_log() -> str:
    try:
        with UseDatabase(db) as cursor:
            _SQL = """select phrase, letters, ip, browser_string, results
................................................................................
            contents = cursor.fetchall()
        titles = ('Phraise', 'Letters', 'Remote addr', 'User_agent', 'Results')
        return render_template('viewlog.html',
                                   the_title = 'View Log',
                                   the_row_titles = titles,
                                   the_data = contents,)
    except ConnectionError as err:
        print('Is your database switched on? Error: ', str(err))
    except CredentialsError as err:
        print("User-id/Password issues.Error: ", str(err))
    except SQLError as err:
        print("Is your query correct? Error:", str(err))
    except Exception as err:
        print("Something went wrong", str(errr))
    return "Error"


#if __name__ == '__main__':
app.run(debug=True)