
    +d                     |    d dl Z d dlZd dlmZ d dlmZ d dlmZmZ ddl	m
Z
mZ ddlmZ  G d	 d
e          Zd ZdS )    N)urljoin)__version__)
DataSourceSchema   )pack_kwargsunpack_kwargs   )
serializerc                   @     e Zd ZdZeZd fd	Zd Zd Zd Z	d Z
 xZS )	RemoteSourcez9Base class for all DataSources living on an Intake serverNc                     t          t          |                               |            || _        || _        || _        || _        d| _        |pi | _        | 	                                 dS )a  

        Parameters
        ----------
        url: str
            Address of the server
        headers: dict
            HTTP headers to sue in calls
        name: str
            handle to reference this data
        parameters: dict
            To pass to the server when it instantiates the data source
        metadata: dict
            Additional info
        kwargs: ignored
        N)
superr   __init__urlname
parametersheaders
_source_idmetadata_get_source_id)selfr   r   r   r   r   kwargs	__class__s          5lib/python3.11/site-packages/intake/container/base.pyr   zRemoteSource.__init__   si    " 	lD!!**4000	$ B    c           	      \   | j         t          d| j        | j                  }t	          j        t          | j        d          fdt          j	        |fi t          i| j        }|                                 t          j        |j        fi t          }|                     |           d S d S )Nopen)actionr   r   	v1/sourcedata)r   dictr   r   requestspostr   r   msgpackpackbr   r   raise_for_statusunpackbcontentr	   _parse_open_response)r   payloadreqresponses       r   r   zRemoteSource._get_source_id2   s    ? 	0&tyT_UUUG-+ > >{{W]SZEjEj^iEjEj{nrnz{{C  """s{DDmDDH%%h/////	0 	0r   c                 R   |d         }t          |t                    rd |d         D             }|| _        t          |d         pd          | _        |d         | _        |d         | _        t          d | j        | j        | j        | j                  | _        |d         | _	        d S )	Ndtypec                 ,    g | ]}t          |          S  )tuple).0xs     r   
<listcomp>z5RemoteSource._parse_open_response.<locals>.<listcomp>>   s    ???588???r   shaper1   npartitionsr   )	datashaper/   r6   r7   r   	source_id)

isinstancelistr/   r2   r6   r7   r   r   _schemar   )r   r-   dtype_descrs      r   r*   z!RemoteSource._parse_open_response:   s    w'k4(( 	@??Xg->???K 
8G,233
#M2 ,DJdj^b^ny}  zG  H  H  H";/r   c                     t           NNotImplementedError)r   is     r   _get_partitionzRemoteSource._get_partitionF       !!r   c                     t           r?   r@   )r   s    r   to_daskzRemoteSource.to_daskI   rD   r   r?   )__name__
__module____qualname____doc__r   versionr   r   r*   rC   rF   __classcell__)r   s   @r   r   r      s        CCG     40 0 0
0 
0 
0" " "" " " " " " "r   r   c           	         t          t          j                                                  }t          t          j                                                  }t          d|||          }|||d<   	 t          j        t          | d          fdt          j
        |fi t          i|}|j        dk    rt          d          t          j        |j        fi t           }	|	d	         }
|	d
         }t          j        |         }t          j        |
         }|                    |                    |	d                   |          }|||                                 S S # ||                                 w w xY w)a  Serializable function for fetching a data source partition

    Parameters
    ----------
    url: str
        Server address
    headers: dict
        HTTP header parameters
    source_id: str
        ID of the source in the server's cache (unique per user)
    container: str
        Type of data, like "dataframe" one of ``intake.container.container_map``
    partition: serializable
        Part of data to fetch, e.g., an integer for a dataframe.
    read)r   r9   accepted_formatsaccepted_compressionN	partitionr    r!      zError reading dataformatcompression)r;   r   format_registrykeyscompression_registryr"   r#   r$   r   r%   r&   r   status_code	Exceptionr(   r)   r	   decode
decompressclose)r   r   r9   	containerrQ   rO   rP   r+   respmsgrS   rT   
compressorencoderchunks                  r   get_partitionrc   M   s|     J6;;==>>
 ? D D F FGG&IHX  pD  E  E  EG )(}WS+66nnW]7=b=bVa=b=bnfmnns" 	20111odl<<m<<X-(4[A
,V4z44S[AA9MM 	JJLLLL	4 	JJLLLL	s   2CE E4)r%   r#   requests.compatr   intaker   intake.source.baser   r   compatr   r	    r   r   rc   r1   r   r   <module>ri      s      # # # # # #       1 1 1 1 1 1 1 1 / / / / / / / /      7" 7" 7" 7" 7": 7" 7" 7"t% % % % %r   