
    +d                     ~    d dl mZ d dlmZ d dlmZ d dlmZ  G d de          Zddddd	d
Z	 G d de          Z
dS )    )from_uri)Node)Catalog)
DataSourcec                   6     e Zd ZdZdZd fd	Zd	dZd Z xZS )
TiledCatalogaG  View Tiled server as a catalog

    See the documentation for setting up such a server at
    https://blueskyproject.io/tiled/

    A tiled server may contain sources of dataframe, array or xarray type.
    This driver exposes the full tree as exposed by the server, but you
    can also specify the sub-path of that tree.
    	tiled_catNc                 t   || _         t          |t                    r@|                    d          r|                    ddd          }n|}t          |d          }n	|}|j        }|| _        |||         }t                                          |d|	                    dd          d         z              dS )	a  

        Parameters
        ----------
        server: str or tiled.client.node.Node
            Location of tiles server. Usually of the form "http[s]://address:port/"
            May include a path. If the protocol is "tiled", we assume HTTP
            connection. Alternatively, can be a Node instance, already connected
            to a server.
        path: str (optional)
            If given, restrict the catalog to this part of the server's catalog
            tree. Equivalent to extending the server URL.
        tiledhttp   daskNztiled::)entriesname)
path
isinstancestr
startswithreplacer   urisuper__init__split)selfserverr   r   client	__class__s        3lib/python3.11/site-packages/intake/source/tiled.pyr   zTiledCatalog.__init__   s     	fc"" 	  )) nnWfa88c6**FFF*C 	"D\Fh39J9J19M.MNNNNN    textc                     |dk    rddl m}  ||          }nt          t                              | j                            |          | j        | j                  S )zSFull text search

        Queries other than full text will be added later
        r!   r   )FullText)r   r   )	tiled.queriesr#   NotImplementedErrorr   	from_dict_entriessearchr   r   )r   querytyper#   qs        r   r(   zTiledCatalog.search2   sh    
 6> 	&......AA%%%%dm&:&:1&=&=48RVR[%\\\r    c                     | j         |         }t          |t                    rt          |          S t	          | j        ||          S )N)r   r   instance)r'   r   r   r   TiledSourcer   )r   itemnodes      r   __getitem__zTiledCatalog.__getitem__?   sF    }T"dD!! 	G%%%48$FFFFr    N)r!   )	__name__
__module____qualname____doc__r   r   r(   r1   __classcell__r   s   @r   r   r      s          DO O O O O O:] ] ] ]G G G G G G Gr    r   ndarrayxarray	dataframe)DaskArrayClientDaskDataArrayClientDaskDatasetClientDaskVariableClientDaskDataFrameClientc                   D     e Zd ZdZdZd
 fd	Zd Zd Zd Z fd	Z	 xZ
S )r.   zA source on a Tiled server

    The container type of this source is determined at runtime.
    The attribute ``.instance`` gives access to the underlying Tiled
    API, but most users will only call ``.to_dask()``.
    r    Nc                 d   |(t          |d          |                                         }|| _        t          |j                  }|r|                    |           t                                          |           || _        t          t          | j                  j                 | _        dS )aq  

        Parameters
        ----------
        uri: str (optional)
            Location of the server. If ``instance`` is given, this is
            only used for the repr
        pathL str (optional)
            Path of the data source within the server tree. If ``instance``
            is given, this is only used for the repr
        instance: tiled.client.node.None (optional)
            The tiled object pointing to the data source; normally created
            by a ``TiledCatalog``
        metadata: dict
            Extra metadata for this source; metadata will also be provided
            by the server.
        Nr   )metadata)r   readr-   dictrD   updater   r   r   typesr*   r3   	container)r   r   r   r-   rD   mdr   s         r   r   zTiledSource.__init__Z   s    $  	:V,,T27799H (#$$ 	 IIh"%%%	tDM22;<r    c                 8   |                                  }t          |dd           pt          |dd           }t          |dd           p|j        j        }t	          |t          | j                                        j        d|j                  || j	                  S )Ndtypedtypesnpartitionsshape)rL   rO   rN   rD   )
to_daskgetattrdatarN   rF   r-   	structuremacrorO   rD   )r   xdtpartss       r   discoverzTiledSource.discoverv   s    LLNNQ&&D'!Xt*D*D=$//E163E"GDM,C,C,E,E,KWVWV]$^$^lq  }A  }J  K  K  K  	Kr    c                 4    | j                                         S r2   )r-   rE   r   s    r   rP   zTiledSource.to_dask|   s    }!!###r    c                 X    | j                                                                         S r2   )r-   rE   computerZ   s    r   rE   zTiledSource.read   s"    }!!##++---r    c                     t                                                      }t          |d                                                   d         }|d                             d           |S )Nsourcesr   argsr-   )r   _yamllistvaluespop)r   yvr   s      r   r`   zTiledSource._yaml   sQ    GGMMOO9$$&&''*	&	j!!!r    )rB   rB   NN)r3   r4   r5   r6   r   r   rX   rP   rE   r`   r7   r8   s   @r   r.   r.   P   s          D= = = = = =8K K K$ $ $. . .        r    r.   N)tiled.clientr   tiled.client.noder   intake.catalogr   intake.sourcer   r   rH   r.    r    r   <module>rk      s    ! ! ! ! ! ! " " " " " " " " " " " " $ $ $ $ $ $<G <G <G <G <G7 <G <G <G@ !#!"&	 	7 7 7 7 7* 7 7 7 7 7r    