commit-gnue
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

CVSROOT: /cvsroot/gnue


From: Jan Ischebeck
Subject: CVSROOT: /cvsroot/gnue
Date: Fri, 10 Oct 2003 08:18:56 -0400

Module name:    gnue-common
Branch:         datasource-cleanup
Changes by:     Jan Ischebeck <address@hidden>  03/10/10 08:18:51
Reply-to: address@hidden

CVSROOT:        /cvsroot/gnue
Module name:    gnue-common
Branch:         datasource-cleanup
Changes by:     Jan Ischebeck <address@hidden>  03/10/10 08:18:51

Modified files:
        src/datasources: GConnection.py GDataSource.py GDataObjects.py 
        src/datasources/drivers/DBSIG2: DataObject.py ResultSet.py 
        src/datasources/drivers/appserver/appserver: Connection.py 
                                                     DataObject.py 
        src/datasources/drivers/postgresql/Base: Connection.py 

Log message:
        add _encoding parameter to GConnection base class (created a dummy)
        add _unicodeMode parameter to GDataObject base class.
        update toSQLString to actual cvs version (DBSIG2 driver)
        update _loadNextRecord to be able to produce unicode (DBSIG2)
        change postgresql Base driver to set encoding depending on db encoding
        update appserver dbdriver

CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue-common/src/datasources/GConnection.py.diff?only_with_tag=datasource-cleanup&tr1=1.1.2.1&tr2=1.1.2.2&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue-common/src/datasources/GDataSource.py.diff?only_with_tag=datasource-cleanup&tr1=1.64.2.1&tr2=1.64.2.2&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue-common/src/datasources/GDataObjects.py.diff?only_with_tag=datasource-cleanup&tr1=1.72.2.1&tr2=1.72.2.2&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue-common/src/datasources/drivers/DBSIG2/DataObject.py.diff?only_with_tag=datasource-cleanup&tr1=1.1.2.1&tr2=1.1.2.2&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue-common/src/datasources/drivers/DBSIG2/ResultSet.py.diff?only_with_tag=datasource-cleanup&tr1=1.1.2.1&tr2=1.1.2.2&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue-common/src/datasources/drivers/appserver/appserver/Connection.py.diff?only_with_tag=datasource-cleanup&tr1=1.1.2.1&tr2=1.1.2.2&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue-common/src/datasources/drivers/appserver/appserver/DataObject.py.diff?only_with_tag=datasource-cleanup&tr1=1.1.2.1&tr2=1.1.2.2&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue-common/src/datasources/drivers/postgresql/Base/Connection.py.diff?only_with_tag=datasource-cleanup&tr1=1.1.2.1&tr2=1.1.2.2&r1=text&r2=text

Patches:
Index: gnue-common/src/datasources/GConnection.py
diff -c gnue-common/src/datasources/GConnection.py:1.1.2.1 
gnue-common/src/datasources/GConnection.py:1.1.2.2
*** gnue-common/src/datasources/GConnection.py:1.1.2.1  Thu Oct  9 21:21:08 2003
--- gnue-common/src/datasources/GConnection.py  Fri Oct 10 08:18:47 2003
***************
*** 7,9 ****
--- 7,21 ----
     +-- GDataSources Intialized
       +-- GConnection.getDataObject()
         +--
+ 
+ class Connection(GConnection.Connection):
+ 
+    def __init__(self):
+       
+       self._encoding = 'iso8859-1'  # contain encoding used by database
+       
+       try:
+          self._encoding = gConfig('textEncoding')
+       except:
+          pass
+ 
Index: gnue-common/src/datasources/GDataObjects.py
diff -c gnue-common/src/datasources/GDataObjects.py:1.72.2.1 
gnue-common/src/datasources/GDataObjects.py:1.72.2.2
*** gnue-common/src/datasources/GDataObjects.py:1.72.2.1        Thu Oct  9 
21:21:08 2003
--- gnue-common/src/datasources/GDataObjects.py Fri Oct 10 08:18:48 2003
***************
*** 116,121 ****
--- 116,127 ----
  
      self._defaultValues = {}
  
+     self._unicodeMode = 0 # if set to true, datasources will unicode
+                           # strings instead of strings in local encoding
+                           # and if non unicode strings are passed to the
+                           # db driver a warning is raised (in 0.6.0 an
+                           # exception will be raised)
+ 
      # TODO: This is to keep old code from breaking.
      # TODO: 0.5.1 was last version to support
      # TODO triggerExtensions (functionality is now
