def get_tile(filename, coord):
 db = _connect(filename)
 db.text_factory = bytes
 formats = {'png': 'image/png', 'jpg': 'image/jpeg', 'json': 'application/json', None: None}
 format = db.execute("SELECT value FROM metadata WHERE name='format'").fetchone()
 format = ((format and format[0]) or None)
 mime_type = formats[format]
 tile_row = (((2 ** coord.zoom) - 1) - coord.row)
 q = 'SELECT tile_data FROM tiles WHERE zoom_level=? AND tile_column=? AND tile_row=?'
 content = db.execute(q, (coord.zoom, coord.column, tile_row)).fetchone()
 content = ((content and content[0]) or None)
 return (mime_type, content)

def get_tile ( filename , coord ) : db = _connect ( filename ) db . text_factory = bytes formats = { 'png' : 'image/png' , 'jpg' : 'image/jpeg' , 'json' : 'application/json' , None : None } format = db . execute ( "SELECT value FROM metadata WHERE name='format'" ) . fetchone ( ) format = ( ( format and format [ 0 ] ) or None ) mime_type = formats [ format ] tile_row = ( ( ( 2 ** coord . zoom ) - 1 ) - coord . row ) q = 'SELECT tile_data FROM tiles WHERE zoom_level=? AND tile_column=? AND tile_row=?' content = db . execute ( q , ( coord . zoom , coord . column , tile_row ) ) . fetchone ( ) content = ( ( content and content [ 0 ] ) or None ) return ( mime_type , content )
retrieve the mime-type and raw content of a tile by coordinate .