o
    Chn                     @   s   d Z ddlmZ ddlmZ ddlmZmZmZmZm	Z	 ddl
mZ ddlmZ dZd	Zd
ZdZdZG dd dZG dd dZG dd dZdd ZdddZdddZe  dS )z
    tablib.core
    ~~~~~~~~~~~

    This module implements the central Tablib objects.

    :copyright: (c) 2016 by Kenneth Reitz. 2019 Jazzband.
    :license: MIT, see LICENSE for more details.
    )copy)
itemgetter   )HeadersNeededInvalidDatasetIndexInvalidDatasetTypeInvalidDimensionsUnsupportedFormat)registry)normalize_inputtablibzKenneth ReitzMITz,Copyright 2017 Kenneth Reitz. 2019 Jazzband.restructuredtextc                   @   s   e Zd ZdZddgZd*ddZdd Zd	d
 Zdd Zdd Z	dd Z
dd Zdd Zdd Zdd Zdd Zdd Zdd Zdd  Zd!d" Zed#d$ Zed%d& Zd'd( Zd)S )+Rowz/Internal Row object. Mainly used for filtering._rowtags c                 C   s   t || _t || _d S N)listr   r   selfrowr   r   r   ]/var/www/html/myvaluetrips/my_value_trip_new/venv/lib/python3.10/site-packages/tablib/core.py__init__$   s   
zRow.__init__c                 C   s   dd | j D S )Nc                 s   s    | ]}|V  qd S r   r   ).0colr   r   r   	<genexpr>)   s    zRow.__iter__.<locals>.<genexpr>r   r   r   r   r   __iter__(      zRow.__iter__c                 C   
   t | jS r   )lenr   r   r   r   r   __len__+      
zRow.__len__c                 C   r!   r   )reprr   r   r   r   r   __repr__.   r$   zRow.__repr__c                 C   s
   | j | S r   r   r   ir   r   r   __getitem__1   r$   zRow.__getitem__c                 C   s   || j |< d S r   r   )r   r(   valuer   r   r   __setitem__4      zRow.__setitem__c                 C   s   | j |= d S r   r   r'   r   r   r   __delitem__7      zRow.__delitem__c                 C   s   | j | jfS r   r   r   r   r   r   r   __getstate__:   r.   zRow.__getstate__c                 C   s   |\| _ | _d S r   r/   )r   stater   r   r   __setstate__=   r    zRow.__setstate__c                 C   s   |  t| j| d S r   )insertr"   r   r   r*   r   r   r   rpush@      z	Row.rpushc                 C   s   |  d| d S )Nr   r3   r4   r   r   r   lpushC   r    z	Row.lpushc                 C   s   |  | d S r   r5   r4   r   r   r   appendF   r,   z
Row.appendc                 C   s   | j || d S r   )r   r3   )r   indexr*   r   r   r   r3   I   s   z
Row.insertc                 C   s   t | j | j S r   )r   r   r   r   r   r   r   r   r   L   r6   zRow.copyc                 C   s
   || j v S r   r   )r   itemr   r   r   __contains__O   r$   zRow.__contains__c                 C   r!   )z%Tuple representation of :class:`Row`.)tupler   r   r   r   r   r>   R      
z	Row.tuplec                 C   r!   )z$List representation of :class:`Row`.)r   r   r   r   r   r   r   W   r?   zRow.listc                 C   s:   |du rdS t |tr|| jv S ttt|t| j@ S )z)Returns true if current row contains tag.NF)
isinstancestrr   boolr"   set)r   tagr   r   r   has_tag\   s
   

zRow.has_tagN)r   r   )__name__
__module____qualname____doc__	__slots__r   r   r#   r&   r)   r+   r-   r0   r2   r5   r8   r:   r3   r   r=   propertyr>   r   rE   r   r   r   r   r      s.    


