[Zope3-checkins] CVS: Products3/pypgsqlda - adapter.py:1.6.2.3

Christian Theune ct@gocept.com
Sun, 13 Apr 2003 19:06:18 -0400


Update of /cvs-repository/Products3/pypgsqlda
In directory cvs.zope.org:/tmp/cvs-serv22541

Modified Files:
      Tag: tiran-pypgsql_types-branch
	adapter.py 
Log Message:
 - some typos and minor comments
 
 - whitespace normalization
 
 - adapting to zope/python style guide
 
 - expanded single character variable names
 
 - removed old "atoi" reference
 
 - decided to ignore the "day" field for time types
 
 - renamed "convertAclitem" to "convertACLItem" which is correct camel case


=== Products3/pypgsqlda/adapter.py 1.6.2.2 => 1.6.2.3 ===
--- Products3/pypgsqlda/adapter.py:1.6.2.2	Mon Apr  7 12:17:31 2003
+++ Products3/pypgsqlda/adapter.py	Sun Apr 13 19:06:17 2003
@@ -37,11 +37,11 @@
         conn_info = parseDSN(self.dsn)
         params = conn_info['parameters']
         
-        # XXX ADd options and port
+        # XXX Add options and port
         if params.has_key('client_encoding'):
             client_encoding = params['client_encoding']
         else:
-            client_encoding = 'ISO-8859-1'      # XXX where do i get the system default?
+            client_encoding = 'ISO-8859-1'      # XXX where do i get the zope default?
 
         return PgSQL.connect(user=conn_info['username'],
                              password=conn_info['password'],
@@ -81,23 +81,21 @@
         return map(self.__class__(self.cfun), data)
         
     def __call__(self, data):
-        if not data: return NULL
-        if self.isPgArray(data): return self.convertArray(data)
+        if not data: 
+            return NULL
+        if self.isPgArray(data): 
+            return self.convertArray(data)
         retval = self.cfun(data)
-        #import pdb;
-        #pdb.set_trace()
         return retval
-        
 
-def _sec2my(sec):
-    """ Return second and mikro for a float second"""
+def _sec2micro(sec):
+    """ Return second and micro for a float second"""
     # from psycopgda
-    sec, my = divmod(sec, 1.0)
-    my = round(my * 1000000) 
-    return (sec, my)
+    sec, micro = divmod(sec, 1.0)
+    micro = round(micro * 1000000) 
+    return (sec, micro)
 
 # Converters
-
  
 # *********************************
 # ***   byte and string types   ***
@@ -134,7 +132,7 @@
 
 def convertSmallInt(data):
     """Converts a string containing a small int (int2) to int"""
-    return string.atoi(unicode(data))    
+    return int(unicode(data))    
 
 def convertInt(data):
     """Return an int"""
@@ -155,36 +153,38 @@
     
 def convertTime(data):
     """Converts a mxDateTime.time object to a datetime.time object"""
-    # XXX: day?
-    d, h, min, sec = data.tuple()
-    sec, my = _sec2my(sec)
-    return datetime.time(h, min, sec, my)
+    day, hour, min, sec = data.tuple()
+    sec, micro = _sec2micro(sec)
+    return datetime.time(hour, min, sec, micro)
 
 def convertTimeTZ(data):
     """Converts a mxDateTime.time object to a datetime.time object with timezone"""
-    # XXX: day?
-    d, h, min, sec = data.tuple()
-    sec, my = _sec2my(sec)
+    day, hour, min, sec = data.tuple()
+    sec, micro = _sec2micro(sec)
     tzoffset = data.gmtoffset().minutes
-    if tzoffset: tz = datetimeutils.tzinfo(tzoffset) 
-    else: tz = datetimeutils.tzinfo(0)
-    return datetime.time(h, min, sec, my, tz)
+    if tzoffset:
+        tz = datetimeutils.tzinfo(tzoffset)
+    else: 
+        tz = datetimeutils.tzinfo(0)
+    return datetime.time(hour, min, sec, micro, tz)
 
 def convertTimestamp(data):
     """Converts a mxDateTime.datetime object to a datetime.datetime object"""
-    y, m, d, h, min, sec, dayOfWeek, dayOfYear, dst = data.tuple()
-    sec, my = _sec2my(sec)
-    return datetime.datetime(y, m, d, h, min, sec, my)
+    year, month, day, hour, min, sec, dayOfWeek, dayOfYear, dst = data.tuple()
+    sec, micro = _sec2micro(sec)
+    return datetime.datetime(year, month, day, hour, min, sec, micro)
 
 def convertTimestampTZ(data):
     """Converts a mxDateTime.time object to a datetime.time object with timezone"""
-    y, m, d, h, min, sec, dayOfWeek, dayOfYear, dst = data.tuple()
-    sec, my = _sec2my(sec)
+    year, month, day, hour, min, sec, dayOfWeek, dayOfYear, dst = data.tuple()
+    sec, micro = _sec2micro(sec)
     # time zone offset in minutes
     tzoffset = data.gmtoffset().minutes
-    if tzoffset: tz = datetimeutils.tzinfo(tzoffset) 
-    else: tz = datetimeutils.tzinfo(0)
-    return datetime.datetime(y, m, d, h, min, sec, my, tz)
+    if tzoffset: 
+        tz = datetimeutils.tzinfo(tzoffset) 
+    else: 
+        tz = datetimeutils.tzinfo(0)
+    return datetime.datetime(year, month, day, hour, min, sec, micro, tz)
 
 def convertInterval(data):
     """Converts a mxDateTime.DateTimeDelta object to a datetime.timedelta object
@@ -195,9 +195,9 @@
     XXX BUG BUG BUG
     """
     days, hours, min, sec = data.tuple()
-    sec, my = _sec2my(sec)
+    sec, micro = _sec2micro(sec)
     return datetime.timedelta(days=days, hours=hours, minutes=min,
-                              seconds=sec, microseconds=my)
+                              seconds=sec, microseconds=micro)
                               
 def convertPoint(data):
     return pgtypes.Point2d(data)
@@ -222,18 +222,16 @@
         return pgtypes.OpenPath(data)
     if pgtypes.isClosedPath(data):
         return pgtypes.ClosedPath(data)
-    raise TypeError
+    raise TypeError, "Unknown type of path."
 
 def convertINet(data):
     return convertUnicode(data)
 
-def convertAclitem(data):
-    """
-    unnested PgArray with string 'key=val'
-    """
+def convertACLItem(data):
+    """Unnested PgArray with string 'key=val'"""
     retval = {}
     for item in data:
-        key, val = unicode(item).split('=')
+        key, val = unicode(item).split('=')     # XXX may there be more than on "=" ?
         retval[key] = val
     return retval
 
@@ -241,8 +239,9 @@
     """
     int int .... NOT PgArray
     """
-    if not data: return None
-    return tuple([ int(item) for item in data.split(' ')])
+    if not data: 
+        return None
+    return tuple([long(item) for item in data.split(' ')])
 
 
 def debug(data):
@@ -259,7 +258,7 @@
 
 converter_mapping = {
     'abstime'   : convertUnicode,    # PG_ABSTIME        XXXtime (obsolet)
-    'aclitem'   : convertAclitem,   # PG_ACLITEM    S   
+    'aclitem'   : convertACLItem,    # PG_ACLITEM    S   
     'blob'      : convertBlob,      # PG_BLOB           string
     'bool'      : convertBool,      # PG_BOOL           boolean
     'box'       : convertBox,       # PG_BOX            geometric.box