From bd2d221c488d80cf992bd4d141d2db27db1b8ce4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?GOLDERWEB=20=E2=80=93=20Jonathan=20Golder?= Date: Wed, 24 Aug 2016 15:48:30 +0200 Subject: [PATCH] Prevent flush from creating cursor without con MysqlRed.flush() tried to create a cursor in any case. If there was no connection (because the subclasses haven't been instantiated an oursql Error occured. Instead, check before if there is a connection and otherwise raise an Error Related Task: [https://fs.golderweb.de/index.php?do=details&task_id=75 FS#75] Related Task: [https://fs.golderweb.de/index.php?do=details&task_id=75 FS#75] --- mysqlred.py | 17 +++++++++++++++++ reddiscparser.py | 2 +- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/mysqlred.py b/mysqlred.py index 055b995..77eae35 100644 --- a/mysqlred.py +++ b/mysqlred.py @@ -92,6 +92,9 @@ class MysqlRed: """ Run cached querys """ + if not cls.connection: + raise MysqlRedConnectionError( "No connection exists!" ) + cursor = cls.connection.cursor() # Execute insert query @@ -307,3 +310,17 @@ article7 ) VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? );' break for row in res: yield row + + +class MysqlRedError(Exception): + """ + Basic Exception class for this module + """ + pass + + +class MysqlRedConnectionError(MysqlRedError): + """ + Raised if there are Errors with Mysql-Connections + """ + pass diff --git a/reddiscparser.py b/reddiscparser.py index 962eb5a..3a6f43b 100644 --- a/reddiscparser.py +++ b/reddiscparser.py @@ -123,7 +123,7 @@ class DiscussionParserBot( reddisc=red_page.page.title() ) ) else: jogobot.output( - "\03{red} Page [[{reddisc}]], ".format( + "\03{red}" + "Page [[{reddisc}]], ".format( reddisc=red_page.page.title() ) + "containing no redfam, parsed!", "WARNING" )