commit-gnue
[Top][All Lists]
Advanced

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

gnue-appserver/src geasInstance.py


From: Reinhard Mueller
Subject: gnue-appserver/src geasInstance.py
Date: Fri, 17 Oct 2003 05:03:44 -0400

CVSROOT:        /cvsroot/gnue
Module name:    gnue-appserver
Branch:         
Changes by:     Reinhard Mueller <address@hidden>       03/10/17 05:03:44

Modified files:
        src            : geasInstance.py 

Log message:
        Correctly typecast values between DB driver and appserver. Notably, 
this fixes
        NULL values for strings.

CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue-appserver/src/geasInstance.py.diff?tr1=1.24&tr2=1.25&r1=text&r2=text

Patches:
Index: gnue-appserver/src/geasInstance.py
diff -c gnue-appserver/src/geasInstance.py:1.24 
gnue-appserver/src/geasInstance.py:1.25
*** gnue-appserver/src/geasInstance.py:1.24     Thu Oct 16 19:03:43 2003
--- gnue-appserver/src/geasInstance.py  Fri Oct 17 05:03:43 2003
***************
*** 19,25 ****
  # write to the Free Software Foundation, Inc., 59 Temple Place
  # - Suite 330, Boston, MA 02111-1307, USA.
  #
! # $Id: geasInstance.py,v 1.24 2003/10/16 23:03:43 reinhard Exp $
  
  import types
  
--- 19,25 ----
  # write to the Free Software Foundation, Inc., 59 Temple Place
  # - Suite 330, Boston, MA 02111-1307, USA.
  #
! # $Id: geasInstance.py,v 1.25 2003/10/17 09:03:43 reinhard Exp $
  
  import types
  
***************
*** 48,66 ****
      if propertydef.gnue_type == "id" or \
         propertydef.gnue_type == "string":      
        # String property (the id is actually a string, too)
!       value = self._record.getField (propertydef.column)
!       try:
          # encode unicode values to utf-8 (normal case)
!         return value.encode('utf-8')
!       except AttributeError:
          # if not UnicodeType then return normal string
!         return str(value)
      
  
      elif propertydef.gnue_type == "number":
        # Number property
        s = self._record.getField (propertydef.column)
!       if propertydef.gnue_scale == 0:
          # ... without fractional part
          try:
            return int (s)
--- 48,73 ----
      if propertydef.gnue_type == "id" or \
         propertydef.gnue_type == "string":      
        # String property (the id is actually a string, too)
!       s = self._record.getField (propertydef.column)
!       if s is None:
!         return ""
!       elif type (s) == types.UnicodeType:
          # encode unicode values to utf-8 (normal case)
!         return s.encode ('utf-8')
!       elif type (s) == types.StringType:
          # if not UnicodeType then return normal string
!         return s
!       else:
!         raise Exception, ("Database returned invalid value '%s' for " + \
!                           "property '%s'") % (s, propertyname)
      
  
      elif propertydef.gnue_type == "number":
        # Number property
        s = self._record.getField (propertydef.column)
!       if s is None:
!         return ""
!       elif propertydef.gnue_scale == 0:
          # ... without fractional part
          try:
            return int (s)
***************
*** 79,85 ****
        # Boolean property
        s = self._record.getField (propertydef.column)
        if s is None:
!         return None
        elif s in [0, "0", "f", "F", "false", "FALSE", "n", "N", "no", "NO"]:
          return 0
        elif s in [1, "1", "t", "T", "true", "true", "y", "Y", "yes", "YES"]:
--- 86,92 ----
        # Boolean property
        s = self._record.getField (propertydef.column)
        if s is None:
!         return ""
        elif s in [0, "0", "f", "F", "false", "FALSE", "n", "N", "no", "NO"]:
          return 0
        elif s in [1, "1", "t", "T", "true", "true", "y", "Y", "yes", "YES"]:
***************
*** 90,96 ****
  
      elif self._classdef.classes.has_key (propertydef.gnue_type):
        # Reference property: gnue_type is a classname
!       return self._record.getField (propertydef.column)
  
      # TODO: Missing property types:
      #       * datetime
--- 97,107 ----
  
      elif self._classdef.classes.has_key (propertydef.gnue_type):
        # Reference property: gnue_type is a classname
!       s = self._record.getField (propertydef.column)
!       if s is None:
!         return ""
!       else:
!         return s
  
      # TODO: Missing property types:
      #       * datetime
***************
*** 107,117 ****
    def get (self, propertylist):
      result = []
      for property in propertylist:
!       value = self._getValue (property)
!       # transfer None as ""
!       if value == None:
!         value = ""
!       result.append (value)
      return result
  
    # 
---------------------------------------------------------------------------
--- 118,124 ----
    def get (self, propertylist):
      result = []
      for property in propertylist:
!       result.append (self._getValue (property))
      return result
  
    # 
---------------------------------------------------------------------------
***************
*** 126,138 ****
      if propertydef.gnue_type == "id" or \
         propertydef.gnue_type == "string":      
        # String property (the id is actually a string, too)
!       try:
          # decode unicode values from utf-8 
!         value = unicode(value,'utf-8')
!       except (AttributeError, UnicodeError):
!         # return normal string in all other cases (this will raise a warning 
by
!         # the dbdriver
!         value = str(value)
            
      elif propertydef.gnue_type == "number":
        # TODO: check if value is an number
--- 133,145 ----
      if propertydef.gnue_type == "id" or \
         propertydef.gnue_type == "string":      
        # String property (the id is actually a string, too)
!       if value == "":
!         value = None
!       else:
!         if type (value) is not types.StringType:
!           value = str (value)
          # decode unicode values from utf-8 
!         value = unicode (value, 'utf-8')
            
      elif propertydef.gnue_type == "number":
        # TODO: check if value is an number




reply via email to

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