r   c                   @   s  e Zd ZdZdd Zdd Zdd Zdd	 Zd
d Zdd Z	dd Z
dd Zdd ZdeddZdfddZdd Zdd ZeeeZdd  Zd!d" ZeeeZd#d$ Zed%d& Zed'd( Zdgd)d*Zd+d, Zdhd.d/Zdhd0d1Zdhd2d3Zdhd4d5Zdhd6d7Zd8d9 Z d:d; Z!d<d= Z"d>d? Z#did@dAZ$dgdBdCZ%dgdDdEZ&djdGdHZ'djdIdJZ(dgdKdLZ)dMdN Z*dOdP Z+dQdR Z,dkdSdTZ-dUdV Z.dWdX Z/dYdZ Z0d[d\ Z1d]d^ Z2d_d` Z3dadb Z4didcddZ5dS )lDataseta  The :class:`Dataset` object is the heart of Tablib. It provides all core
    functionality.

    Usually you create a :class:`Dataset` instance in your main module, and append
    rows as you collect data. ::

        data = tablib.Dataset()
        data.headers = ('name', 'age')

        for (name, age) in some_collector():
            data.append((name, age))


    Setting columns is similar. The column data length must equal the
    current height of the data and headers must be set. ::

        data = tablib.Dataset()
        data.headers = ('first_name', 'last_name')

        data.append(('John', 'Adams'))
        data.append(('George', 'Washington'))

        data.append_col((90, 67), header='age')


    You can also set rows and headers upon instantiation. This is useful if
    dealing with dozens or hundreds of :class:`Dataset` objects. ::

        headers = ('first_name', 'last_name')
        data = [('John', 'Adams'), ('George', 'Washington')]

        data = tablib.Dataset(*data, headers=headers)

    :param \*args: (optional) list of rows to populate Dataset
    :param headers: (optional) list strings for Dataset header row
    :param title: (optional) string to use as title of the Dataset


    .. admonition:: Format Attributes Definition

    If you look at the code, the various output/import formats are not
    defined within the :class:`Dataset` object. To add support for a new format, see
    :ref:`Adding New Formats <newformats>`.

    c                 O   sH   t dd |D | _d | _g | _g | _i | _|d| _|d| _d S )Nc                 s   s    | ]}t |V  qd S r   r   )r   argr   r   r   r          z#Dataset.__init__.<locals>.<genexpr>headerstitle)	r   _data_Dataset__headers_separators_formatters_dynamic_columnsgetrP   rQ   )r   argskwargsr   r   r   r      s   zDataset.__init__c                 C      | j S r   )heightr   r   r   r   r#         zDataset.__len__c                    s`   t |tr|| jv r| j|  fdd| jD S t| j| }t |tr)|jS dd |D S )Nc                       g | ]}|  qS r   r   r   r   posr   r   
<listcomp>       z'Dataset.__getitem__.<locals>.<listcomp>c                 S   s   g | ]}|j qS r   )r>   )r   resultr   r   r   ra      s    )r@   rA   rP   r;   rR   KeyErrorr   r>   )r   key_resultsr   r_   r   r)      s   



zDataset.__getitem__c                 C   s   |  | t|| j|< d S r   )	_validater   rR   )r   re   r*   r   r   r   r+      s   
zDataset.__setitem__c                 C   sr   t |tr3|| jv r1| j|}| j|= || jv r| j|= t| jD ]\}}||= || j|< q"d S t| j|= d S r   )r@   rA   rP   r;   rV   	enumeraterR   rd   )r   re   r`   r(   r   r   r   r   r-      s   


zDataset.__delitem__c                 C   &   zd| j   W S  ty   Y dS w )Nz<%s dataset>z<dataset object>rQ   lowerAttributeErrorr   r   r   r   r&      
   zDataset.__repr__c                    s   g }| j r|dd | j D  |dd | jD  dd |D }tttt| }| j r9|ddd |D  d	d	d t
