[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
r6283 - in trunk/gnue-common/src: apps datasources datasources/drivers/p
From: |
johannes |
Subject: |
r6283 - in trunk/gnue-common/src: apps datasources datasources/drivers/postgresql/Base |
Date: |
Tue, 14 Sep 2004 13:37:54 -0500 (CDT) |
Author: johannes
Date: 2004-09-14 13:37:53 -0500 (Tue, 14 Sep 2004)
New Revision: 6283
Modified:
trunk/gnue-common/src/apps/errors.py
trunk/gnue-common/src/datasources/GConnections.py
trunk/gnue-common/src/datasources/drivers/postgresql/Base/Connection.py
Log:
Fixed encoding of non-gException-exception messages
Modified: trunk/gnue-common/src/apps/errors.py
===================================================================
--- trunk/gnue-common/src/apps/errors.py 2004-09-14 16:25:52 UTC (rev
6282)
+++ trunk/gnue-common/src/apps/errors.py 2004-09-14 18:37:53 UTC (rev
6283)
@@ -228,8 +228,8 @@
if count is not None:
del lines [1:count + 1]
- name = unicode (aType).split ('.') [-1]
- message = unicode (aValue)
+ name = unicode ("%s" % aType, i18n.getencoding ()).split ('.') [-1]
+ message = unicode ("%s" % aValue, i18n.getencoding ())
detail = string.join (lines)
if isinstance (detail, types.StringType):
detail = unicode (detail, i18n.getencoding ())
Modified: trunk/gnue-common/src/datasources/GConnections.py
===================================================================
--- trunk/gnue-common/src/datasources/GConnections.py 2004-09-14 16:25:52 UTC
(rev 6282)
+++ trunk/gnue-common/src/datasources/GConnections.py 2004-09-14 18:37:53 UTC
(rev 6283)
@@ -462,7 +462,7 @@
# Four times is plenty...
#self._loginHandler.destroyLoginDialog()
tmsg = u_("Unable to log in after 4 attempts.\n\nError: %s") \
- % error
+ % errors.getException () [2]
raise Exceptions.LoginError, tmsg
except GLoginHandler.UserCanceledLogin:
Modified:
trunk/gnue-common/src/datasources/drivers/postgresql/Base/Connection.py
===================================================================
--- trunk/gnue-common/src/datasources/drivers/postgresql/Base/Connection.py
2004-09-14 16:25:52 UTC (rev 6282)
+++ trunk/gnue-common/src/datasources/drivers/postgresql/Base/Connection.py
2004-09-14 18:37:53 UTC (rev 6283)
@@ -1,10 +1,13 @@
+# GNU Enterprise Common - Database Drivers - Base driver for PostgreSQL
#
-# This file is part of GNU Enterprise.
+# Copyright 2001-2004 Free Software Foundation
#
+# This file is part of GNU Enterprise
+#
# GNU Enterprise is free software; you can redistribute it
# and/or modify it under the terms of the GNU General Public
# License as published by the Free Software Foundation; either
-# version 2, or(at your option) any later version.
+# version 2, or (at your option) any later version.
#
# GNU Enterprise is distributed in the hope that it will be
# useful, but WITHOUT ANY WARRANTY; without even the implied
@@ -16,25 +19,14 @@
# write to the Free Software Foundation, Inc., 59 Temple Place
# - Suite 330, Boston, MA 02111-1307, USA.
#
-# Copyright 2000-2004 Free Software Foundation
-#
-# FILE:
-# _pgsql/DBdriver.py
-#
-# DESCRIPTION:
-# A core Postgresql dbdriver that the other (specific)
-# postgresql drivers can extend
-#
-# NOTES:
-#
-# $Id: $
+# $Id$
__all__ = ['Connection']
import string
from string import lower, join, split
import sys
-from gnue.common.apps import GDebug, GConfig
+from gnue.common.apps import GDebug, GConfig, errors
from gnue.common.datasources import Exceptions
from gnue.common.datasources.drivers import DBSIG2
from DataObject import *
@@ -42,12 +34,13 @@
from gnue.common.datasources.drivers.postgresql.Schema.Creation.Creation
import Creation
-######################################################################
-#
-# GConnection object for PostgreSQL-based drivers
-#
-class Connection(DBSIG2.Connection):
+# =============================================================================
+# GConnection object for PostgreSQL-based drivers
+# =============================================================================
+
+class Connection (DBSIG2.Connection):
+
defaultBehavior = Introspection
defaultCreator = Creation
supportedDataObjects = {
@@ -58,73 +51,80 @@
_pg_connectString = 'host=%s dbname=%s user=%s password=%s port=%s'
- def connect(self, connectData):
+ # ---------------------------------------------------------------------------
+ # Connect to the database
+ # ---------------------------------------------------------------------------
+ def connect (self, connectData):
+
if not self._driver:
self._driver = __import__ (self._driver_module, None, None, '*')
- if not hasattr(self,'_DatabaseError'):
+ if not hasattr (self,'_DatabaseError'):
try:
self._DatabaseError = self._driver.Error
except:
self._DatabaseError = self._driver.DatabaseError
- GDebug.printMesg(1,"Postgresql database driver initializing")
+ gDebug (1, "Postgresql database driver initializing")
+
try:
- try:
- port = connectData['port']
- except:
- port = '5432'
+ port = connectData.get ('port', '5432')
+ conStr = self._pg_connectString % (connectData ['host'],
+ connectData ['dbname'],
+ connectData ['_username'],
+ connectData ['_password'],
+ port)
- self.native = self._driver.connect(self._pg_connectString %
- (connectData['host'],
- connectData['dbname'],
- connectData['_username'],
- connectData['_password'],
- port))
+ self.native = self._driver.connect (conStr)
+
except self._DatabaseError, value:
- GDebug.printMesg(1,"Connect String: %s" % (self._pg_connectString % \
- (connectData['host'],
- connectData['dbname'],
- connectData['_username'],
- connectData['_password'],
- port)))
- GDebug.printMesg(1,"Exception %s " % value)
+ gDebug (1, "Connect String: %s" % conStr)
+ gDebug (1, "Exception %s" % value)
+
raise Exceptions.LoginError, \
u_("The PostgreSQL driver returned the following error:\n\t%s") \
- % value
+ % errors.getException () [2]
- try:
- self._pg_encoding = pg_encTable[self._encoding]
- except KeyError:
+ self._pg_encoding = pg_encTable.get (self._encoding, '')
+ if not pg_encTable.has_key (self._encoding):
gDebug (1, u_("Encoding '%s' is not supported by postgresql dbdriver. "
"Using default encoding.") % self._encoding)
- self._pg_encoding = ''
- if self._pg_encoding not in ("",'DEFAULT'):
- GDebug.printMesg(1,'Setting postgresql client_encoding to %s (%s)' %
(self._pg_encoding,
-
self._encoding))
+ if self._pg_encoding not in ["", 'DEFAULT']:
+ gDebug (1, 'Setting postgresql client_encoding to %s (%s)' \
+ % (self._pg_encoding, self._encoding))
self.sql ("SET CLIENT_ENCODING TO '%s'" % self._pg_encoding)
- if connectData.has_key('datetimeformat'):
- self._dateTimeFormat = "'%s'" % connectData['datetimeformat']
- else:
- self._dateTimeFormat = "'%Y-%m-%d %H:%M:%S'"
+ dtfmt = connectData.get ('datetimeformat', "%Y-%m-%d %H:%M:%S")
+ self._dateTimeFormat = "'%s'" % dtfmt
+ gDebug (1, "datetime-format set to %s" % self._dateTimeFormat)
- #########
- #
+
+ # ===========================================================================
# Extensions to the basic GConnection object
- #
+ # ===========================================================================
+
+ # ---------------------------------------------------------------------------
# Return the current date, according to database
- def getTimeStamp(self):
+ # ---------------------------------------------------------------------------
+
+ def getTimeStamp (self):
+
return self.sql1 ("select current_timestamp")
+
+ # ---------------------------------------------------------------------------
# Return a sequence number from sequence 'name'
- def getSequence(self, name):
+ # ---------------------------------------------------------------------------
+
+ def getSequence (self, name):
+
return self.sql1 ("select nextval('%s')" % name)
+
# ---------------------------------------------------------------------------
# PostgreSQL treats all identifiers as lowercase
# ---------------------------------------------------------------------------
@@ -136,34 +136,42 @@
@param identifier: identifier to be converted
@return: lowercase string
"""
+
return identifier.lower ()
-pg_encTable = {'ascii' : 'SQL_ASCII', # ASCII
- '' : 'EUC_JP', # Japanese EUC
- '' : 'EUC_CN', # Chinese EUC
- '' : 'EUC_KR', # Korean EUC
- '' : 'JOHAB', # Korean EUC (Hangle base)
- '' : 'EUC_TW', # Taiwan EUC
- 'utf-8' : 'UNICODE', # Unicode (UTF-8)
- '' : 'MULE_INTERNAL', # Mule internal code
- 'iso8859-1' : 'LATIN1', # ISO 8859-1 ECMA-94 Latin
Alphabet No.1
- 'iso8859-2' : 'LATIN2', # ISO 8859-2 ECMA-94 Latin
Alphabet No.2
- 'iso8859-3' : 'LATIN3', # ISO 8859-3 ECMA-94 Latin
Alphabet No.3
- 'iso8859-4' : 'LATIN4', # ISO 8859-4 ECMA-94 Latin
Alphabet No.4
- 'iso8859-9' : 'LATIN5', # ISO 8859-9 ECMA-128 Latin
Alphabet No.5
- 'iso8859-10': 'LATIN6', # ISO 8859-10 ECMA-144 Latin
Alphabet No.6
- 'iso8859-13': 'LATIN7', # ISO 8859-13 Latin Alphabet
No.7
- 'iso8859-14': 'LATIN8', # ISO 8859-14 Latin Alphabet
No.8
- 'iso8859-15': 'LATIN9', # ISO 8859-15 Latin Alphabet
No.9
- 'iso8859-16': 'LATIN10', # ISO 8859-16 ASRO SR 14111
Latin Alphabet No.10
- 'iso8859-5' : 'ISO-8859-5', # ECMA-113 Latin/Cyrillic
- 'iso8859-6' : 'ISO-8859-6', # ECMA-114 Latin/Arabic
- 'iso8859-7' : 'ISO-8859-7', # ECMA-118 Latin/Greek
- 'iso8859-8' : 'ISO-8859-8', # ECMA-121 Latin/Hebrew
- '' : 'KOI8', # KOI8-R(U)
- '' : 'WIN', # Windows CP1251
- '' : 'ALT', # Windows CP866
- '' : 'WIN1256', # Arabic Windows CP1256
- '' : 'TCVN', # Vietnamese TCVN-5712
(Windows CP1258)
- '' : 'WIN874'} # Thai Windows CP874
+
+# =============================================================================
+# Encoding-Table
+# =============================================================================
+
+pg_encTable = {
+ 'ascii' : 'SQL_ASCII', # ASCII
+ '' : 'EUC_JP', # Japanese EUC
+ '' : 'EUC_CN', # Chinese EUC
+ '' : 'EUC_KR', # Korean EUC
+ '' : 'JOHAB', # Korean EUC (Hangle base)
+ '' : 'EUC_TW', # Taiwan EUC
+ 'utf-8' : 'UNICODE', # Unicode (UTF-8)
+ '' : 'MULE_INTERNAL', # Mule internal code
+ 'iso8859-1' : 'LATIN1', # ISO 8859-1 ECMA-94 Latin Alphabet No.1
+ 'iso8859-2' : 'LATIN2', # ISO 8859-2 ECMA-94 Latin Alphabet No.2
+ 'iso8859-3' : 'LATIN3', # ISO 8859-3 ECMA-94 Latin Alphabet No.3
+ 'iso8859-4' : 'LATIN4', # ISO 8859-4 ECMA-94 Latin Alphabet No.4
+ 'iso8859-9' : 'LATIN5', # ISO 8859-9 ECMA-128 Latin Alphabet No.5
+ 'iso8859-10': 'LATIN6', # ISO 8859-10 ECMA-144 Latin Alphabet No.6
+ 'iso8859-13': 'LATIN7', # ISO 8859-13 Latin Alphabet No.7
+ 'iso8859-14': 'LATIN8', # ISO 8859-14 Latin Alphabet No.8
+ 'iso8859-15': 'LATIN9', # ISO 8859-15 Latin Alphabet No.9
+ 'iso8859-16': 'LATIN10', # ISO 8859-16 ASRO SR 14111 Latin Alph. No.10
+ 'iso8859-5' : 'ISO-8859-5', # ECMA-113 Latin/Cyrillic
+ 'iso8859-6' : 'ISO-8859-6', # ECMA-114 Latin/Arabic
+ 'iso8859-7' : 'ISO-8859-7', # ECMA-118 Latin/Greek
+ 'iso8859-8' : 'ISO-8859-8', # ECMA-121 Latin/Hebrew
+ '' : 'KOI8', # KOI8-R(U)
+ '' : 'WIN', # Windows CP1251
+ '' : 'ALT', # Windows CP866
+ '' : 'WIN1256', # Arabic Windows CP1256
+ '' : 'TCVN', # Vietnamese TCVN-5712 (Windows CP1258)
+ '' : 'WIN874', # Thai Windows CP874
+}
Property changes on:
trunk/gnue-common/src/datasources/drivers/postgresql/Base/Connection.py
___________________________________________________________________
Name: svn:keywords
- +Id
+ Id
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- r6283 - in trunk/gnue-common/src: apps datasources datasources/drivers/postgresql/Base,
johannes <=