Update of /usr/cvs/Public/pygresql/module
In directory druid.net:/tmp/cvs-serv3551/module

Modified Files:
        TEST_PyGreSQL_dbapi20.py dbapi20.py pgdb.py 
Log Message:
Escape and unescape Binary objects (as suggested by Dan McDonald).
To see the diffs for this commit:
   
http://www.druid.net/pygresql/viewcvs.cgi/cvs/pygresql/module/TEST_PyGreSQL_dbapi20.py.diff?r1=1.16&r2=1.17

Index: TEST_PyGreSQL_dbapi20.py
===================================================================
RCS file: /usr/cvs/Public/pygresql/module/TEST_PyGreSQL_dbapi20.py,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -r1.16 -r1.17
--- TEST_PyGreSQL_dbapi20.py    2 Apr 2009 22:18:59 -0000       1.16
+++ TEST_PyGreSQL_dbapi20.py    22 Oct 2009 17:46:45 -0000      1.17
@@ -1,5 +1,5 @@
 #!/usr/bin/env python
-# $Id: TEST_PyGreSQL_dbapi20.py,v 1.16 2009/04/02 22:18:59 cito Exp $
+# $Id: TEST_PyGreSQL_dbapi20.py,v 1.17 2009/10/22 17:46:45 cito Exp $
 
 import dbapi20
 import unittest
@@ -63,8 +63,9 @@
 
     def test_fetch_2_rows(self):
         Decimal = pgdb.decimal_type()
