Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
# must be above Unicode, because Polygon is Unicode's subclass
elif issubclass(cls, Polygon):
return PGGeometry("POLYGON", dimension=cls.Attributes.dim)
# must be above Unicode, because MultiPoint is Unicode's subclass
elif issubclass(cls, MultiPoint):
return PGGeometry("MULTIPOINT", dimension=cls.Attributes.dim)
# must be above Unicode, because MultiLine is Unicode's subclass
elif issubclass(cls, MultiLine):
return PGGeometry("MULTILINESTRING", dimension=cls.Attributes.dim)
# must be above Unicode, because MultiPolygon is Unicode's subclass
elif issubclass(cls, MultiPolygon):
return PGGeometry("MULTIPOLYGON", dimension=cls.Attributes.dim)
# must be above Unicode, because String is Unicode's subclass
elif issubclass(cls, String):
if cls.Attributes.max_len == String.Attributes.max_len: # Default is arbitrary-length
return sqlalchemy.Text
else:
return sqlalchemy.String(cls.Attributes.max_len)
elif issubclass(cls, Unicode):
if cls.Attributes.max_len == Unicode.Attributes.max_len: # Default is arbitrary-length
return sqlalchemy.UnicodeText
else:
return sqlalchemy.Unicode(cls.Attributes.max_len)
elif issubclass(cls, EnumBase):
return sqlalchemy.Enum(*cls.__values__, name=cls.__type_name__)
def get_sqlalchemy_type(cls):
db_type = cls.Attributes.db_type
if db_type is not None:
return db_type
# must be above Unicode, because Uuid is Unicode's subclass
if issubclass(cls, Uuid):
return PGUuid(as_uuid=True)
# must be above Unicode, because Point is Unicode's subclass
elif issubclass(cls, Point):
return PGGeometry("POINT", dimension=cls.Attributes.dim)
# must be above Unicode, because Line is Unicode's subclass
elif issubclass(cls, Line):
return PGGeometry("LINESTRING", dimension=cls.Attributes.dim)
# must be above Unicode, because Polygon is Unicode's subclass
elif issubclass(cls, Polygon):
return PGGeometry("POLYGON", dimension=cls.Attributes.dim)
# must be above Unicode, because MultiPoint is Unicode's subclass
elif issubclass(cls, MultiPoint):
return PGGeometry("MULTIPOINT", dimension=cls.Attributes.dim)
# must be above Unicode, because MultiLine is Unicode's subclass
elif issubclass(cls, MultiLine):
return PGGeometry("MULTILINESTRING", dimension=cls.Attributes.dim)
# must be above Unicode, because MultiPolygon is Unicode's subclass
elif issubclass(cls, MultiPolygon):
return PGGeometry("MULTIPOLYGON", dimension=cls.Attributes.dim)
if value is not None:
return value
if self.format is PGGeometry.PlainWkb:
def process(value):
if value is not None:
return sql.func.ST_AsBinary(value, self.srid)
return process
def bind_expression(self, bindvalue):
if self.format is PGGeometry.PlainWkt:
return sql.func.ST_GeomFromText(bindvalue, self.srid)
Geometry = PGGeometry
@compiles(PGGeometry)
def compile_geometry(type_, compiler, **kw):
return '%s(%s,%d)' % (type_.name, type_.geometry_type, type_.srid)
@compiles(PGGeometry, "sqlite")
def compile_geometry_sqlite(type_, compiler, **kw):
return "BLOB"
class PGXml(UserDefinedType):
def __init__(self, pretty_print=False, xml_declaration=False,
encoding='UTF-8'):
super(PGXml, self).__init__()
self.xml_declaration = xml_declaration
def result_processor(self, dialect, coltype):
if self.format is PGGeometry.PlainWkt:
def process(value):
if value is not None:
return value
if self.format is PGGeometry.PlainWkb:
def process(value):
if value is not None:
return sql.func.ST_AsBinary(value, self.srid)
return process
# must be above Unicode, because Uuid is Unicode's subclass
if issubclass(cls, Uuid):
return PGUuid(as_uuid=True)
# must be above Unicode, because Point is Unicode's subclass
elif issubclass(cls, Point):
return PGGeometry("POINT", dimension=cls.Attributes.dim)
# must be above Unicode, because Line is Unicode's subclass
elif issubclass(cls, Line):
return PGGeometry("LINESTRING", dimension=cls.Attributes.dim)
# must be above Unicode, because Polygon is Unicode's subclass
elif issubclass(cls, Polygon):
return PGGeometry("POLYGON", dimension=cls.Attributes.dim)
# must be above Unicode, because MultiPoint is Unicode's subclass
elif issubclass(cls, MultiPoint):
return PGGeometry("MULTIPOINT", dimension=cls.Attributes.dim)
# must be above Unicode, because MultiLine is Unicode's subclass
elif issubclass(cls, MultiLine):
return PGGeometry("MULTILINESTRING", dimension=cls.Attributes.dim)
# must be above Unicode, because MultiPolygon is Unicode's subclass
elif issubclass(cls, MultiPolygon):
return PGGeometry("MULTIPOLYGON", dimension=cls.Attributes.dim)
# must be above Unicode, because String is Unicode's subclass
elif issubclass(cls, String):
if cls.Attributes.max_len == String.Attributes.max_len: # Default is arbitrary-length
# must be above Unicode, because Line is Unicode's subclass
elif issubclass(cls, Line):
return PGGeometry("LINESTRING", dimension=cls.Attributes.dim)
# must be above Unicode, because Polygon is Unicode's subclass
elif issubclass(cls, Polygon):
return PGGeometry("POLYGON", dimension=cls.Attributes.dim)
# must be above Unicode, because MultiPoint is Unicode's subclass
elif issubclass(cls, MultiPoint):
return PGGeometry("MULTIPOINT", dimension=cls.Attributes.dim)
# must be above Unicode, because MultiLine is Unicode's subclass
elif issubclass(cls, MultiLine):
return PGGeometry("MULTILINESTRING", dimension=cls.Attributes.dim)
# must be above Unicode, because MultiPolygon is Unicode's subclass
elif issubclass(cls, MultiPolygon):
return PGGeometry("MULTIPOLYGON", dimension=cls.Attributes.dim)
# must be above Unicode, because String is Unicode's subclass
elif issubclass(cls, String):
if cls.Attributes.max_len == String.Attributes.max_len: # Default is arbitrary-length
return sqlalchemy.Text
else:
return sqlalchemy.String(cls.Attributes.max_len)
elif issubclass(cls, Unicode):
if cls.Attributes.max_len == Unicode.Attributes.max_len: # Default is arbitrary-length
return sqlalchemy.UnicodeText
else:
def get_sqlalchemy_type(cls):
db_type = cls.Attributes.db_type
if db_type is not None:
return db_type
# must be above Unicode, because Uuid is Unicode's subclass
if issubclass(cls, Uuid):
return PGUuid(as_uuid=True)
# must be above Unicode, because Point is Unicode's subclass
elif issubclass(cls, Point):
return PGGeometry("POINT", dimension=cls.Attributes.dim)
# must be above Unicode, because Line is Unicode's subclass
elif issubclass(cls, Line):
return PGGeometry("LINESTRING", dimension=cls.Attributes.dim)
# must be above Unicode, because Polygon is Unicode's subclass
elif issubclass(cls, Polygon):
return PGGeometry("POLYGON", dimension=cls.Attributes.dim)
# must be above Unicode, because MultiPoint is Unicode's subclass
elif issubclass(cls, MultiPoint):
return PGGeometry("MULTIPOINT", dimension=cls.Attributes.dim)
# must be above Unicode, because MultiLine is Unicode's subclass
elif issubclass(cls, MultiLine):
return PGGeometry("MULTILINESTRING", dimension=cls.Attributes.dim)