|D  d
	 fdd|D S )Nc                 S   s   g | ]}t |qS r   )rA   )r   hr   r   r   ra      rb   z#Dataset.__str__.<locals>.<listcomp>c                 s   s    | ]
}t tt|V  qd S r   )r   maprA   r^   r   r   r   r          z"Dataset.__str__.<locals>.<genexpr>c                 S   s   g | ]	}t tt|qS r   )r   ro   r"   r^   r   r   r   ra          r   c                 S   s   g | ]}d | qS -r   )r   lengthr   r   r   ra      rb   |c                 s   s    | ]}d | V  qdS )z{%s:%s}Nr   )r   r<   r   r   r   r      rO   
c                 3   s    | ]} j | V  qd S r   )formatr^   format_stringr   r   r      s    )rS   r:   extendrR   r   ro   maxzipr3   joinrh   )r   rc   lens
field_lensr   rx   r   __str__   s   zDataset.__str__c                 K   s   t |j| fi |S r   )r
   
get_format
export_set)r   fmt_keyrY   r   r   r   _get_in_format   s   zDataset._get_in_formatc                 K   s"   t |}t|j| |fi |S r   )r   r
   r   
import_set)r   r   	in_streamrY   r   r   r   _set_in_format   s   zDataset._set_in_formatNFc                    s   |r j rt| j kpt| j t j k}n'd}n$|r4t|dk r'd}n jr1t| jknd}nt fdd jD }|rDdS |sHtdS )z>Assures size of every row in dataset is of proper proportions.Tr   c                 3   s    | ]
}t | jkV  qd S r   )r"   width)r   xr   r   r   r     rp   z$Dataset._validate.<locals>.<genexpr>F)r   r"   rV   r[   allrR   r   )r   r   r   safetyis_validr   r   r   rg      s    zDataset._validateTc                    sp   t j}fdd jr-|r fdd|D }|S t jg fdd|D  }|S  fdd|D }|S )z=Packages Dataset into lists of dictionaries for transmission.c                    sR   j r%|  } j D ]\} |d u r fdd| D } q
 | | | |< q
t| S )Nc                       g | ]} |qS r   r   )r   cellcallbackr   r   ra     rb   z8Dataset._package.<locals>.format_row.<locals>.<listcomp>)rU   r   r   )r   r   r   r   r   
format_row  s   z$Dataset._package.<locals>.format_rowc                    s$   g | ]}t ttj |qS r   )dictr   r|   rP   r^   r   r   r   r   ra   "  s   $ z$Dataset._package.<locals>.<listcomp>c                    r   r   r   r^   r   r   r   ra   $  rb   c                    r   r   r   r^   r   r   r   ra   &  rb   )r   rR   rP   )r   dictsrR   datar   r   r   _package  s   
zDataset._packagec                 C   rZ   )zAn *optional* list of strings to be used for header rows and attribute names.

        This must be set manually. The given list length must equal :attr:`Dataset.width`.

        )rS   r   r   r   r   _get_headers)  s   zDataset._get_headersc                 C   s&   |  | |rt|| _dS d| _dS )zValidating headers setter.N)rg   r   rS   )r   
collectionr   r   r   _set_headers1  s   

