<s> """<STR_LIT>""" <EOL> from django . contrib . gis import memoryview <EOL> from django . utils import six <EOL> class GeometryProxy ( object ) : <EOL> def __init__ ( self , klass , field ) : <EOL> """<STR_LIT>""" <EOL> self . _field = field <EOL> self . _klass = klass <EOL> def __get__ ( self , obj , type = None ) : <EOL> """<STR_LIT>""" <EOL> if obj is None : <EOL> return self <EOL> geom_value = obj . __dict__ [ self . _field . attname ] <EOL> if isinstance ( geom_value , self . _klass ) : <EOL> geom = geom_value <EOL> elif ( geom_value is None ) or ( geom_value == '<STR_LIT>' ) : <EOL> geom = None <EOL> else : <EOL> geom = self . _klass ( geom_value ) <EOL> setattr ( obj , self . _field . attname , geom ) <EOL> return geom <EOL> def __set__ ( self , obj , value ) : <EOL> """<STR_LIT>""" <EOL> gtype = self . _field . geom_type <EOL> if isinstance ( value , self . _klass ) and ( str ( value . geom_type ) . upper ( ) == gtype or gtype == '<STR_LIT>' ) : <EOL> if value . srid is None : value . srid = self . _field . srid <EOL> elif value is None or isinstance ( value , six . string_types + ( memoryview , ) ) : <EOL> pass <EOL> else : <EOL> raise TypeError ( '<STR_LIT>' % ( obj . __class__ . __name__ , type ( value ) ) ) <EOL> obj . __dict__ [ self . _field . attname ] = value <EOL> return value </s>
