
    tf                     (    d dl Z d dlZd dlZd Zd Zy)    Nc                 D   t         j                  j                  |       sddiS t        j                  |       }|j                  d      j                         }|d   |d   |d   d}	 |d   |d	<   |d
   |d<   	 |d   |d<   |S # t        $ r Y w xY w# t        $ r Y |S w xY w)NerrorzTileset info is not available!zSELECT * FROM tileset_info         )	tile_sizemax_zoommax_size   width	   height
   dtype)ospathisfilesqlite3connectexecutefetchone
IndexError)tilesetdbresos       _/var/www/html/software/conda/envs/higlass/lib/python3.12/site-packages/clodius/tiles/imtiles.pyget_tileset_infor      s    77>>'"9::		!B
**1
2
;
;
=C!f#a&c!fEAV'
!f(W'
 H  
  Hs$   (B 9B 	BB	BBc                    t        j                  |       }g }|xr t        |      }|D ]  }||j                  d      dz   d j	                  d      }d}t        |d         t        |d         t        |d         d}	|j                  ||	      j                         }
|
sx|
d   }|rd|i}n&d	t        j                  |      j                  d
      i}|j                  ||f        |S )a  
    Generate tiles from a imtiles file.
    Parameters
    ----------
    tileset: tilesets.models.Tileset object
        The tileset that the tile ids should be retrieved from
    tile_ids: [str,...]
        A list of tile_ids (e.g. xyx.0.0.1) identifying the tiles
        to be retrieved
    Returns
    -------
    generated_tiles: [(tile_id, tile_data),...]
        A list of tile_id, tile_data tuples
    .   Nz:SELECT image FROM tiles WHERE z = :z AND y = :y AND x = :xr      )zyximagedensezlatin-1)r   r   lenfindsplitintr   r   base64	b64encodedecodeappend)filenametile_idsrawr   generate_tilesgenerate_imagetile_ididsqlparamr   
image_blob	tile_datas                r   	get_tilesr;      s      
	"BN*S]N 8W\\#&*,-33C8J"Q%js2a5zBqE
Cjje$--/QJ$j1	$f&6&6z&B&I&I)&TU	!!7I"678"     )r,   r   r   r   r;    r<   r   <module>r>      s     	 0'r<   