Index: gnue-common/src/datasources/GDataSource.py
diff -c gnue-common/src/datasources/GDataSource.py:1.64.2.1 
gnue-common/src/datasources/GDataSource.py:1.64.2.2
*** gnue-common/src/datasources/GDataSource.py:1.64.2.1 Thu Oct  9 21:21:08 2003
--- gnue-common/src/datasources/GDataSource.py  Fri Oct 10 08:18:47 2003
***************
*** 553,559 ****
  # Wrapper for standalone DataSources
  # (i.e., not in context of a GObj tree)
  #
! def DataSourceWrapper(connections=None, fields=(), attributes={}, init=1):
    source = _DataSourceWrapper()
    
    if connections: 
--- 553,559 ----
  # Wrapper for standalone DataSources
  # (i.e., not in context of a GObj tree)
  #
! def DataSourceWrapper(connections=None, fields=(), attributes={}, init=1, 
unicodeMode=0):
    source = _DataSourceWrapper()
    
    if connections: 
Index: gnue-common/src/datasources/drivers/DBSIG2/DataObject.py
diff -c gnue-common/src/datasources/drivers/DBSIG2/DataObject.py:1.1.2.1 
gnue-common/src/datasources/drivers/DBSIG2/DataObject.py:1.1.2.2
*** gnue-common/src/datasources/drivers/DBSIG2/DataObject.py:1.1.2.1    Thu Oct 
 9 21:21:09 2003
--- gnue-common/src/datasources/drivers/DBSIG2/DataObject.py    Fri Oct 10 
08:18:49 2003
***************
*** 114,139 ****
      try:
        return value.strftime(self._dateTimeFormat)
      except AttributeError:
        if value == None:
          return "NULL"
        elif type(value) == types.FloatType:
          if value==int(value):
            return "%d" % value
          else:
            return str(value)
  
!       elif type(value) == types.UnicodeType:
!         return "'%s'" % 
string.replace(value.encode(gConfig("textEncoding")),"'",
!                   "%s'" % self._escapeSingleQuote)
!       else:
  
!         try:
!           return "'%s'" % string.replace(str(value),"'",
!                     "%s'" % self._escapeSingleQuote)
!         except:
!           return "'%s'" % string.replace(value,"'",
!                     "%s'" % self._escapeSingleQuote)
  
  
    # Used by drivers with a unique id (like rowid) (see Oracle for example)
    def _checkForPrimaryId(self):
--- 114,164 ----
      try:
        return value.strftime(self._dateTimeFormat)
      except AttributeError:
+       
        if value == None:
          return "NULL"
+ 
+       elif type(value) == types.BooleanType:
+         if value:
+           return 'TRUE'
+         else:
+           return 'FALSE'
+         
+       elif type(value) == types.IntType:
+         return str(value)
+ 
+       elif type(value) == types.LongType:
+         return str(value)
+ 
        elif type(value) == types.FloatType:
          if value==int(value):
            return "%d" % value
          else:
            return str(value)
  
