<s> from ctypes import c_void_p <EOL> from django . contrib . gis . gdal . base import GDALBase <EOL> from django . contrib . gis . gdal . error import GDALException <EOL> from django . contrib . gis . gdal . prototypes import ds as vcapi , raster as rcapi <EOL> from django . utils import six <EOL> from django . utils . encoding import force_bytes , force_text <EOL> class Driver ( GDALBase ) : <EOL> """<STR_LIT>""" <EOL> _alias = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } <EOL> def __init__ ( self , dr_input ) : <EOL> """<STR_LIT>""" <EOL> if isinstance ( dr_input , six . string_types ) : <EOL> self . ensure_registered ( ) <EOL> if dr_input . lower ( ) in self . _alias : <EOL> name = self . _alias [ dr_input . lower ( ) ] <EOL> else : <EOL> name = dr_input <EOL> for iface in ( vcapi , rcapi ) : <EOL> driver = iface . get_driver_by_name ( force_bytes ( name ) ) <EOL> if driver : <EOL> break <EOL> elif isinstance ( dr_input , int ) : <EOL> self . ensure_registered ( ) <EOL> for iface in ( vcapi , rcapi ) : <EOL> driver = iface . get_driver ( dr_input ) <EOL> if driver : <EOL> break <EOL> elif isinstance ( dr_input , c_void_p ) : <EOL> driver = dr_input <EOL> else : <EOL> raise GDALException ( '<STR_LIT>' % str ( type ( dr_input ) ) ) <EOL> if not driver : <EOL> raise GDALException ( '<STR_LIT>' % str ( dr_input ) ) <EOL> self . ptr = driver <EOL> def __str__ ( self ) : <EOL> return self . name <EOL> @ classmethod <EOL> def ensure_registered ( cls ) : <EOL> """<STR_LIT>""" <EOL> if not cls . driver_count ( ) : <EOL> vcapi . register_all ( ) <EOL> rcapi . register_all ( ) <EOL> @ classmethod <EOL> def driver_count ( cls ) : <EOL> """<STR_LIT>""" <EOL> return vcapi . get_driver_count ( ) + rcapi . get_driver_count ( ) <EOL> @ property <EOL> def name ( self ) : <EOL> """<STR_LIT>""" <EOL> return force_text ( rcapi . get_driver_description ( self . ptr ) ) </s>
