-# From pgdb
-def _quote(x):
- if isinstance(x, DateTimeType):
- x = str(x)
- elif isinstance(x, unicode):
- x = x.encode( 'utf-8' )
-
- if isinstance(x, types.StringType):
- x = "'%s'" % str(x).replace("\\", "\\\\").replace("'", "''")
- elif isinstance(x, (types.IntType, types.LongType, types.FloatType)):
- pass
- elif x is None:
- x = 'NULL'
- elif isinstance(x, (types.ListType, types.TupleType, set)):
- x = 'ARRAY[%s]' % ', '.join(map(lambda x: str(_quote(x)), x))
- elif hasattr(x, '__pg_repr__'):
- x = x.__pg_repr__()
- else:
- raise pgdb.InterfaceError, 'do not know how to handle type %s' % type(x)
- return x
-