Skip to content

Commit 65e8105

Browse files
committed
Use isinstance(..., basestring) instead of isinstance(..., (str, unicode));
stop emulating basestring, stop using types.StringTypes and type(""). git-svn-id: http://svn.colorstudy.com/SQLObject/trunk@2967 95a46c32-92d2-0310-94a5-8d71aeb3d4b3
1 parent b044b74 commit 65e8105

10 files changed

Lines changed: 19 additions & 28 deletions

File tree

sqlobject/col.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1297,7 +1297,7 @@ def from_python(self, value, state):
12971297
return None
12981298
if isinstance(value, float):
12991299
value = str(value)
1300-
if isinstance(value, (str, unicode)):
1300+
if isinstance(value, basestring):
13011301
connection = state.soObject._connection
13021302
if hasattr(connection, "decimalSeparator"):
13031303
value = value.replace(connection.decimalSeparator, ".")

sqlobject/constraints.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def __init__(self, desc, obj, col, value, *args):
1919
ValueError.__init__(self, fullDesc, *args)
2020

2121
def isString(obj, col, value):
22-
if type(value) is not type(""):
22+
if not isinstance(value, str):
2323
raise BadValue("only allows strings", obj, col, value)
2424

2525
def notNull(obj, col, value):

sqlobject/converters.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,8 @@ def StringLikeConverter(value, db):
115115
assert 0, "Database %s unknown" % db
116116
return "'%s'" % value
117117

118-
registerConverter(type(""), StringLikeConverter)
119-
registerConverter(type(u""), StringLikeConverter)
118+
registerConverter(str, StringLikeConverter)
119+
registerConverter(unicode, StringLikeConverter)
120120
registerConverter(array_type, StringLikeConverter)
121121
registerConverter(buffer_type, StringLikeConverter)
122122

sqlobject/dbconnection.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -521,7 +521,7 @@ def _SO_selectOne(self, so, columnNames):
521521