-        values = ['test', 'test', True, 5, 6L, 5.7,
-            Decimal('234.234234'), Decimal('75.45'),
+        values = ['test', pgdb.Binary('\xff\x52\xb2'),
+            True, 5, 6L,
+            5.7, Decimal('234.234234'), Decimal('75.45'),
             '2008-10-20 15:25:35', 7897234L]
         table = self.table_prefix + 'booze'
         con = self._connect()

   
http://www.druid.net/pygresql/viewcvs.cgi/cvs/pygresql/module/dbapi20.py.diff?r1=1.4&r2=1.5

Index: dbapi20.py
===================================================================
RCS file: /usr/cvs/Public/pygresql/module/dbapi20.py,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- dbapi20.py  1 Nov 2008 18:37:55 -0000       1.4
+++ dbapi20.py  22 Oct 2009 17:46:45 -0000      1.5
@@ -11,14 +11,17 @@
     -- Ian Bicking
 '''
 
-__rcs_id__  = '$Id: dbapi20.py,v 1.4 2008/11/01 18:37:55 cito Exp $'
-__version__ = '$Revision: 1.4 $'[11:-2]
+__rcs_id__  = '$Id: dbapi20.py,v 1.5 2009/10/22 17:46:45 cito Exp $'
+__version__ = '$Revision: 1.5 $'[11:-2]
 __author__ = 'Stuart Bishop <[email protected]>'
 
 import unittest
 import time
 
 # $Log: dbapi20.py,v $
+# Revision 1.5  2009/10/22 17:46:45  cito
+# Escape and unescape Binary objects (as suggested by Dan McDonald).
+#
 # Revision 1.4  2008/11/01 18:37:55  cito
 # Updated the dbapi20 test module. Exposed the exceptions as attributes of the 
connection.
 #
@@ -109,16 +112,16 @@
         cursor.execute(self.ddl2)
 
     def setUp(self):
-        ''' self.drivers should override this method to perform required setup
+        """self.drivers should override this method to perform required setup
             if any is necessary, such as creating the database.
-        '''
+        """
         pass
 
     def tearDown(self):
-        ''' self.drivers should override this method to perform required 
cleanup
+        """self.drivers should override this method to perform required cleanup
             if any is necessary, such as deleting the test database.
             The default drops the tables that may be created.
-        '''
+        """
         con = self._connect()
         try:
             cur = con.cursor()
@@ -175,8 +178,9 @@
             self.fail("Driver doesn't define paramstyle")
 
     def test_Exceptions(self):
-        # Make sure required exceptions exist, and are in the
-        # defined heirarchy.
+        """Make sure required exceptions exist, and are in the
+        defined hierarchy.
+        """
         self.failUnless(issubclass(self.driver.Warning,StandardError))
         self.failUnless(issubclass(self.driver.Error,StandardError))
         self.failUnless(
@@ -202,12 +206,14 @@
             )
 
     def test_ExceptionsAsConnectionAttributes(self):
-        # OPTIONAL EXTENSION
-        # Test for the optional DB API 2.0 extension, where the exceptions
-        # are exposed as attributes on the Connection object
-        # I figure this optional extension will be implemented by any
-        # driver author who is using this test suite, so it is enabled
-        # by default.
+        """Optional extension
+
+        Test for the optional DB API 2.0 extension, where the exceptions
+        are exposed as attributes on the Connection object
+        I figure this optional extension will be implemented by any
+        driver author who is using this test suite, so it is enabled
+        by default.
+        """
         con = self._connect()
         drv = self.driver
         self.failUnless(con.Warning is drv.Warning)
@@ -220,7 +226,6 @@
         self.failUnless(con.ProgrammingError is drv.ProgrammingError)
         self.failUnless(con.NotSupportedError is drv.NotSupportedError)
 
-
     def test_commit(self):
         con = self._connect()
         try:
@@ -528,9 +533,9 @@
         ]
 
     def _populate(self):
-        ''' Return a list of sql commands to setup the DB for the fetch
+        """Return a list of sql commands to setup the DB for the fetch
             tests.
-        '''
+        """
         populate = [
             "insert into %sbooze values ('%s')" % (self.table_prefix,s)
                 for s in self.samples
@@ -702,10 +707,10 @@
             con.close()
 
     def help_nextset_setUp(self,cur):
-        ''' Should create a procedure called deleteme
+        """Should create a procedure called deleteme
             that returns two result sets, first the
-           number of rows in booze then "name from booze"
-        '''
+            number of rows in booze then "name from booze"
+        """
         raise NotImplementedError,'Helper not implemented'
         #sql="""
         #    create procedure deleteme as
@@ -717,7 +722,7 @@
         #cur.execute(sql)
 
     def help_nextset_tearDown(self,cur):
-        'If cleaning up is needed after nextSetTest'
+        """If cleaning up is needed after nextSetTest"""
         raise NotImplementedError,'Helper not implemented'
         #cur.execute("drop procedure deleteme")
 
@@ -754,7 +759,7 @@
         raise NotImplementedError,'Drivers need to override this test'
 
     def test_arraysize(self):
-        # Not much here - rest of the tests for this are in test_fetchmany
+        """Not much here - rest of the tests for this are in test_fetchmany"""
         con = self._connect()
         try:
             cur = con.cursor()
@@ -774,7 +779,7 @@
             con.close()
 
     def test_setoutputsize_basic(self):
-        # Basic test is to make sure setoutputsize doesn't blow up
+        """Basic test is to make sure setoutputsize doesn't blow up"""
         con = self._connect()
         try:
             cur = con.cursor()
@@ -785,7 +790,7 @@
             con.close()
 
     def test_setoutputsize(self):
-        # Real test for setoutputsize is driver dependant
+        """Real test for setoutputsize is driver dependant"""
         raise NotImplementedError,'Driver need to override this test'
 
     def test_None(self):

   
http://www.druid.net/pygresql/viewcvs.cgi/cvs/pygresql/module/pgdb.py.diff?r1=1.55&r2=1.56

Index: pgdb.py
===================================================================
RCS file: /usr/cvs/Public/pygresql/module/pgdb.py,v
retrieving revision 1.55
retrieving revision 1.56
diff -u -r1.55 -r1.56
--- pgdb.py     2 Apr 2009 22:18:59 -0000       1.55
+++ pgdb.py     22 Oct 2009 17:46:45 -0000      1.56
@@ -4,7 +4,7 @@
 #
 # Written by D'Arcy J.M. Cain
 #
-# $Id: pgdb.py,v 1.55 2009/04/02 22:18:59 cito Exp $
+# $Id: pgdb.py,v 1.56 2009/10/22 17:46:45 cito Exp $
 #
 
 """pgdb - DB-API 2.0 compliant module for PygreSQL.
@@ -109,7 +109,11 @@
         lambda v: v in '0123456789.-', value)))
 
 
-_cast = {'bool': _cast_bool,
+def _cast_bytea(value):
+    return unescape_bytea(value)
+
+
+_cast = {'bool': _cast_bool, 'bytea': _cast_bytea,
     'int2': int, 'int4': int, 'serial': int,
     'int8': long, 'oid': long, 'oid8': long,
     'float4': float, 'float8': float,
@@ -192,7 +196,11 @@
         elif isinstance(val, unicode):
             val = val.encode( 'utf8' )
         if isinstance(val, str):
-            val = "'%s'" % self._cnx.escape_string(val)
+            if isinstance(val, Binary):
+                # the 'E' notation exists only since PostgreSQL 8.1
+                val = "E'%s'" % self._cnx.escape_bytea(val)
+            else:
+                val = "'%s'" % self._cnx.escape_string(val)
         elif isinstance(val, (int, long, float)):
             pass
         elif val is None:
@@ -572,9 +580,8 @@
     """construct an object holding a time stamp from the given ticks value."""
     return Timestamp(*time.localtime(ticks)[:6])
 
-def Binary(value):
+class Binary(str):
     """construct an object capable of holding a binary (long) string value."""
-    return value
 
 
 # If run as script, print some information:

_______________________________________________
PyGreSQL mailing list
[email protected]
http://mailman.vex.net/mailman/listinfo/pygresql

Reply via email to