U
    DAf7                     @   s   d dl mZ d dlmZmZmZmZmZ d dlm	Z	 ee
ee	f e	dddZeeee
ef eee
ef  f  eeee
ef  ddd	Zd
S )    )Path)AnyDictListOptionalUnion)
ByteStream)sourcereturnc                 C   sR   t | tr| S t | ttfr<tt| }t| |jd< |S tdt|  dS )z
    Creates a ByteStream object from a source.

    :param source:
        A source to convert to a ByteStream. Can be a string (path to a file), a Path object, or a ByteStream.
    :return:
        A ByteStream object.
    	file_pathzUnsupported source type N)
isinstancer   strr   Zfrom_file_pathmeta
ValueErrortype)r	   bs r   H/tmp/pip-unpacked-wheel-z752163x/haystack/components/converters/utils.pyget_bytestream_from_source   s    

r   )r   sources_countr
   c                 C   sT   | dkri g| S t | tr&| g| S t | trH|t| krDtd| S tddS )a  
    Normalize the metadata input for a converter.

    Given all the possible value of the meta input for a converter (None, dictionary or list of dicts),
    makes sure to return a list of dictionaries of the correct length for the converter to use.

    :param meta: the meta input of the converter, as-is
    :param sources_count: the number of sources the converter received
    :returns: a list of dictionaries of the make length as the sources list
    NzAThe length of the metadata list must match the number of sources.zAmeta must be either None, a dictionary or a list of dictionaries.)r   dictlistlenr   )r   r   r   r   r   normalize_metadata   s    



r   N)pathlibr   typingr   r   r   r   r   Zhaystack.dataclassesr   r   r   intr   r   r   r   r   <module>   s   " 