Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
elif t.count('float') or t.count('real') or t.count('double'):
return col.FloatCol, {}
elif t == 'text':
return col.StringCol, {}
elif t.startswith('timestamp'):
return col.DateTimeCol, {}
elif t.startswith('datetime'):
return col.DateTimeCol, {}
elif t.startswith('date'):
return col.DateCol, {}
elif t.startswith('bool'):
return col.BoolCol, {}
elif t.startswith('bytea'):
return col.BLOBCol, {}
else:
return col.Col, {}
else:
return col.StringCol, {'length': flength, 'varchar': False}
elif t == 'varchar': # 32767 bytes
if fCharset and (fCharset != "NONE"):
return col.UnicodeCol, {'length': flength, 'varchar': True,
'dbEncoding': fCharset}
elif self.dbEncoding:
return col.UnicodeCol, {'length': flength, 'varchar': True,
'dbEncoding': self.dbEncoding}
else:
return col.StringCol, {'length': flength, 'varchar': True}
elif t == 'blob': # 32GB
return col.BLOBCol, {}
else:
return col.Col, {}
return [JSONValidator(name=self.name)] + \
super(SOJSONCol, self).createValidators()
class JSONCol(StringCol):
baseClass = SOJSONCol
def pushKey(kw, name, value):
if name not in kw:
kw[name] = value
all = []
# Use copy() to avoid 'dictionary changed' issues on python 3
for key, value in globals().copy().items():
if isinstance(value, type) and (issubclass(value, (Col, SOCol))):
all.append(key)
__all__.extend(all)
del all
elif t.count('float') or t.count('real') or t.count('double'):
return col.FloatCol, {}
elif t == 'text':
return col.StringCol, {}
elif t.startswith('timestamp'):
return col.DateTimeCol, {}
elif t.startswith('datetime'):
return col.DateTimeCol, {}
elif t.startswith('date'):
return col.DateCol, {}
elif t.startswith('bool'):
return col.BoolCol, {}
elif t.startswith('bytea'):
return col.BLOBCol, {}
else:
return col.Col, {}
return self.key_type[self._idType()]
def _sybaseType(self):
key_type = {int: "NUMERIC(18,0)", str: "TEXT"}
return key_type[self._idType()]
def _mssqlType(self):
key_type = {int: "INT", str: "TEXT"}
return key_type[self._idType()]
def _firebirdType(self):
key_type = {int: "INT", str: "VARCHAR(255)"}
return key_type[self._idType()]
class KeyCol(Col):
baseClass = SOKeyCol
class ForeignKeyValidator(SOValidator):
def __init__(self, *args, **kw):
super(ForeignKeyValidator, self).__init__(*args, **kw)
self.fkIDType = None
def from_python(self, value, state):
if value is None:
return None
# Avoid importing the main module
# to get the SQLObject class for isinstance
if hasattr(value, 'sqlmeta'):
return col.UnicodeCol, {'length': size}
return col.StringCol, {'length': size}
elif t.startswith('char'):
if self.usingUnicodeStrings:
return col.UnicodeCol, {'length': size,
'varchar': False}
return col.StringCol, {'length': size,
'varchar': False}
elif t.startswith('datetime'):
return col.DateTimeCol, {}
elif t.startswith('decimal'):
# be careful for awkward naming
return col.DecimalCol, {'size': precision,
'precision': scale}
else:
return col.Col, {}
if self.connection and self.connection.can_use_microseconds():
return 'TIME(6)'
else:
return 'TIME'
def _sqliteType(self):
return 'TIME'
def _firebirdType(self):
return 'TIME'
def _maxdbType(self):
return 'TIME'
class TimeCol(Col):
baseClass = SOTimeCol
class SOTimestampCol(SODateTimeCol):
"""
Necessary to support MySQL's use of TIMESTAMP versus DATETIME types
"""
def __init__(self, **kw):
if 'default' not in kw:
kw['default'] = None
SOCol.__init__(self, **kw)
def _mysqlType(self):
if self.connection and self.connection.can_use_microseconds():
return 'TIMESTAMP(6)'
def __classinit__(cls, new_attrs):
# This is true if we're initializing the SQLObject class,
# instead of a subclass:
is_base = cls.__bases__ == (object,)
cls._SO_setupSqlmeta(new_attrs, is_base)
implicitColumns = _collectAttributes(cls, new_attrs, col.Col)
implicitJoins = _collectAttributes(cls, new_attrs, joins.Join)
implicitIndexes = _collectAttributes(cls, new_attrs,
index.DatabaseIndex)
if not is_base:
cls._SO_cleanDeprecatedAttrs(new_attrs)
if '_connection' in new_attrs:
connection = new_attrs['_connection']
del cls._connection
assert 'connection' not in new_attrs
elif 'connection' in new_attrs:
connection = new_attrs['connection']
del cls.connection
else:
connection = None
class SOSmallIntCol(SOIntCol):
def _sqlType(self):
return self.addSQLAttrs("SMALLINT")
class SmallIntCol(Col):
baseClass = SOSmallIntCol
class SOMediumIntCol(SOIntCol):
def _sqlType(self):
return self.addSQLAttrs("MEDIUMINT")
class MediumIntCol(Col):
baseClass = SOMediumIntCol
class SOBigIntCol(SOIntCol):
def _sqlType(self):
return self.addSQLAttrs("BIGINT")
class BigIntCol(Col):
baseClass = SOBigIntCol
class BoolValidator(SOValidator):
def to_python(self, value, state):
if value is None: