changeset 36:75de027b49e7

Always use utf8 charset for database connections.
author Daniele Nicolodi <daniele@grinta.net>
date Mon, 27 Jun 2011 21:05:24 +0200
parents 56e3649ff013
children e71a85df59e0
files src/ltpdarepo/admin.py src/ltpdarepo/install.py src/ltpdarepo/tests/test_users.py src/ltpdarepo/upgrade.py
diffstat 4 files changed, 11 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/src/ltpdarepo/admin.py	Mon Jun 27 21:05:24 2011 +0200
+++ b/src/ltpdarepo/admin.py	Mon Jun 27 21:05:24 2011 +0200
@@ -134,7 +134,7 @@
 def grant(username, database, privs):
     """grant permissions to given user for a specific database"""
 
-    conn = mysql.connect(host=HOSTNAME, db=DATABASE, user=USERNAME, passwd=PASSWORD)
+    conn = mysql.connect(host=HOSTNAME, db=DATABASE, user=USERNAME, passwd=PASSWORD, charset='utf8')
     curs = conn.cursor()
 
     if 'admin' in privs:
@@ -157,7 +157,7 @@
 def privileges(username):
     """show privileges for given user"""
 
-    conn = mysql.connect(host=HOSTNAME, db=DATABASE, user=USERNAME, passwd=PASSWORD)
+    conn = mysql.connect(host=HOSTNAME, db=DATABASE, user=USERNAME, passwd=PASSWORD, charset='utf8')
     curs = conn.cursor()
 
     privs = {}
@@ -207,7 +207,7 @@
 def wipe(yes=True):
     """delete all database content"""
 
-    conn = mysql.connect(host=HOSTNAME, db='', user=USERNAME, passwd=PASSWORD)
+    conn = mysql.connect(host=HOSTNAME, db='', user=USERNAME, passwd=PASSWORD, charset='utf8')
     curs = conn.cursor()
 
     # databases list
@@ -239,7 +239,7 @@
 def populate(database, nobjs):
     """populate a dababase witn fake objects"""
 
-    conn = mysql.connect(host=HOSTNAME, db=database, user=USERNAME, passwd=PASSWORD)
+    conn = mysql.connect(host=HOSTNAME, db=database, user=USERNAME, passwd=PASSWORD, charset='utf8')
     curs = conn.cursor()
 
     from datetime import datetime
--- a/src/ltpdarepo/install.py	Mon Jun 27 21:05:24 2011 +0200
+++ b/src/ltpdarepo/install.py	Mon Jun 27 21:05:24 2011 +0200
@@ -6,13 +6,13 @@
 def install():
     """create LTDA repository database tables"""
 
-    conn = mysql.connect(host=HOSTNAME, db='', user=USERNAME, passwd=PASSWORD)
+    conn = mysql.connect(host=HOSTNAME, db='', user=USERNAME, passwd=PASSWORD, charset='utf8')
     curs = conn.cursor()
 
     curs.execute("CREATE DATABASE `%s`" % DATABASE)
     conn.close()
 
-    conn = mysql.connect(host=HOSTNAME, db=DATABASE, user=USERNAME, passwd=PASSWORD)
+    conn = mysql.connect(host=HOSTNAME, db=DATABASE, user=USERNAME, passwd=PASSWORD, charset='utf8')
     curs = conn.cursor()
 
     curs.execute("""CREATE TABLE `available_dbs` (
--- a/src/ltpdarepo/tests/test_users.py	Mon Jun 27 21:05:24 2011 +0200
+++ b/src/ltpdarepo/tests/test_users.py	Mon Jun 27 21:05:24 2011 +0200
@@ -70,14 +70,16 @@
         u2.create()
         # test that the user can connect to the database
         conn = mysql.connect(host=self.app.config['HOSTNAME'],
-                             user=u2.username, passwd=u2.password)        
+                             user=u2.username, passwd=u2.password,
+                             charset='utf8')
 
     def test_user_login_generated_password(self):
         u2 = User(username='u2')
         u2.create()
         # test that the user can connect to the database
         conn = mysql.connect(host=self.app.config['HOSTNAME'],
-                             user=u2.username, passwd=u2.password)        
+                             user=u2.username, passwd=u2.password,
+                             charset='utf8')
 
 
 if __name__ == '__main__':
--- a/src/ltpdarepo/upgrade.py	Mon Jun 27 21:05:24 2011 +0200
+++ b/src/ltpdarepo/upgrade.py	Mon Jun 27 21:05:24 2011 +0200
@@ -20,7 +20,7 @@
 def upgrade(fromrev=None):
     """run database schema upgrade steps"""
     
-    conn = mysql.connect(host=HOSTNAME, db=DATABASE, user=USERNAME, passwd=PASSWORD)
+    conn = mysql.connect(host=HOSTNAME, db=DATABASE, user=USERNAME, passwd=PASSWORD, charset='utf8')
     curs = conn.cursor()
     logger = logging.getLogger(__name__)