zDataset._set_headersc                 C      |   S )a  A native Python representation of the :class:`Dataset` object. If headers have
        been set, a list of Python dictionaries will be returned. If no headers have been set,
        a list of tuples (rows) will be returned instead.

        A dataset object can also be imported by setting the `Dataset.dict` attribute: ::

            data = tablib.Dataset()
            data.dict = [{'age': 90, 'first_name': 'Kenneth', 'last_name': 'Reitz'}]

        )r   r   r   r   r   	_get_dict;  s   zDataset._get_dictc                 C   s   d}|sdS t |tst|t |d tr(|   |D ]	}| t| qdS t |d trN|   t|d  | _|D ]}| tt|	  q>dS t|)a  A native Python representation of the Dataset object. If headers have been
        set, a list of Python dictionaries will be returned. If no headers have been
        set, a list of tuples (rows) will be returned instead.

        A dataset object can also be imported by setting the :attr:`Dataset.dict` attribute. ::

            data = tablib.Dataset()
            data.dict = [{'age': 90, 'first_name': 'Kenneth', 'last_name': 'Reitz'}]

        z[Please check format documentation https://tablib.readthedocs.io/en/stable/formats.html#yamlNr   )
r@   r   r	   wiper:   r   r   keysrP   values)r   pickleerror_detailsr   r   r   r   	_set_dictH  s$   
zDataset._set_dictc                 C   s:   t |}t|dkrt|d drt t|d | j}|S )zsPrepares the given column for insert/append. `col` is not supposed to
           contain any header value.
        r   r   __call__)r   r"   hasattrro   rR   )r   r   r   r   r   
_clean_colq  s   zDataset._clean_colc                 C   r!   )zfThe number of rows currently in the :class:`Dataset`.
           Cannot be directly modified.
        )r"   rR   r   r   r   r   r[   }  s   
zDataset.heightc                 C   sH   zt | jd W S  ty#   zt | jW  Y S  ty"   Y Y dS w w )ziThe number of columns currently in the :class:`Dataset`.
           Cannot be directly modified.
        r   )r"   rR   
IndexErrorrP   	TypeErrorr   r   r   r   r     s   zDataset.widthc                 K   P   t |}|s
t|}t|}t|dstd| d|j| |fi | | S )z
        Import `in_stream` to the :class:`Dataset` object using the `format`.
        `in_stream` can be a file-like object, a string, or a bytestring.

        :param \*\*kwargs: (optional) custom configuration to the format `import_set`.
        r   Format z cannot be imported.)r   detect_formatr
   r   r   r	   r   r   r   rw   rY   streamfmtr   r   r   load     

zDataset.loadc                 K   6   t |}t|dstd| d|j| fi |S )z
        Export :class:`Dataset` object to `format`.

        :param \*\*kwargs: (optional) custom configuration to the format `export_set`.
        r   r    cannot be exported.)r
   r   r   r	   r   r   rw   rY   r   r   r   r   export     

zDataset.exportr   c                 C   s^   |  | t|| jk r"| j D ]\}}t|}|||| q| j|t||d dS )a  Inserts a row to the :class:`Dataset` at the given index.

        Rows inserted must be the correct size (height or width).

        The default behaviour is to insert the given row to the :class:`Dataset`
        object at the given index.

        You can add :ref:`tags <tags>` to the row you are inserting.
        This gives you the ability to :method:`filter <Dataset.filter>` your
        :class:`Dataset` later.
        )r   N)	rg   r"   r   rV   itemsr   r3   rR   r   )r   r;   r   r   r`   funcr   r   r   r3     s   
zDataset.insertc                 C      | j | j||d dS )zzAdds a row to the end of the :class:`Dataset`.
        See :method:`Dataset.insert` for additional documentation.
        r   r   N)r3   r[   r   r   r   r   r5        zDataset.rpushc                 C      | j d||d dS )zzAdds a row to the top of the :class:`Dataset`.
        See :method:`Dataset.insert` for additional documentation.
        r   r   Nr7   r   r   r   r   r8        zDataset.lpushc                 C      |  || dS )zoAdds a row to the :class:`Dataset`.
        See :method:`Dataset.insert` for additional documentation.
        Nr9   r   r   r   r   r:        zDataset.appendc                 C   s   |D ]}|  || qdS )z[Adds a list of rows to the :class:`Dataset` using
        :method:`Dataset.append`
        N)r:   )r   rowsr   r   r   r   r   rz     s   zDataset.extendc                 C      | d }| d= |S )z:Removes and returns the first row of the :class:`Dataset`.r   r   r   cacher   r   r   lpop     zDataset.lpopc                 C   r   )9Removes and returns the last row of the :class:`Dataset`.r   r   r   r   r   rpop  r   zDataset.rpopc                 C   r   )r   )r   r   r   r   r   pop  s   zDataset.popc                 C   s   t |tr	| | S td)z=Returns the row from the :class:`Dataset` at the given index.zRow indices must be integers.)r@   intr   r   r;   r   r   r   rW     s   