!       elif type(value) == types.StringType:
! 
!         if self._unicodeMode:
!           GDebug.printMesg(0,'WARNING: non-unicode passed to the dbdriver 
(%s)' % value)
!           
!         return "'%s'" % string.replace(value,
!                                        "'",
!                                        "%s'" % self._escapeSingleQuote)      
  
!       elif type(value) == types.UnicodeType:
!         return "'%s'" % 
string.replace(value.encode(self._connection._encoding),
!                                        "'",
!                                        "%s'" % self._escapeSingleQuote)
  
+       else:
+         err = _("Object of unknown type (%s) passed to DBSIG2 based 
dbdriver.") % type(value)
+         # FIXME: raise an error instead of just printing a warning, after 
some transition time
+         #raise GDataObjects.UnknownDataType, err
+         GDebug.printMesg (0,err)
+         return "'%s'" % string.replace(str(value),
+                                        "'",
+                                        "%s'" % self._escapeSingleQuote)
+         
  
    # Used by drivers with a unique id (like rowid) (see Oracle for example)
    def _checkForPrimaryId(self):
Index: gnue-common/src/datasources/drivers/DBSIG2/ResultSet.py
diff -c gnue-common/src/datasources/drivers/DBSIG2/ResultSet.py:1.1.2.1 
gnue-common/src/datasources/drivers/DBSIG2/ResultSet.py:1.1.2.2
*** gnue-common/src/datasources/drivers/DBSIG2/ResultSet.py:1.1.2.1     Thu Oct 
 9 21:21:10 2003
--- gnue-common/src/datasources/drivers/DBSIG2/ResultSet.py     Fri Oct 10 
08:18:49 2003
***************
*** 71,76 ****
--- 71,79 ----
              i = 0
              dict = {}
              for f in (rs):
+               if self._dataObject._unicodeMode and type(f)==types.StringType:
+                 f = unicode(f,self._dataObject._connection._encoding)
+                 
                dict[string.lower(self._fieldNames[i])] = f
                i += 1
              self._cachedRecords.append (self._recordSetClass(parent=self, \
Index: gnue-common/src/datasources/drivers/appserver/appserver/Connection.py
diff -c 
gnue-common/src/datasources/drivers/appserver/appserver/Connection.py:1.1.2.1 
gnue-common/src/datasources/drivers/appserver/appserver/Connection.py:1.1.2.2
*** 
gnue-common/src/datasources/drivers/appserver/appserver/Connection.py:1.1.2.1   
    Thu Oct  9 21:21:12 2003
--- gnue-common/src/datasources/drivers/appserver/appserver/Connection.py       
Fri Oct 10 08:18:50 2003
***************
*** 67,72 ****
--- 67,76 ----
      params = { 'host': connectData['host'],
                 'port': connectData['port'],
                 'transport': connectData['transport']}
+     
+     if connectData.has_key('encoding'):
+       GDebug.printMesg(1,"Appserver's dbdriver doesn't support 'encoding' 
parameter, as the transport"+\
+                        " encoding has to be 'utf-8'.")
  
      self._server = GComm.attach(connectData['rpctype'],params)
  
***************
*** 93,101 ****
    def cursor(self):
      return self._updateCursor
  
!   def request(self,table,filter,sort,fieldlist):
      listid = self._sm.request(self._sess_id,table,filter,sort,fieldlist)
!     return Appserver_ListCursor(self,listid,fieldlist)
  
    def call(self,classname,obj_id_list,methodname,parameters):
      self._sm.call(self._sess_id,classname,obj_id_list,methodname,parameters)
--- 97,105 ----
    def cursor(self):
      return self._updateCursor
  
!   def request(self,table,filter,sort,fieldlist,unicodeMode=0):
      listid = self._sm.request(self._sess_id,table,filter,sort,fieldlist)
!     return Appserver_ListCursor(self,listid,fieldlist,unicodeMode)
  
    def call(self,classname,obj_id_list,methodname,parameters):
      self._sm.call(self._sess_id,classname,obj_id_list,methodname,parameters)
***************
*** 130,140 ****
  
  
  class Appserver_ListCursor:
!   def __init__(self,dataCon,listid,fieldlist):
      self._dataCon=dataCon
      self._listid=listid
      self._fieldlist=fieldlist
      self._stackpos=0
  
    def fetch(self,count=5):
      if self._stackpos == -1:
--- 134,145 ----
  
  
  class Appserver_ListCursor:
!   def __init__(self,dataCon,listid,fieldlist,unicodeMode=0):
      self._dataCon=dataCon
      self._listid=listid
      self._fieldlist=fieldlist
      self._stackpos=0
+     self._unicodeMode=unicodeMode
  
    def fetch(self,count=5):
      if self._stackpos == -1:
***************
*** 156,162 ****
        dict = {}
        j = 1
        for fieldName in self._fieldlist:
!         dict[fieldName] = i[j]
          j=j+1
  
        dict["gnue_id"]=i[0]
--- 161,178 ----
        dict = {}
        j = 1
        for fieldName in self._fieldlist:
!         value = i[j]
!         
!         # convert Strings to unicode
!         if type(value) == types.StringType:
!           value = unicode(value,'utf-8')
! 
!         # recode unicode strings to standart encoding
!         if (type(value) == types.UnicodeType) and \
!                (not self._unicodeMode):
!           value = value.encode(gConfig('textEncoding'))
!             
!         dict[fieldName] = value
          j=j+1
  
        dict["gnue_id"]=i[0]
***************
*** 175,185 ****
  
  
  class Appserver_UpdateCursor:
!   def __init__(self,dataCon):
      self._dataCon=dataCon
      self._deleteList={}
      self._updateList={}
      self._updateKeyList={}
  
    def delete(self,classname,id):
      if not self._deleteList.has_key(classname):
--- 191,202 ----
  
  
  class Appserver_UpdateCursor:
!   def __init__(self,dataCon,unicodeMode=0):
      self._dataCon=dataCon
      self._deleteList={}
      self._updateList={}
      self._updateKeyList={}
+     self._unicodeMode=unicodeMode
  
    def delete(self,classname,id):
      if not self._deleteList.has_key(classname):
***************
*** 191,196 ****
--- 208,230 ----
      if not self._updateList.has_key(classname):
         self._updateList[classname]=[]
         self._updateKeyList[classname]=[]
+ 
+     # convert data to transfer encoding (utf-8)
+     for key in fieldDict.keys():
+       value=fieldDict[key]
+       
+       # convert Strings from local encoding to 'utf-8'
+       if type(value) == types.StringType:
+         fieldDict[key] = 
unicode(value,gConfig('textEncoding')).encode('utf-8')
+ 
+         # raise Warning if running in unicode mode
+         if self._unicodeMode:
+           GDebug.printMesg(0,'WARNING: non-unicode passed to the dbdriver 
(%s)' % value)
+           
+       # recode unicode strings to 'utf-8'
+       if type(value) == types.UnicodeType:
+         fieldDict[key] = value.encode('utf-8')
+               
      self._updateList[classname].append(fieldDict)
      self._updateKeyList[classname].append(id)
  
Index: gnue-common/src/datasources/drivers/appserver/appserver/DataObject.py
diff -c 
gnue-common/src/datasources/drivers/appserver/appserver/DataObject.py:1.1.2.1 
gnue-common/src/datasources/drivers/appserver/appserver/DataObject.py:1.1.2.2
*** 
gnue-common/src/datasources/drivers/appserver/appserver/DataObject.py:1.1.2.1   
    Thu Oct  9 21:21:12 2003
--- gnue-common/src/datasources/drivers/appserver/appserver/DataObject.py       
Fri Oct 10 08:18:50 2003
***************
*** 96,102 ****
        raise GDataObjects.ConnectionError, err
  
      try:
!       listcursor = 
self._dataConnection.request(self.table,filter,sort,fieldlist)
      except Exception, msg:
        tmsg = _("Error during creation of object list \n\n --- %s ---)") % msg
        raise GDataObjects.ConnectionError, tmsg
--- 96,103 ----
        raise GDataObjects.ConnectionError, err
  
      try:
!       listcursor = 
self._dataConnection.request(self.table,filter,sort,fieldlist,\
!                                                 self._dataObject._unicodeMode)
      except Exception, msg:
        tmsg = _("Error during creation of object list \n\n --- %s ---)") % msg
        raise GDataObjects.ConnectionError, tmsg
Index: gnue-common/src/datasources/drivers/postgresql/Base/Connection.py
diff -c 
gnue-common/src/datasources/drivers/postgresql/Base/Connection.py:1.1.2.1 
gnue-common/src/datasources/drivers/postgresql/Base/Connection.py:1.1.2.2
*** gnue-common/src/datasources/drivers/postgresql/Base/Connection.py:1.1.2.1   
Thu Oct  9 21:21:26 2003
--- gnue-common/src/datasources/drivers/postgresql/Base/Connection.py   Fri Oct 
10 08:18:50 2003
***************
*** 54,59 ****
--- 54,88 ----
    _pg_connectString = 'host=%s dbname=%s user=%s password=%s port=%s'
    _pg_driver = None
  
+   _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
+ 
    def connect(self                                                            
                                                                                
                                                                                
              , connectData={}):
  
      if not hasattr(self,'_DatabaseError'):
***************
*** 83,102 ****
        raise GDataObjects.LoginError, value
  
      try:
-       encoding = ""
        try:
!         encoding = connectData['encoding']
        except KeyError:
!         # if encoding is not defined in connectData use gnue.conf setting 
instead
!         try:
!           encoding = gConfig('encoding')
!         except:
!           pass
! 
!       if encoding.upper() not in ("",'DEFAULT'):
!         GDebug.printMesg(1,'Setting postgresql client_encoding to %s' % 
encoding)
!         cursor = self.native.cursor()
!         cursor.execute("SET CLIENT_ENCODING TO '%s'" % encoding)
          cursor.close()
  
      except self._DatabaseError:
--- 112,134 ----
        raise GDataObjects.LoginError, value
  
      try:
        try:
!         self._encoding = connectData['encoding']
!       except KeyError:
!         pass
! 
!       try:
!         self._pg_encoding = self._pg_encTable[self._encoding]
        except KeyError:
!         GDebug.printMesg(1,_("Encoding '%s' is not supported by postgresql 
dbdriver.") % \
!                          self._encoding + _('Using default 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))
!         cursor = self._dataConnection.cursor()
!         cursor.execute("SET CLIENT_ENCODING TO '%s'" % self._pg_encoding)
          cursor.close()
  
      except self._DatabaseError:




reply via email to

[Prev in Thread] Current Thread [Next in Thread]