522522
def _SO_selectOneAlt(self, so, columnNames, condition):
523523
if columnNames:
524-
columns = [isinstance(x, (str, unicode)) and sqlbuilder.SQLConstant(x) or x for x in columnNames]
524+
columns = [isinstance(x, basestring) and sqlbuilder.SQLConstant(x) or x for x in columnNames]
525525
else:
526526
columns = None
527527
return self.queryOne(self.sqlrepr(sqlbuilder.Select(columns,

sqlobject/inheritance/__init__.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,6 @@
66
import iteration
77

88

9-
try:
10-
basestring
11-
except NameError: # Python 2.2
12-
import types
13-
basestring = (types.StringType, types.UnicodeType)
14-
15-
169
def tablesUsedDict(obj, db):
1710
if hasattr(obj, "tablesUsedDict"):
1811
return obj.tablesUsedDict(db)
@@ -49,7 +42,7 @@ def __init__(self, sourceClass, clause, clauseTables=None,
4942
#DSM: because if the user uses clauseTables
5043
#DSM: (and normal string SELECT), he must know what he wants
5144
#DSM: and will do himself the relationship between classes.
52-
if type(clause) is not str:
45+
if not isinstance(clause, str):
5346
tableRegistry = {}
5447
allClasses = classregistry.registry(
5548
sourceClass.sqlmeta.registry).allClasses()
@@ -222,7 +215,7 @@ def __classinit__(cls, new_attrs):
222215
for column in currentClass.sqlmeta.columnDefinitions.values():
223216
if column.name == 'childName':
224217
continue
225-
if type(column) == ForeignKey:
218+
if isinstance(column, ForeignKey):
226219
continue
227220
setattr(cls.q, column.name,
228221
getattr(currentClass.q, column.name))

sqlobject/main.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1618,7 +1618,7 @@ def _reprItems(self):
16181618
return items
16191619

16201620
def setConnection(cls, value):
1621-
if isinstance(value, (str, unicode)):
1621+
if isinstance(value, basestring):
16221622
value = dbconnection.connectionForURI(value)
16231623
cls._connection = value
16241624
setConnection = classmethod(setConnection)
@@ -1663,7 +1663,7 @@ def getID(obj):
16631663
return obj
16641664
elif type(obj) is type(1L):
16651665
return int(obj)
1666-
elif type(obj) is type(""):
1666+
elif isinstance(obj, str):
16671667
try:
16681668
return int(obj)
16691669
except ValueError:
@@ -1676,7 +1676,7 @@ def getObject(obj, klass):
16761676
return klass(obj)
16771677
elif type(obj) is type(1L):
16781678
return klass(int(obj))
1679-
elif type(obj) is type(""):
1679+
elif isinstance(obj, str):
16801680
return klass(int(obj))
16811681
elif obj is None:
16821682
return None

sqlobject/manager/command.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1256,7 +1256,7 @@ def best_upgrade(self, current, dest, target_dbname):
12561256
return upgraders[-1]
12571257

12581258
def update_sys_path(paths, verbose):
1259-
if isinstance(paths, (str, unicode)):
1259+
if isinstance(paths, basestring):
12601260
paths = [paths]
12611261
for path in paths:
12621262
path = os.path.abspath(path)

sqlobject/sqlbuilder.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ class NoDefault:
8080
safeSQLRE = re.compile(r'^[a-zA-Z_][a-zA-Z0-9_\.]*$')
8181
def sqlIdentifier(obj):
8282
# some db drivers return unicode column names
83-
return isinstance(obj, types.StringTypes) and bool(safeSQLRE.search(obj.strip()))
83+
return isinstance(obj, basestring) and bool(safeSQLRE.search(obj.strip()))
8484

8585

8686
def execute(expr, executor):
@@ -584,7 +584,7 @@ def filter(self, filter_clause):
584584
# None doesn't filter anything, it's just a no-op:
585585
return self
586586
clause = self.ops['clause']
587-
if isinstance(clause, (str, unicode)):
587+
if isinstance(clause, basestring):
588588
clause = SQLConstant('(%s)' % clause)
589589

590590
if clause == SQLTrueClause:
@@ -849,7 +849,7 @@ def ISNOTNULL(expr):
849849
class ColumnAS(SQLOp):
850850
''' Just like SQLOp('AS', expr, name) except without the parentheses '''
851851
def __init__(self, expr, name):
852-
if isinstance(name, (str, unicode)):
852+
if isinstance(name, basestring):
853853
name = SQLConstant(name)
854854
SQLOp.__init__(self, 'AS', expr, name)
855855
def __sqlrepr__(self, db):
@@ -888,7 +888,7 @@ def __sqlrepr__(self, db):
888888
return "CONCAT(%s)" % ", ".join(values)
889889
else:
890890
return " || ".join(values)
891-
elif isinstance(s, (str, unicode)):
891+
elif isinstance(s, basestring):
892892
s = _quote_percent(sqlrepr(s, db)[1:-1], db)
893893
return "'%s%s%s'" % (self.prefix, s, self.postfix)
894894
else:

sqlobject/sresults.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
import main
44
import joins
55

6-
StringType = type('')
7-
86
class SelectResults(object):
97
IterationClass = dbconnection.Iteration
108

@@ -76,7 +74,7 @@ def _mungeOrderBy(self, orderBy):
7674
desc = True
7775
else:
7876
desc = False
79-
if isinstance(orderBy, (str, unicode)):
77+
if isinstance(orderBy, basestring):
8078
if orderBy in self.sourceClass.sqlmeta.columns:
8179
val = getattr(self.sourceClass.q, self.sourceClass.sqlmeta.columns[orderBy].name)
8280
if desc:
@@ -125,7 +123,7 @@ def filter(self, filter_clause):
125123
# None doesn't filter anything, it's just a no-op:
126124
return self
127125
clause = self.clause
128-
if isinstance(clause, (str, unicode)):
126+
if isinstance(clause, basestring):
129127
clause = sqlbuilder.SQLConstant('(%s)' % self.clause)
130128
return self.newClause(sqlbuilder.AND(clause, filter_clause))
131129

@@ -236,7 +234,7 @@ def accumulateMany(self, *attributes):
236234
"""
237235
expressions = []
238236
for func_name, attribute in attributes:
239-
if type(attribute) == StringType:
237+
if isinstance(attribute, str):
240238
expression = '%s(%s)' % (func_name, attribute)
241239
else:
242240
expression = getattr(sqlbuilder.func, func_name)(attribute)

sqlobject/util/csvexport.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ def export_csv_zip(soClasses, file=None, zip=None, filename_prefix='',
153153
close_zip_when_finished = True
154154
return_when_finished = False
155155
if file:
156-
if isinstance(file, (str, unicode)):
156+
if isinstance(file, basestring):
157157
close_when_finished = True
158158
file = open(file, 'wb')
159159
elif zip:

0 commit comments

Comments
 (0)