zDataset.getc                 C   s   |du rg }t |r|| j| j< tt|| j}| |}| j|d | jr?|s+t	 |r8| j
dkr8t|r8t| j|| | j
r^| jr^t| jD ]\}}||||  || j|< qJdS dd |D | _dS )a?  Inserts a column to the :class:`Dataset` at the given index.

        Columns inserted must be the correct height.

        You can also insert a column of a single callable object, which will
        add a new column with the return values of the callable each as an
        item in the column. ::

            data.append_col(col=random.randint)

        If inserting a column, and :attr:`Dataset.headers` is set, the
        header attribute must be set, and will be considered the header for
        that row.

        See :ref:`dyncols` for an in-depth example.
        Nr   r   c                 S   s   g | ]}t |gqS r   rM   r^   r   r   r   ra   6  s    z&Dataset.insert_col.<locals>.<listcomp>)callablerV   r   r   ro   rR   r   rg   rP   r   r[   r"   r   r3   rh   )r   r;   r   headerr(   r   r   r   r   
insert_col  s&   
zDataset.insert_colc                 C   r   )z}Adds a column to the end of the :class:`Dataset`.
        See :method:`Dataset.insert` for additional documentation.
        r   N)r   r   r   r   r   r   r   r   	rpush_col8  r   zDataset.rpush_colc                 C   r   )z}Adds a column to the top of the :class:`Dataset`.
        See :method:`Dataset.insert` for additional documentation.
        r   r   N)r   r   r   r   r   	lpush_col?  r   zDataset.lpush_colrs   c                 C   s   ||f}| j | dS )z4Adds a separator to :class:`Dataset` at given index.N)rT   r:   )r   r;   textsepr   r   r   insert_separatorF  s   zDataset.insert_separatorc                 C   s<   | j s| jr	| jnd}n
| jr| jd nd}| || dS )z=Adds a :ref:`separator <separators>` to the :class:`Dataset`.r   r   N)rP   r[   r   )r   r   r;   r   r   r   append_separatorL  s   zDataset.append_separatorc                 C   r   )zvAdds a column to the :class:`Dataset`.
        See :method:`Dataset.insert_col` for additional documentation.
        N)r   r   r   r   r   
append_colW  r   zDataset.append_colc                    s    fdd| j D S )z@Returns the column from the :class:`Dataset` at the given index.c                    r]   r   r   r^   r;   r   r   ra   a  rb   z#Dataset.get_col.<locals>.<listcomp>)rR   r   r   r   r   get_col^  s   zDataset.get_colc                 C   sP   t |tr|| jv r| j|}nt|du s|| jkr&| j||f dS t)a'  Adds a formatter to the :class:`Dataset`.

        :param col: column to. Accepts index int, header str, or None to apply
                    the formatter to all columns.
        :param handler: reference to callback function to execute against
                        each cell value.
        NT)	r@   rA   rP   r;   rd   r   rU   r:   r   )r   r   handlerr   r   r   add_formatterg  s   
	
zDataset.add_formatterc                    s"   t | } fdd|jD |_|S )zReturns a new instance of the :class:`Dataset`, excluding any rows
        that do not contain the given :ref:`tags <tags>`.
        c                    s   g | ]	}|  r|qS r   )rE   r^   rD   r   r   ra     rq   z"Dataset.filter.<locals>.<listcomp>)r   rR   )r   rD   _dsetr   r   r   filter}  s   zDataset.filterc                    s   t |tr3| js
