<s> """<STR_LIT>""" <EOL> from ctypes import c_void_p , string_at <EOL> from django . contrib . gis . gdal . error import ( <EOL> GDALException , SRSException , check_err , <EOL> ) <EOL> from django . contrib . gis . gdal . libgdal import lgdal <EOL> from django . utils import six <EOL> def arg_byref ( args , offset = - <NUM_LIT:1> ) : <EOL> "<STR_LIT>" <EOL> return args [ offset ] . _obj . value <EOL> def ptr_byref ( args , offset = - <NUM_LIT:1> ) : <EOL> "<STR_LIT>" <EOL> return args [ offset ] . _obj <EOL> def check_const_string ( result , func , cargs , offset = None , cpl = False ) : <EOL> """<STR_LIT>""" <EOL> if offset : <EOL> check_err ( result , cpl = cpl ) <EOL> ptr = ptr_byref ( cargs , offset ) <EOL> return ptr . value <EOL> else : <EOL> return result <EOL> def check_string ( result , func , cargs , offset = - <NUM_LIT:1> , str_result = False ) : <EOL> """<STR_LIT>""" <EOL> if str_result : <EOL> ptr = result <EOL> if not ptr : <EOL> s = None <EOL> else : <EOL> s = string_at ( result ) <EOL> else : <EOL> check_err ( result ) <EOL> ptr = ptr_byref ( cargs , offset ) <EOL> s = ptr . value <EOL> if ptr : <EOL> lgdal . VSIFree ( ptr ) <EOL> return s <EOL> def check_envelope ( result , func , cargs , offset = - <NUM_LIT:1> ) : <EOL> "<STR_LIT>" <EOL> env = ptr_byref ( cargs , offset ) <EOL> return env <EOL> def check_geom ( result , func , cargs ) : <EOL> "<STR_LIT>" <EOL> if isinstance ( result , six . integer_types ) : <EOL> result = c_void_p ( result ) <EOL> if not result : <EOL> raise GDALException ( '<STR_LIT>' % func . __name__ ) <EOL> return result <EOL> def check_geom_offset ( result , func , cargs , offset = - <NUM_LIT:1> ) : <EOL> "<STR_LIT>" <EOL> check_err ( result ) <EOL> geom = ptr_byref ( cargs , offset = offset ) <EOL> return check_geom ( geom , func , cargs ) <EOL> def check_srs ( result , func , cargs ) : <EOL> if isinstance ( result , six . integer_types ) : <EOL> result = c_void_p ( result ) <EOL> if not result : <EOL> raise SRSException ( '<STR_LIT>' % func . __name__ ) <EOL> return result <EOL> def check_arg_errcode ( result , func , cargs , cpl = False ) : <EOL> """<STR_LIT>""" <EOL> check_err ( arg_byref ( cargs ) , cpl = cpl ) <EOL> return result <EOL> def check_errcode ( result , func , cargs , cpl = False ) : <EOL> """<STR_LIT>""" <EOL> check_err ( result , cpl = cpl ) <EOL> def check_pointer ( result , func , cargs ) : <EOL> "<STR_LIT>" <EOL> if isinstance ( result , six . integer_types ) : <EOL> result = c_void_p ( result ) <EOL> if result : <EOL> return result <EOL> else : <EOL> raise GDALException ( '<STR_LIT>' % func . __name__ ) <EOL> def check_str_arg ( result , func , cargs ) : <EOL> """<STR_LIT>""" <EOL> dbl = result <EOL> ptr = cargs [ - <NUM_LIT:1> ] . _obj <EOL> return dbl , ptr . value . decode ( ) </s>
