[SQL-CVS] r2967 - in SQLObject/trunk/sqlobject: . inheritance manager util
SQLObject is a Python ORM.
Brought to you by:
ianbicking,
phd
From: <sub...@co...> - 2007-09-20 14:40:47
|
Author: phd Date: 2007-09-20 08:40:33 -0600 (Thu, 20 Sep 2007) New Revision: 2967 Modified: SQLObject/trunk/sqlobject/col.py SQLObject/trunk/sqlobject/constraints.py SQLObject/trunk/sqlobject/converters.py SQLObject/trunk/sqlobject/dbconnection.py SQLObject/trunk/sqlobject/inheritance/__init__.py SQLObject/trunk/sqlobject/main.py SQLObject/trunk/sqlobject/manager/command.py SQLObject/trunk/sqlobject/sqlbuilder.py SQLObject/trunk/sqlobject/sresults.py SQLObject/trunk/sqlobject/util/csvexport.py Log: Use isinstance(..., basestring) instead of isinstance(..., (str, unicode)); stop emulating basestring, stop using types.StringTypes and type(""). Modified: SQLObject/trunk/sqlobject/col.py =================================================================== --- SQLObject/trunk/sqlobject/col.py 2007-09-19 20:52:35 UTC (rev 2966) +++ SQLObject/trunk/sqlobject/col.py 2007-09-20 14:40:33 UTC (rev 2967) @@ -1297,7 +1297,7 @@ return None if isinstance(value, float): value = str(value) - if isinstance(value, (str, unicode)): + if isinstance(value, basestring): connection = state.soObject._connection if hasattr(connection, "decimalSeparator"): value = value.replace(connection.decimalSeparator, ".") Modified: SQLObject/trunk/sqlobject/constraints.py =================================================================== --- SQLObject/trunk/sqlobject/constraints.py 2007-09-19 20:52:35 UTC (rev 2966) +++ SQLObject/trunk/sqlobject/constraints.py 2007-09-20 14:40:33 UTC (rev 2967) @@ -19,7 +19,7 @@ ValueError.__init__(self, fullDesc, *args) def isString(obj, col, value): - if type(value) is not type(""): + if not isinstance(value, str): raise BadValue("only allows strings", obj, col, value) def notNull(obj, col, value): Modified: SQLObject/trunk/sqlobject/converters.py =================================================================== --- SQLObject/trunk/sqlobject/converters.py 2007-09-19 20:52:35 UTC (rev 2966) +++ SQLObject/trunk/sqlobject/converters.py 2007-09-20 14:40:33 UTC (rev 2967) @@ -115,8 +115,8 @@ assert 0, "Database %s unknown" % db return "'%s'" % value -registerConverter(type(""), StringLikeConverter) -registerConverter(type(u""), StringLikeConverter) +registerConverter(str, StringLikeConverter) +registerConverter(unicode, StringLikeConverter) registerConverter(array_type, StringLikeConverter) registerConverter(buffer_type, StringLikeConverter) Modified: SQLObject/trunk/sqlobject/dbconnection.py =================================================================== --- SQLObject/trunk/sqlobject/dbconnection.py 2007-09-19 20:52:35 UTC (rev 2966) +++ SQLObject/trunk/sqlobject/dbconnection.py 2007-09-20 14:40:33 UTC (rev 2967) @@ -521,7 +521,7 @@ def _SO_selectOneAlt(self, so, columnNames, condition): if columnNames: - columns = [isinstance(x, (str, unicode)) and sqlbuilder.SQLConstant(x) or x for x in columnNames] + columns = [isinstance(x, basestring) and sqlbuilder.SQLConstant(x) or x for x in columnNames] else: columns = None return self.queryOne(self.sqlrepr(sqlbuilder.Select(columns, Modified: SQLObject/trunk/sqlobject/inheritance/__init__.py =================================================================== --- SQLObject/trunk/sqlobject/inheritance/__init__.py 2007-09-19 20:52:35 UTC (rev 2966) +++ SQLObject/trunk/sqlobject/inheritance/__init__.py 2007-09-20 14:40:33 UTC (rev 2967) @@ -6,13 +6,6 @@ import iteration -try: - basestring -except NameError: # Python 2.2 - import types - basestring = (types.StringType, types.UnicodeType) - - def tablesUsedDict(obj, db): if hasattr(obj, "tablesUsedDict"): return obj.tablesUsedDict(db) @@ -49,7 +42,7 @@ #DSM: because if the user uses clauseTables #DSM: (and normal string SELECT), he must know what he wants #DSM: and will do himself the relationship between classes. - if type(clause) is not str: + if not isinstance(clause, str): tableRegistry = {} allClasses = classregistry.registry( sourceClass.sqlmeta.registry).allClasses() @@ -222,7 +215,7 @@ for column in currentClass.sqlmeta.columnDefinitions.values(): if column.name == 'childName': continue - if type(column) == ForeignKey: + if isinstance(column, ForeignKey): continue setattr(cls.q, column.name, getattr(currentClass.q, column.name)) Modified: SQLObject/trunk/sqlobject/main.py =================================================================== --- SQLObject/trunk/sqlobject/main.py 2007-09-19 20:52:35 UTC (rev 2966) +++ SQLObject/trunk/sqlobject/main.py 2007-09-20 14:40:33 UTC (rev 2967) @@ -1618,7 +1618,7 @@ return items def setConnection(cls, value): - if isinstance(value, (str, unicode)): + if isinstance(value, basestring): value = dbconnection.connectionForURI(value) cls._connection = value setConnection = classmethod(setConnection) @@ -1663,7 +1663,7 @@ return obj elif type(obj) is type(1L): return int(obj) - elif type(obj) is type(""): + elif isinstance(obj, str): try: return int(obj) except ValueError: @@ -1676,7 +1676,7 @@ return klass(obj) elif type(obj) is type(1L): return klass(int(obj)) - elif type(obj) is type(""): + elif isinstance(obj, str): return klass(int(obj)) elif obj is None: return None Modified: SQLObject/trunk/sqlobject/manager/command.py =================================================================== --- SQLObject/trunk/sqlobject/manager/command.py 2007-09-19 20:52:35 UTC (rev 2966) +++ SQLObject/trunk/sqlobject/manager/command.py 2007-09-20 14:40:33 UTC (rev 2967) @@ -1256,7 +1256,7 @@ return upgraders[-1] def update_sys_path(paths, verbose): - if isinstance(paths, (str, unicode)): + if isinstance(paths, basestring): paths = [paths] for path in paths: path = os.path.abspath(path) Modified: SQLObject/trunk/sqlobject/sqlbuilder.py =================================================================== --- SQLObject/trunk/sqlobject/sqlbuilder.py 2007-09-19 20:52:35 UTC (rev 2966) +++ SQLObject/trunk/sqlobject/sqlbuilder.py 2007-09-20 14:40:33 UTC (rev 2967) @@ -80,7 +80,7 @@ safeSQLRE = re.compile(r'^[a-zA-Z_][a-zA-Z0-9_\.]*$') def sqlIdentifier(obj): # some db drivers return unicode column names - return isinstance(obj, types.StringTypes) and bool(safeSQLRE.search(obj.strip())) + return isinstance(obj, basestring) and bool(safeSQLRE.search(obj.strip())) def execute(expr, executor): @@ -584,7 +584,7 @@ # None doesn't filter anything, it's just a no-op: return self clause = self.ops['clause'] - if isinstance(clause, (str, unicode)): + if isinstance(clause, basestring): clause = SQLConstant('(%s)' % clause) if clause == SQLTrueClause: @@ -849,7 +849,7 @@ class ColumnAS(SQLOp): ''' Just like SQLOp('AS', expr, name) except without the parentheses ''' def __init__(self, expr, name): - if isinstance(name, (str, unicode)): + if isinstance(name, basestring): name = SQLConstant(name) SQLOp.__init__(self, 'AS', expr, name) def __sqlrepr__(self, db): @@ -888,7 +888,7 @@ return "CONCAT(%s)" % ", ".join(values) else: return " || ".join(values) - elif isinstance(s, (str, unicode)): + elif isinstance(s, basestring): s = _quote_percent(sqlrepr(s, db)[1:-1], db) return "'%s%s%s'" % (self.prefix, s, self.postfix) else: Modified: SQLObject/trunk/sqlobject/sresults.py =================================================================== --- SQLObject/trunk/sqlobject/sresults.py 2007-09-19 20:52:35 UTC (rev 2966) +++ SQLObject/trunk/sqlobject/sresults.py 2007-09-20 14:40:33 UTC (rev 2967) @@ -3,8 +3,6 @@ import main import joins -StringType = type('') - class SelectResults(object): IterationClass = dbconnection.Iteration @@ -76,7 +74,7 @@ desc = True else: desc = False - if isinstance(orderBy, (str, unicode)): + if isinstance(orderBy, basestring): if orderBy in self.sourceClass.sqlmeta.columns: val = getattr(self.sourceClass.q, self.sourceClass.sqlmeta.columns[orderBy].name) if desc: @@ -125,7 +123,7 @@ # None doesn't filter anything, it's just a no-op: return self clause = self.clause - if isinstance(clause, (str, unicode)): + if isinstance(clause, basestring): clause = sqlbuilder.SQLConstant('(%s)' % self.clause) return self.newClause(sqlbuilder.AND(clause, filter_clause)) @@ -236,7 +234,7 @@ """ expressions = [] for func_name, attribute in attributes: - if type(attribute) == StringType: + if isinstance(attribute, str): expression = '%s(%s)' % (func_name, attribute) else: expression = getattr(sqlbuilder.func, func_name)(attribute) Modified: SQLObject/trunk/sqlobject/util/csvexport.py =================================================================== --- SQLObject/trunk/sqlobject/util/csvexport.py 2007-09-19 20:52:35 UTC (rev 2966) +++ SQLObject/trunk/sqlobject/util/csvexport.py 2007-09-20 14:40:33 UTC (rev 2967) @@ -153,7 +153,7 @@ close_zip_when_finished = True return_when_finished = False if file: - if isinstance(file, (str, unicode)): + if isinstance(file, basestring): close_when_finished = True file = open(file, 'wb') elif zip: |