tt| jt||d}t| j| jd}|D ]  fdd| jD }|j	|d q|S | jr;| j| }t| jt||d}t| j| jd}|D ] | jr_ fdd| jD }n }|j	|d qO|S )a  Sort a :class:`Dataset` by a specific column, given string (for
        header) or integer (for column index). The order can be reversed by
        setting ``reverse`` to ``True``.

        Returns a new :class:`Dataset` instance where columns have been
        sorted.
        )re   reverse)rP   rQ   c                       g | ]} | qS r   r   r   re   r<   r   r   ra     rb   z Dataset.sort.<locals>.<listcomp>r   c                    r   r   r   r   r   r   r   ra     rb   )
r@   rA   rP   r   sortedr   r   rL   rQ   r:   )r   r   r   _sortedr   r   r   r   r   sort  s&   
	
zDataset.sortc                 C   sr   t  }| jd g| | jd   }||_t| jD ]\}}|| jd kr$q|g| | }t|}|j|d q|S )zTranspose a :class:`Dataset`, turning rows into columns and vice
        versa, returning a new ``Dataset`` instance. The first row of the
        original instance becomes the new header row.r   r   )rL   rP   rh   r   r   r:   )r   r   new_headersr;   columnrow_datar   r   r   _transpose_with_headers  s   zDataset._transpose_with_headersc                 C   s:   t  }tdt| jd D ]}| |}|j|d q|S )zTranspose a :class:`Dataset`, turning rows into columns and vice
        versa, returning a new ``Dataset`` instance. This instance should not
        have headers, or the dimension would be invalid.r   r   )rL   ranger"   rR   r   r:   )r   r   r;   r   r   r   r   _transpose_without_headers  s
   
z"Dataset._transpose_without_headersc                 C   s"   | sdS | j du r|  S |  S )zTranspose a :class:`Dataset`, turning rows into columns and vice
        versa, returning a new ``Dataset`` instance. If the instance has
        headers, the first row of the original instance becomes the new header
        row.N)rP   r   r   r   r   r   r   	transpose  s
   
zDataset.transposec                 C   sZ   t |tsdS | j|jkrtt| }dd |jD }dd |jD }|| ||_|S )zStack two :class:`Dataset` instances together by
        joining at the row level, and return new combined
        ``Dataset`` instance.Nc                 S      g | ]}|qS r   r   r^   r   r   r   ra         z!Dataset.stack.<locals>.<listcomp>c                 S   r   r   r   r^   r   r   r   ra     r   )r@   rL   r   r   r   rR   rz   )r   otherr   rows_to_stack
other_rowsr   r   r   stack  s   

zDataset.stackc                 C   s   t |tsdS | js|jr| jr|jst| j|jkrtz| j|j }W n ty0   d}Y nw t }| jD ]
}|j| | d q7|jD ]
}|j|| d qE||_|S )zStack two :class:`Dataset` instances together by
        joining at the column level, and return a new
        combined ``Dataset`` instance. If either ``Dataset``
        has headers set, than the other must as well.Nr   )r@   rL   rP   r   r[   r   r   r   )r   r   r   r   r   r   r   r   
stack_cols  s&   


zDataset.stack_colsc                    s(   t    fdd| jD | jdd< dS )ziRemoves all duplicate rows from the :class:`Dataset` object
        while maintaining the original order.c                    s*   g | ]}t | v s t |s|qS r   )r>   addr^   seenr   r   ra     s    $z-Dataset.remove_duplicates.<locals>.<listcomp>N)rC   rR   r   r   r   r   remove_duplicates  s   
