[Zope3-checkins] SVN: Zope3/trunk/src/zope/app/rdb/__init__.py Removed dependency from the 'types' and 'string' modules

Dmitry Vasiliev dima at hlabs.spb.ru
Sun Aug 21 06:05:32 EDT 2005


Log message for revision 38019:
  Removed dependency from the 'types' and 'string' modules
  

Changed:
  U   Zope3/trunk/src/zope/app/rdb/__init__.py

-=-
Modified: Zope3/trunk/src/zope/app/rdb/__init__.py
===================================================================
--- Zope3/trunk/src/zope/app/rdb/__init__.py	2005-08-21 08:59:07 UTC (rev 38018)
+++ Zope3/trunk/src/zope/app/rdb/__init__.py	2005-08-21 10:05:32 UTC (rev 38019)
@@ -19,8 +19,7 @@
 
 $Id$
 """
-import types, string, time, random, thread
-from types import StringTypes
+import time, random, thread
 from urllib import unquote_plus
 
 from persistent import Persistent
@@ -31,42 +30,42 @@
 from zope.security.checker import NamesChecker
 
 from zope.interface import implements
-from zope.app import zapi
 from zope.app.container.contained import Contained
 from zope.app.rdb.interfaces import DatabaseException
 from zope.app.rdb.interfaces import IResultSet
 from zope.app.rdb.interfaces import IZopeConnection, IZopeCursor
-from zope.app.rdb.interfaces import ISQLCommand
 from zope.app.rdb.interfaces import IManageableZopeDatabaseAdapter
-from zope.app.rdb.interfaces import IZopeDatabaseAdapter
 from zope.thread import local
 
 
 DEFAULT_ENCODING = "utf-8"
 
 def sqlquote(x):
-    """
+    r"""
     Escape data suitable for inclusion in generated ANSI SQL92 code for
     cases where bound variables are not suitable.
 
-    >>> sqlquote('''Hi''')
+    >>> sqlquote("Hi")
     "'Hi'"
-    >>> sqlquote('''It's mine''')
+    >>> sqlquote("It's mine")
     "'It''s mine'"
+    >>> sqlquote("\\'")
+    "'\\\\'''"
+    >>> sqlquote(u"\\'")
+    u"'\\\\'''"
     >>> sqlquote(32)
     32
     >>> sqlquote(None)
     'NULL'
     """
-    if type(x) == types.StringType:
-        x = "'" + string.replace(
-            string.replace(str(x), '\\', '\\\\'), "'", "''") + "'"
-    elif type(x) in (types.IntType, types.LongType, types.FloatType):
+    if isinstance(x, (str, unicode)):
+        x = "'%s'" % x.replace('\\', '\\\\').replace("'", "''")
+    elif isinstance(x, (int, long, float)):
         pass
     elif x is None:
         x = 'NULL'
     else:
-        raise TypeError, 'do not know how to handle type %s' % type(x)
+        raise TypeError('do not know how to handle type %s' % type(x))
     return x
 
 
@@ -219,11 +218,10 @@
        dbname       database name
        parameters   a mapping of additional parameters to their values
     """
-    if not isinstance(dsn, StringTypes):
-        raise ValueError('The dsn is not a string. It is a %s'
-                         % repr(type(dsn)))
+    if not isinstance(dsn, (str, unicode)):
+        raise ValueError('The dsn is not a string. It is a %r' % type(dsn))
     if not dsn.startswith('dbi://'):
-        raise ValueError('Invalid DSN; must start with "dbi://": %s' % dsn)
+        raise ValueError('Invalid DSN; must start with "dbi://": %r' % dsn)
 
     result = {}
 



More information about the Zope3-Checkins mailing list