zDataset.remove_duplicatesc                 C   s   t  | _d| _dS )zARemoves all content and headers from the :class:`Dataset` object.N)r   rR   rS   r   r   r   r   r     s   
zDataset.wipec           	         s    sdS |du rt t j}|du rt  j} fdd|D } fdd|D }t }t ||_g |_t jD ],\}}g }|jD ]}| jv rX j|}|||  qCt	||v rf|jt
|d q:|S )zkReturns a new instance of the :class:`Dataset`,
        including only specified rows and columns.
        Nc                    s   g | ]}|t  jv r|qS r   )r   r[   r^   r   r   r   ra   4  s    z"Dataset.subset.<locals>.<listcomp>c                    s   g | ]	}| j v r|qS r   )rP   )r   r   r   r   r   ra   5  rq   r   )r   r   r[   rP   rL   rR   rh   r;   r:   rd   r   )	r   r   colsr   row_nor   data_rowre   r`   r   r   r   subset$  s,   



zDataset.subset)NNF)Tr   )r   )NNrr   )F)6rF   rG   rH   rI   r   r#   r)   r+   r-   r&   r   r   r   rg   r   r   r   rK   rP   r   r   r   r   r[   r   r   r   r3   r5   r8   r:   rz   r   r   r   rW   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rL   g   sj    .



'









1



	
	%!rL   c                   @   s^   e Zd ZdZdddZdd Zdd Zd	d
 Zdd Zdd Z	e
dd Zdd Zdd ZdS )Databookz(A book of :class:`Dataset` objects.
    Nc                 C   s   |pg | _ d S r   	_datasets)r   setsr   r   r   r   P  r,   zDatabook.__init__c                 C   ri   )Nz<%s databook>z<databook object>rj   r   r   r   r   r&   S  rm   zDatabook.__repr__c                 C   s
   g | _ dS )z@Removes all :class:`Dataset` objects from the :class:`Databook`.Nr   r   r   r   r   r   Y  s   
zDatabook.wipec                 C   rZ   r   r   r   r   r   r   sheets]  r\   zDatabook.sheetsc                 C   s   t |tr| j| dS t)z5Adds given :class:`Dataset` to the :class:`Databook`.N)r@   rL   r   r:   r   )r   datasetr   r   r   	add_sheet`  s   
zDatabook.add_sheetc                 C   s*   g }| j D ]}||j| d q|S )z(Packages :class:`Databook` for delivery.)rQ   r   )r   r:   rQ   r   )r   	collectordsetr   r   r   r   g  s   

zDatabook._packagec                 C   r!   )zDThe number of the :class:`Dataset` objects within :class:`Databook`.)r"   r   r   r   r   r   sizer  r?   zDatabook.sizec                 K   r   )z
        Import `in_stream` to the :class:`Databook` object using the `format`.
        `in_stream` can be a file-like object, a string, or a bytestring.

        :param \*\*kwargs: (optional) custom configuration to the format `import_book`.
        import_bookr   z cannot be loaded.)r   r   r
   r   r   r	   r  r   r   r   r   r   w  r   zDatabook.loadc                 K   r   )z
        Export :class:`Databook` object to `format`.

        :param \*\*kwargs: (optional) custom configuration to the format `export_book`.
        export_bookr   r   )r
   r   r   r	   r  r   r   r   r   r     r   zDatabook.exportr   )rF   rG   rH   rI   r   r&   r   r   r  r   rK   r  r   r   r   r   r   r   r   L  s    

r   c              
   C   s   t | } d}t D ]@}z2z|| r(|j}W W t| dr%| d  |S  |S W n	 ty2   Y nw W t| dr>| d q
t| drJ| d w w |S )zMReturn format name of given stream (file-like object, string, or bytestring).Nseekr   )r   r
   formatsdetectrQ   r   r  rl   )r   	fmt_titler   r   r   r   r     s0   




r   Nc                 K      t  j| |fi |S zIReturn dataset of given stream (file-like object, string, or bytestring).)rL   r   r   rw   rY   r   r   r   r        r   c                 K   r  r  )r   r   r  r   r   r   r    r  r  r   )rI   r   operatorr   
exceptionsr   r   r   r   r	   r	  r
   utilsr   	__title__
__author____license____copyright____docformat__r   rL   r   r   r   r  register_builtinsr   r   r   r   <module>   s.    
H     jK

