Ë
    –2ÚiLk  ã                   óè   — d Z ddlm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«      Z G d„ d«      Z G d„ d«      Zd„ Zdd„Zdd„Z ej6                  «        y)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.
é    )ÚOrderedDict)Úcopy)Ú
itemgetter)ÚHeadersNeededÚInvalidDatasetIndexÚInvalidDatasetTypeÚInvalidDimensionsÚUnsupportedFormat)Úregistry)Únormalize_inputÚtablibzKenneth ReitzÚMITz,Copyright 2017 Kenneth Reitz. 2019 Jazzband.Úrestructuredtextc                   ó”   — e Zd ZdZddgZdd„Zd„ Zd„ Zd„ Zd„ Z	d	„ Z
d
„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zed„ «       Zed„ «       Zd„ Zy)ÚRowz/Internal Row object. Mainly used for filtering.Ú_rowÚtagsc                 óD   — t        |«      | _        t        |«      | _        y ©N)Úlistr   r   ©ÚselfÚrowr   s      úB/var/www/html/acx/venv/lib/python3.12/site-packages/tablib/core.pyÚ__init__zRow.__init__%   s   € Ü˜“IˆŒ	Ü˜“Jˆ�	ó    c                 ó(   — d„ | j                   D «       S )Nc              3   ó    K  — | ]  }|–— Œ y ­wr   © )Ú.0Úcols     r   ú	<genexpr>zRow.__iter__.<locals>.<genexpr>*   s   è ø€ Ò)˜”Ñ)ùs   ‚©r   ©r   s    r   Ú__iter__zRow.__iter__)   s   € Ù)˜tŸy™yÔ)Ð)r   c                 ó,   — t        | j                  «      S r   )Úlenr   r$   s    r   Ú__len__zRow.__len__,   s   € Ü�4—9‘9‹~Ðr   c                 ó,   — t        | j                  «      S r   )Úreprr   r$   s    r   Ú__repr__zRow.__repr__/   s   € Ü�D—I‘I‹Ðr   c                 ó    — | j                   |   S r   r#   ©r   Úis     r   Ú__getitem__zRow.__getitem__2   s   € Ø�y‰y˜‰|Ðr   c                 ó"   — || j                   |<   y r   r#   )r   r.   Úvalues      r   Ú__setitem__zRow.__setitem__5   s   € Øˆ�	‰	�!Šr   c                 ó   — | j                   |= y r   r#   r-   s     r   Ú__delitem__zRow.__delitem__8   s   € Ø�I‰I�a‰Lr   c                 ó2   — | j                   | j                  fS r   ©r   r   r$   s    r   Ú__getstate__zRow.__getstate__;   s   € Ø�y‰y˜$Ÿ)™)Ð#Ð#r   c                 ó"   — |\  | _         | _        y r   r6   )r   Ústates     r   Ú__setstate__zRow.__setstate__>   s   € Ø$ÑˆŒ	�4•9r   c                 óN   — | j                  t        | j                  «      |«       y r   )Úinsertr'   r   ©r   r1   s     r   Úrpushz	Row.rpushA   s   € Ø�‰”C˜Ÿ	™	“N EÕ*r   c                 ó(   — | j                  d|«       y )Nr   ©r<   r=   s     r   Úlpushz	Row.lpushD   s   € Ø�‰�A�uÕr   c                 ó&   — | j                  |«       y r   ©r>   r=   s     r   Úappendz
Row.appendG   s   € Ø�
‰
�5Õr   c                 ó<   — | j                   j                  ||«       y r   )r   r<   )r   Úindexr1   s      r   r<   z
Row.insertJ   s   € Ø�	‰	×Ñ˜ Õ&r   c                 ó   — || j                   v S r   r#   )r   Úitems     r   Ú__contains__zRow.__contains__M   s   € Ø˜Ÿ	™	Ð!Ð"r   c                 ó,   — t        | j                  «      S )z%Tuple representation of :class:`Row`.)Útupler   r$   s    r   rK   z	Row.tupleP   s   € ô �T—Y‘YÓÐr   c                 ó,   — t        | j                  «      S )z$List representation of :class:`Row`.)r   r   r$   s    r   r   zRow.listU   s   € ô �D—I‘I‹Ðr   c                 óª   — |€yt        |t        «      r|| j                  v S t        t	        t        |«      t        | j                  «      z  «      «      S )z)Returns true if current row contains tag.F)Ú
isinstanceÚstrr   Úboolr'   Úset)r   Útags     r   Úhas_tagzRow.has_tagZ   sF   € ð ˆ;ØÜ˜œSÔ!Ø˜4Ÿ9™9Ð$Ð%äœœC ›H¤s¨4¯9©9£~Ñ5Ó6Ó7Ð7r   N)r   r   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ú	__slots__r   r%   r(   r+   r/   r2   r4   r7   r:   r>   rA   rD   r<   rI   ÚpropertyrK   r   rS   r   r   r   r   r       s‚   „ Ù9à˜Ð €Ióò*òòòòòò$ò%ò+òòò'ò#ð ñ ó ð ð ñó ðó8r   r   c                   óp  — e Zd ZdZd„ Zd„ Zd„ Zd„ Zd„ Zd„ Z	d„ Z
d	„ Zd
„ Zd/d„Zd0d„Zd„ Zd„ Z eee«      Zd„ Zd„ Z eee«      Zd„ Zed„ «       Zed„ «       Zd1d„Zd„ Zd2d„Zd2d„Zd2d„Zd2d„Zd2d„Zd„ Z d„ Z!d„ Z"d3d„Z#d1d „Z$d1d!„Z%d4d"„Z&d4d#„Z'd1d$„Z(d%„ Z)d&„ Z*d'„ Z+d5d(„Z,d)„ Z-d*„ Z.d+„ Z/d,„ Z0d-„ Z1d3d.„Z2y)6Ú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                 ó´   — t        d„ |D «       «      | _        d | _        g | _        g | _        |j                  d«      | _        |j                  d«      | _        y )Nc              3   ó2   K  — | ]  }t        |«      –— Œ y ­wr   )r   )r    Úargs     r   r"   z#Dataset.__init__.<locals>.<genexpr>•   s   è ø€ Ò3 sœ#˜cŸ(Ñ3ùs   ‚ÚheadersÚtitle)r   Ú_dataÚ_Dataset__headersÚ_separatorsÚ_formattersÚgetr_   r`   )r   ÚargsÚkwargss      r   r   zDataset.__init__”   sO   € ÜÑ3¨dÔ3Ó3ˆŒ
ØˆŒð ˆÔð ˆÔà—z‘z )Ó,ˆŒà—Z‘Z Ó(ˆ�
r   c                 ó   — | j                   S r   )Úheightr$   s    r   r(   zDataset.__len__¢   s   € Ø�{‰{Ðr   c                 óX  — t        |t        «      rL|| j                  v r8| j                  j                  |«      }| j                  D �cg c]  }||   ‘Œ	 c}S t
        ‚| j                  |   }t        |t        «      r|j                  S |D �cg c]  }|j                  ‘Œ c}S c c}w c c}w r   )rN   rO   r_   rF   ra   ÚKeyErrorr   rK   )r   ÚkeyÚposr   Ú_resultsÚresults         r   r/   zDataset.__getitem__¥   sŠ   € Ü�cœ3ÔØ�d—l‘lÑ"Ø—l‘l×(Ñ(¨Ó-�Ø,0¯J©JÖ7 S˜˜C›Ò7Ð7ä�à—z‘z #‘ˆHÜ˜(¤CÔ(Ø—~‘~Ð%à3;Ö<¨˜Ÿ›Ò<Ð<ùò 8ùò =s   ÁB"ÂB'c                 óV   — | j                  |«       t        |«      | j                  |<   y r   )Ú	_validater   ra   )r   rl   r1   s      r   r2   zDataset.__setitem__³   s   € Ø�‰�uÔÜ˜e›*ˆ�
‰
�3Šr   c                 ó  — t        |t        «      rl|| j                  v rX| j                  j                  |«      }| j                  |= t	        | j
                  «      D ]  \  }}||= || j
                  |<   Œ y t        ‚| j
                  |= y r   )rN   rO   r_   rF   Ú	enumeratera   rk   )r   rl   rm   r.   r   s        r   r4   zDataset.__delitem__·   sz   € Ü�cœ3Ôà�d—l‘lÑ"à—l‘l×(Ñ(¨Ó-�Ø—L‘L Ð%ä'¨¯
©
Ó3ò (‘F�A�sà˜C˜Ø$'�D—J‘J˜q’Mñ(ô
 �à—
‘
˜3‘r   c                 ó\   — 	 d| j                   j                  «       z  S # t        $ r Y yw xY w)Nz<%s dataset>z<dataset object>©r`   ÚlowerÚAttributeErrorr$   s    r   r+   zDataset.__repr__È   s1   € ð	&Ø! T§Z¡Z×%5Ñ%5Ó%7Ñ8Ð8øÜò 	&Ù%ð	&úó   ‚ Ÿ	+ª+c           	      óD  ‡— g }| j                   r2|j                  | j                   D �cg c]  }t        |«      ‘Œ c}«       |j                  d„ | j                  D «       «       |D �cg c]  }t        t        t        |«      «      ‘Œ }}t        t        t        t        |Ž «      «      }| j                   r#|j                  d|D �cg c]  }d|z  ‘Œ	 c}«       dj                  d„ t        |«      D «       «      Šdj                  ˆfd„|D «       «      S c c}w c c}w c c}w )Nc              3   óN   K  — | ]  }t        t        t        |«      «      –— Œ y ­wr   )r   ÚmaprO   )r    r   s     r   r"   z"Dataset.__str__.<locals>.<genexpr>Ö   s   è ø€ Ò@¨c”dœ3œs C›=×)Ñ@ùs   ‚#%é   ú-ú|c              3   ó&   K  — | ]	  }d |z  –— Œ y­w)z{%s:%s}Nr   )r    rH   s     r   r"   z"Dataset.__str__.<locals>.<genexpr>ß   s   è ø€ Ò T°d ¨TÕ!1Ñ Tùs   ‚ú
c              3   ó<   •K  — | ]  } ‰j                   |Ž –— Œ y ­wr   )Úformat)r    r   Úformat_strings     €r   r"   z"Dataset.__str__.<locals>.<genexpr>á   s   øè ø€ ÒF¸Ð-˜×-Ñ-¨sÔ3ÑFùs   ƒ)rb   rD   rO   Úextendra   r   r{   r'   ÚmaxÚzipr<   Újoinrs   )r   ro   Úhr   ÚlensÚ
field_lensÚlengthrƒ   s          @r   Ú__str__zDataset.__str__Î   sß   ø€ Øˆð �>Š>Ø�M‰M¨4¯>©>Ö: aœ3˜q�6Ò:Ô;ð 	�‰Ñ@°T·Z±ZÔ@Ô@à/5Ö6¨””Sœ˜c“]Õ#Ð6ˆÐ6Üœ#œc¤3¨ :Ó.Ó/ˆ
ð �>Š>Ø�M‰M˜!¸ÖD¨v˜c F›lÒDÔEàŸ™Ñ T¼iÈ
Ó>SÔ TÓTˆà�y‰yÓF¸vÔFÓFÐFùò ;ùò
 7ùò
 Es   ©DÁ( DÃD
c                 óN   —  t        j                  |«      j                  | fi |¤ŽS r   )r   Ú
get_formatÚ
export_set)r   Úfmt_keyrg   s      r   Ú_get_in_formatzDataset._get_in_formatç   s%   € Ø6Œx×"Ñ" 7Ó+×6Ñ6°tÑF¸vÑFÐFr   c                 óf   — t        |«      } t        j                  |«      j                  | |fi |¤ŽS r   )r   r   rŽ   Ú
import_set)r   r�   Ú	in_streamrg   s       r   Ú_set_in_formatzDataset._set_in_formatê   s1   € Ü# IÓ.ˆ	Ø6Œx×"Ñ" 7Ó+×6Ñ6°t¸YÑQÈ&ÑQÐQr   Nc                 ó  ‡ — |r'‰ j                   rt        |«      ‰ j                   k(  nd}nX|r8t        |«      dk  rd}nE‰ j                  rt        |«      ‰ j                  k(  nd}nt        ˆ fd„‰ j                  D «       «      }|ry|st
        ‚y)z>Assures size of every row in dataset is of proper proportions.Tr|   c              3   óN   •K  — | ]  }t        |«      ‰j                  k(  –— Œ y ­wr   )r'   Úwidth)r    Úxr   s     €r   r"   z$Dataset._validate.<locals>.<genexpr>ø   s   øè ø€ ÒD°Aœ3˜q›6 T§Z¡ZÕ/ÑDùs   ƒ"%F)r˜   r'   ri   Úallra   r	   )r   r   r!   ÚsafetyÚis_valids   `    r   rq   zDataset._validateî   ss   ø€ áØ37·:²:œ˜C› D§J¡JÒ.À4‰HÙÜ�3‹x˜!Š|Ø‘à8<¿ºœC ›H¨¯©Ò3È‘äÓD¸¿¹ÔDÓDˆHáØáÜ'Ð'Ør   c                 óV  — t        | j                  «      }|rt        }nt        }| j                  r]t        |«      D ]O  \  }}| j                  D ];  \  }}	 |€"t        |«      D ]  \  }	}
 ||
«      ||   |	<   Œ n |||   «      ||   |<   Œ= ŒQ | j                  rZ|r4|D �cg c]'  } |t        t        | j                  |«      «      «      ‘Œ) }}|S t        | j                  «      gt        |«      z   }|S |D �cg c]  }t        |«      ‘Œ }}|S # t        $ r t        ‚w xY wc c}w c c}w )z=Packages Dataset into lists of dictionaries for transmission.)
r   ra   r   Údictrd   rs   Ú
IndexErrorr   r_   r†   )r   ÚdictsÚorderedra   Ú	dict_packÚrow_ir   r!   ÚcallbackÚjÚcÚdata_rowÚdatas                r   Ú_packagezDataset._package  sD  € ô �T—Z‘ZÓ ˆáÜ#‰IäˆIð ×ÒÜ'¨Ó.ò 	2‘
��sØ%)×%5Ñ%5ò 2‘M�C˜ð2Ø˜;Ü(1°#«ò >¡  1Ù2:¸1³+  e¡¨Q¢ñ>ñ 19¸¸S¹Ó0B˜E %™L¨Ñ-øñ2ð	2ð �<Š<ÙØUZÖ[È™	¤$¤s¨4¯<©<¸Ó'BÓ"CÕDÐ[�Ð[ð ˆô	 ˜TŸ\™\Ó*Ð+¬d°5«kÑ9�ð ˆð */Ö/ #”D˜•IÐ/ˆDÐ/àˆøô &ò 2Ü1Ð1ð2üò
 \ùò 0s   Á5DÂ ,D!Ã8D&ÄDc                 ó   — | j                   S )z³An *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`.

        )rb   r$   s    r   Ú_get_headerszDataset._get_headers#  s   € ð �~‰~Ðr   c                 ó‚   — | j                  |«       |r	 t        |«      | _        yd| _        y# t        $ r t        ‚w xY w)zValidating headers setter.N)rq   r   rb   Ú	TypeError)r   Ú
collections     r   Ú_set_headerszDataset._set_headers+  sA   € à�‰�zÔ"Ùð Ü!% jÓ!1�•ð "ˆD�Nøô ò  Ü�ð ús   •. ®>c                 ó"   — | j                  «       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$   s    r   Ú	_get_dictzDataset._get_dict8  s   € ð �}‰}‹Ðr   c           	      óÜ  — d}|syt        |t        «      st        |«      ‚t        |d   t        «      r2| j                  «        |D ]  }| j	                  t        |«      «       Œ yt        |d   t        «      rj| j                  «        t        |d   j                  «       «      | _        |D ]3  }| j	                  t        t        |j                  «       «      «      «       Œ5 y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   )
rN   r   r
   ÚwiperD   r   rž   Úkeysr_   Úvalues)r   ÚpickleÚerror_detailsr   s       r   Ú	_set_dictzDataset._set_dictE  sÌ   € ðHð 	ñ
 Øä˜&¤$Ô'ô $ MÓ2Ð2ô �f˜Q‘i¤Ô&Ø�I‰IŒKØò &�Ø—‘œC ›HÕ%ñ&ô ˜˜q™	¤4Ô(Ø�I‰IŒKÜ  q¡	§¡Ó 0Ó1ˆDŒLØò 5�Ø—‘œC¤ S§Z¡Z£\Ó 2Ó3Õ4ñ5ô $ MÓ2Ð2r   c                 óø   — t        |«      }| j                  r|j                  d«      g}ng }t        |«      dk(  r1t	        |d   d«      r"t        t        |d   | j                  «      «      }t        ||z   «      }|S )z,Prepares the given column for insert/append.r   r|   Ú__call__)r   r_   Úpopr'   Úhasattrr{   ra   rK   ©r   r!   Úheaders      r   Ú
_clean_colzDataset._clean_coln  sl   € ô �3‹iˆà�<Š<Ø—g‘g˜a“j�\‰FàˆFäˆs‹8�qŠ=œW S¨¡V¨ZÔ8ä”s˜3˜q™6 4§:¡:Ó.Ó/ˆCÜ�F˜S‘LÓ!ˆàˆ
r   c                 ó,   — t        | j                  «      S )zfThe number of rows currently in the :class:`Dataset`.
           Cannot be directly modified.
        )r'   ra   r$   s    r   ri   zDataset.height  s   € ô
 �4—:‘:‹Ðr   c                 óž   — 	 t        | j                  d   «      S # t        $ r) 	 t        | j                  «      cY S # t        $ r Y Y yw xY ww xY w)ziThe number of columns currently in the :class:`Dataset`.
           Cannot be directly modified.
        r   )r'   ra   rŸ   r_   r­   r$   s    r   r˜   zDataset.width†  sO   € ð	Ü�t—z‘z !‘}Ó%Ð%øÜò 	ðÜ˜4Ÿ<™<Ó(Ò(øÜò Úðúð	ús)   ‚ š	A¤;¸A»	AÁAÁAÁAc                 óè   — t        |«      }|st        |«      }t        j                  |«      }t	        |d«      st        d|› d�«      ‚t        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”   r‚   rg   ÚstreamÚfmts         r   ÚloadzDataset.load”  s|   € ô ! Ó+ˆÙÜ" 6Ó*ˆFä×!Ñ! &Ó)ˆÜ�s˜LÔ)Ü# g¨f¨XÐ5IÐ$JÓKÐKåÜ# g¨f¨XÐ5IÐ$JÓKÐKàˆ�‰�t˜VÑ. vÒ.Øˆr   c                 óˆ   — t        j                  |«      }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   r‚   rg   rÇ   s       r   ÚexportzDataset.exportª  sI   € ô ×!Ñ! &Ó)ˆÜ�s˜LÔ)Ü# g¨f¨XÐ5IÐ$JÓKÐKàˆs�~‰~˜dÑ- fÑ-Ð-r   c                 ót   — | j                  |«       | j                  j                  |t        ||¬«      «       y)zù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.
       )r   N)rq   ra   r<   r   )r   rF   r   r   s       r   r<   zDataset.insertº  s+   € ð 	�‰�sÔØ�
‰
×Ñ˜%¤ S¨tÔ!4Õ5r   c                 ó@   — | j                  | j                  ||¬«       y)zzAdds a row to the end of the :class:`Dataset`.
        See :method:`Dataset.insert` for additional documentation.
        ©r   r   N)r<   ri   r   s      r   r>   zDataset.rpushÆ  s   € ð
 	�‰�D—K‘K S¨tˆÕ4r   c                 ó,   — | j                  d||¬«       y)zzAdds a row to the top of the :class:`Dataset`.
        See :method:`Dataset.insert` for additional documentation.
        r   rÏ   Nr@   r   s      r   rA   zDataset.lpushÍ  s   € ð
 	�‰�A˜3 TˆÕ*r   c                 ó(   — | j                  ||«       y)zoAdds a row to the :class:`Dataset`.
        See :method:`Dataset.insert` for additional documentation.
        NrC   r   s      r   rD   zDataset.appendÔ  s   € ð
 	�
‰
�3˜Õr   c                 ó6   — |D ]  }| j                  ||«       Œ y)z[Adds a list of rows to the :class:`Dataset` using
        :method:`Dataset.append`
        N)rD   )r   Úrowsr   r   s       r   r„   zDataset.extendÛ  s!   € ð
 ò 	#ˆCØ�K‰K˜˜TÕ"ñ	#r   c                 ó   — | d   }| d= |S )z:Removes and returns the first row of the :class:`Dataset`.r   r   ©r   Úcaches     r   ÚlpopzDataset.lpopã  s   € ð �Q‘ˆØ�ˆGàˆr   c                 ó   — | d   }| d= |S )ú9Removes and returns the last row of the :class:`Dataset`.éÿÿÿÿr   rÕ   s     r   ÚrpopzDataset.rpopë  s   € ð �R‘ˆØ�ˆHàˆr   c                 ó"   — | j                  «       S )rÙ   )rÛ   r$   s    r   r»   zDataset.popó  s   € ð �y‰y‹{Ðr   c                 óP  — |€g }t        |d«      rt        t        || j                  «      «      }| j	                  |«      }| j                  |¬«       | j                  rJ|s
t        «       ‚|r | j                  dk(  rt        |«      rt        ‚| j                  j                  ||«       | j                  rN| j                  rBt        | j                  «      D ])  \  }}|j                  |||   «       || j                  |<   Œ+ y|D �cg c]  }t        |g«      ‘Œ c}| _        yc c}w )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.

        .. versionchanged:: 0.9.0
           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.

        .. versionadded:: 0.9.0
           If inserting a row, 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.

        Nrº   ©r!   r   )r¼   r   r{   ra   r¿   rq   r_   r   ri   r'   r	   r<   r˜   rs   r   )r   rF   r!   r¾   r.   r   s         r   Ú
insert_colzDataset.insert_colü  sò   € ð: ˆ;ØˆCô �3˜
Ô#Ü”s˜3 §
¡
Ó+Ó,ˆCà�o‰o˜cÓ"ˆØ�‰˜3ˆÔà�<Š<áÜ#“oÐ%ñ ˜DŸK™K¨1Ò,´°S´Ü'Ð'à�L‰L×Ñ  vÔ.à�;Š;˜4Ÿ:š:ä# D§J¡JÓ/ò $‘��3à—
‘
˜5 # a¡&Ô)Ø #�—
‘
˜1’ñ$ð
 14Ö4¨œ#˜s˜e�*Ò4ˆD�JùÒ4s   ÄD#c                 ó@   — | j                  | j                  ||¬«       y)z}Adds a column to the end of the :class:`Dataset`.
        See :method:`Dataset.insert` for additional documentation.
        ©r¾   N)rß   r˜   r½   s      r   Ú	rpush_colzDataset.rpush_col7  s   € ð
 	�‰˜Ÿ
™
 C°ˆÕ7r   c                 ó,   — | j                  d||¬«       y)z}Adds a column to the top of the :class:`Dataset`.
        See :method:`Dataset.insert` for additional documentation.
        r   rá   N)rß   r½   s      r   Ú	lpush_colzDataset.lpush_col>  s   € ð
 	�‰˜˜3 vˆÕ.r   c                 óB   — ||f}| j                   j                  |«       y)z4Adds a separator to :class:`Dataset` at given index.N)rc   rD   )r   rF   ÚtextÚseps       r   Úinsert_separatorzDataset.insert_separatorE  s!   € ð �dˆmˆØ×Ñ×Ñ Õ$r   c                 ó°   — | j                   s| j                  r| j                  nd}n| j                  r| j                  dz   nd}| j                  ||«       y)z=Adds a :ref:`separator <separators>` to the :class:`Dataset`.r   r|   N)r_   ri   rè   )r   ræ   rF   s      r   Úappend_separatorzDataset.append_separatorK  sA   € ð �|Š|Ø#'§;¢;�D—K’K°A‰Eà)-¯ª�T—[‘[ 1’_¸!ˆEà×Ñ˜e TÕ*r   c                 ó(   — | j                  ||«       y)zvAdds a column to the :class:`Dataset`.
        See :method:`Dataset.insert_col` for additional documentation.
        N)râ   r½   s      r   Ú
append_colzDataset.append_colV  s   € ð
 	�‰�s˜FÕ#r   c                 óF   — | j                   D �cg c]  }||   ‘Œ	 c}S c c}w )z@Returns the column from the :class:`Dataset` at the given index.)ra   )r   rF   r   s      r   Úget_colzDataset.get_col]  s    € ð '+§j¡jÖ1˜s��E“
Ò1Ð1ùÒ1s   �c                 óè   — t        |t        «      r0|| j                  v r| j                  j                  |«      }nt        ‚|| j
                  kD  s| j                  j                  ||f«       yt        ‚)a  Adds a formatter to the :class:`Dataset`.

        .. versionadded:: 0.9.5

        :param col: column to. Accepts index int or header str.
        :param handler: reference to callback function to execute against
                        each cell value.
        T)	rN   rO   r_   rF   rk   r˜   rd   rD   r   )r   r!   Úhandlers      r   Úadd_formatterzDataset.add_formatterf  sd   € ô �cœ3ÔØ�d—l‘lÑ"Ø—l‘l×(Ñ(¨Ó-‘ä�à�T—Z‘ZÒØ×Ñ×#Ñ# S¨' NÔ3ð ô &Ð%r   c                 óˆ   — t        | «      }|j                  D �cg c]  }|j                  |«      sŒ|‘Œ c}|_        |S c c}w )z…Returns a new instance of the :class:`Dataset`, excluding any rows
        that do not contain the given :ref:`tags <tags>`.
        )r   ra   rS   )r   rR   Ú_dsetr   s       r   ÚfilterzDataset.filter}  s9   € ô �T“
ˆØ&+§k¡kÖF˜s°S·[±[ÀÕ5E’sÒFˆŒàˆùò Gs   š?±?c                 ó’  — t        |t        «      r‹| j                  st        ‚t	        | j
                  t        |«      |¬«      }t        | j                  | j                  ¬«      }|D ]0  }| j                  D �cg c]  }||   ‘Œ	 }}|j                  |¬«       Œ2 |S | j                  r| j                  |   }t	        | j
                  t        |«      |¬«      }t        | j                  | j                  ¬«      }|D ]?  }| j                  r| j                  D �cg c]  }||   ‘Œ	 }}n|}|j                  |¬«       ŒA |S c c}w c c}w )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.
        )rl   Úreverse)r_   r`   ©r   )
rN   rO   r_   r   Úsortedrž   r   r[   r`   rD   )r   r!   rö   Ú_sortedró   rH   rl   r   s           r   ÚsortzDataset.sort†  s  € ô �cœ3Ôà—<’<Ü#Ð#ä˜TŸY™Y¬J°s«OÀWÔMˆGÜ D§L¡L¸¿
¹
ÔCˆEàò &�Ø,0¯L©LÖ9 S�t˜C“yÐ9�Ð9Ø—‘ �Õ%ð&ð$ ˆð �|Š|Ø—l‘l 3Ñ'�ä˜TŸY™Y¬J°s«OÀWÔMˆGÜ D§L¡L¸¿
¹
ÔCˆEàò &�Ø—<’<Ø04·±Ö=¨˜4 ›9Ð=�CÑ=à�CØ—‘ �Õ%ð&ð ˆùò# :ùò >s   Á8D?ÄEc                 ó8  — | syt        «       }| j                  d   g| | j                  d      z   }||_        t        | j                  «      D ]J  \  }}|| j                  d   k(  rŒ|g| j                  |«      z   }t	        |«      }|j                  |¬«       ŒL |S )zÀTranspose 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.Nr   r÷   )r[   r_   rs   rî   r   rD   )r   ró   Únew_headersrF   ÚcolumnÚrow_datas         r   Ú	transposezDataset.transpose«  s    € ñ Øä“	ˆð —|‘| A‘Ð'¨$¨t¯|©|¸A©Ñ*?Ñ?ˆà#ˆŒÜ& t§|¡|Ó4ò 
	'‰MˆE�6à˜Ÿ™ a™Ò(àð �x $§,¡,¨uÓ"5Ñ5ˆHÜ˜8“}ˆHØ�L‰L˜XˆLÕ&ð
	'ð ˆr   c                 ó$  — t        |t        «      sy| j                  |j                  k7  rt        ‚t	        | «      }|j
                  D �cg c]  }|‘Œ }}|j
                  D �cg c]  }|‘Œ }}|j                  |«       ||_        |S c c}w c c}w )zˆStack two :class:`Dataset` instances together by
        joining at the row level, and return new combined
        ``Dataset`` instance.N)rN   r[   r˜   r	   r   ra   r„   )r   Úotherró   r   Úrows_to_stackÚ
other_rowss         r   ÚstackzDataset.stackÇ  s‚   € ô
 ˜%¤Ô)Øà�:‰:˜Ÿ™Ò$Ü#Ð#ô �T“
ˆà(-¯©Ö4 šÐ4ˆÐ4Ø%*§[¡[Ö1˜c’cÐ1ˆ
Ð1à×Ñ˜ZÔ(Ø#ˆŒàˆùò 5ùÚ1s   Á
	BÁ#	Bc                 óâ  — t        |t        «      sy| j                  s|j                  r| j                  r|j                  st        ‚| j                  |j                  k7  rt
        ‚	 | j                  |j                  z   }t        «       }| j                  D ]  }|j                  | |   ¬«       Œ |j                  D ]  }|j                  ||   ¬«       Œ ||_        |S # t        $ r d}Y Œlw xY w)zÙStack 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Þ   )rN   r[   r_   r   ri   r	   r­   rì   )r   r  rü   ró   rý   s        r   Ú
stack_colszDataset.stack_colsÝ  sÝ   € ô ˜%¤Ô)Øà�<Š<˜5Ÿ=š=Ø—<’< u§}¢}Ü#Ð#à�;‰;˜%Ÿ,™,Ò&Ü#Ð#ð	ØŸ,™,¨¯©Ñ6ˆKô “	ˆà—l‘lò 	/ˆFØ×Ñ  f¡ÐÕ.ð	/ð —m‘mò 	0ˆFØ×Ñ  v¡ÐÕ/ð	0ð $ˆŒàˆøô ò 	ØŠKð	ús   Á(C  Ã C.Ã-C.c                 óÂ   — t        «       }| j                  D �cg c]-  }t        |«      |v rŒ|j                  t        |«      «      rŒ,|‘Œ/ c}| j                  dd yc c}w )ziRemoves all duplicate rows from the :class:`Dataset` object
        while maintaining the original order.N)rQ   ra   rK   Úadd)r   Úseenr   s      r   Úremove_duplicateszDataset.remove_duplicatesþ  sL   € ô ‹uˆàŸ:™:ö
Ø¬e°C«j¸DÒ.@ÀDÇHÁHÌUÐSVËZÕDXŠCò
ˆ�
‰
‘1‰ùò 
s   ™A¬AÁAc                 ó0   — t        «       | _        d| _        y)zARemoves all content and headers from the :class:`Dataset` object.N)r   ra   rb   r$   s    r   r³   zDataset.wipe  s   € ä“VˆŒ
Øˆ�r   c                 ó€  — | sy|€t        t        | j                  «      «      }|€t        | j                  «      }|D �cg c]  }|t        | j                  «      v sŒ|‘Œ }}|D �cg c]  }|| j                  v sŒ|‘Œ }}t	        «       }t        |«      |_        g |_        t        | j
                  «      D ]{  \  }}g }|j                  D ]E  }|| j                  v r0| j                  j                  |«      }	|j                  ||	   «       ŒAt        ‚ ||v sŒa|j                  t        |«      ¬«       Œ} |S c c}w c c}w )zkReturns a new instance of the :class:`Dataset`,
        including only specified rows and columns.
        Nr÷   )r   Úrangeri   r_   r[   ra   rs   rF   rD   rk   r   )
r   rÓ   Úcolsr   r¾   ró   Úrow_nor§   rl   rm   s
             r   ÚsubsetzDataset.subset  s'  € ñ Øàˆ<Üœ˜dŸk™kÓ*Ó+ˆDàˆ<Ü˜Ÿ™Ó%ˆDð  $ÖA˜ s¬e°D·K±KÓ.@Ò'@’ÐAˆÐAØ%)ÖD˜6¨V°t·|±|Ò-C’ÐDˆÐDä“	ˆô ˜T›
ˆŒàˆŒÜ$ T§Z¡ZÓ0ò 
	0‰KˆF�CØˆHØ—}‘}ò #�Ø˜$Ÿ,™,Ñ&ØŸ,™,×,Ñ,¨SÓ1�CØ—O‘O C¨¡HÕ-ä"�Nð#ð ˜Š~Ø—‘¤ X£�Õ/ð
	0ð ˆùò+ BùÚDs   ¿D6ÁD6Á&D;Á:D;)NNF)TTr   )r   )NN)r}   )F)3rT   rU   rV   rW   r   r(   r/   r2   r4   r+   rŒ   r‘   r•   rq   r©   r«   r¯   rY   r_   r±   r¸   rž   r¿   ri   r˜   rÈ   rÌ   r<   r>   rA   rD   r„   r×   rÛ   r»   rß   râ   rä   rè   rê   rì   rî   rñ   rô   rú   rÿ   r  r  r
  r³   r  r   r   r   r[   r[   e   s&  „ ñ,ò\)òò=ò%ò ò"&òGò2GòRóó& òDò	"ñ �| \Ó2€Gòò%3ñN �I˜yÓ)€Dòð" ñó ðð ñó ðóò,
.ó 
6ó5ó+óó#òòòó95óv8ó/ó%ó	+ó$ò2òò.ó#òJò8ò,òB
òô
%r   r[   c                   óT   — e Zd ZdZdd„Zd„ Zd„ Zd„ Zd„ Zdd„Z	e
d	„ «       Zd
„ Zd„ Zy)ÚDatabookz(A book of :class:`Dataset` objects.
    Nc                 ó   — |xs g | _         y r   ©Ú	_datasets)r   Úsetss     r   r   zDatabook.__init__7  s   € Øš ˆ�r   c                 ó\   — 	 d| j                   j                  «       z  S # t        $ r Y yw xY w)Nz<%s databook>z<databook object>ru   r$   s    r   r+   zDatabook.__repr__:  s1   € ð	'Ø" d§j¡j×&6Ñ&6Ó&8Ñ9Ð9øÜò 	'Ù&ð	'úrx   c                 ó   — g | _         y)z@Removes all :class:`Dataset` objects from the :class:`Databook`.Nr  r$   s    r   r³   zDatabook.wipe@  s	   € àˆ�r   c                 ó   — | j                   S r   r  r$   s    r   ÚsheetszDatabook.sheetsD  s   € Ø�~‰~Ðr   c                 óf   — t        |t        «      r| j                  j                  |«       yt        ‚)z5Adds given :class:`Dataset` to the :class:`Databook`.N)rN   r[   r  rD   r   )r   Údatasets     r   Ú	add_sheetzDatabook.add_sheetG  s$   € ä�gœwÔ'Ø�N‰N×!Ñ! 'Õ*ä$Ð$r   c           	      ó°   — g }|rt         }nt        }| j                  D ]5  }|j                   ||j                  |j                  |¬«      ¬«      «       Œ7 |S )z(Packages :class:`Databook` for delivery.)r¡   )r`   r¨   )r   rž   r  rD   r`   r©   )r   r¡   Ú	collectorr¢   Údsets        r   r©   zDatabook._packageN  sY   € àˆ	áÜ#‰IäˆIà—N‘Nò 	ˆDØ×Ñ™YØ—j‘jØ—]‘]¨7�]Ó3ôõ ð	ð
 Ðr   c                 ó,   — t        | j                  «      S )zDThe number of the :class:`Dataset` objects within :class:`Databook`.)r'   r  r$   s    r   ÚsizezDatabook.size^  s   € ô �4—>‘>Ó"Ð"r   c                 ó¾   — t        |«      }|st        |«      }t        j                  |«      }t	        |d«      st        d|› d�«      ‚ |j                  | |fi |¤Ž | S )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Å   s         r   rÈ   zDatabook.loadc  sd   € ô ! Ó+ˆÙÜ" 6Ó*ˆFä×!Ñ! &Ó)ˆÜ�s˜MÔ*Ü# g¨f¨XÐ5GÐ$HÓIÐIàˆ�‰˜˜fÑ/¨Ò/Øˆr   c                 óˆ   — t        j                  |«      }t        |d«      st        d|› d�«      ‚ |j                  | fi |¤ŽS )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Ë   s       r   rÌ   zDatabook.exportv  sI   € ô ×!Ñ! &Ó)ˆÜ�s˜MÔ*Ü# g¨f¨XÐ5IÐ$JÓKÐKàˆs�‰˜tÑ. vÑ.Ð.r   r   )T)rT   rU   rV   rW   r   r+   r³   r  r  r©   rY   r"  rÈ   rÌ   r   r   r   r  r  3  sC   „ ñó$ò'òòò%óð  ñ#ó ð#òó&
/r   r  c                 ór  — t        | «      } d}t        j                  «       D ]`  }	 |j                  | «      r-|j                  }	 t        | d«      r| j                  d«        |S 	 t        | d«      sŒP| j                  d«       Œb |S # t        $ r Y Œ-w xY w# t        | d«      r| j                  d«       w w xY w)zMReturn format name of given stream (file-like object, string, or bytestring).NÚseekr   )r   r   ÚformatsÚdetectr`   r¼   r(  rw   )rÆ   Ú	fmt_titlerÇ   s      r   rÄ   rÄ   ƒ  s¹   € ä˜VÓ$€FØ€IÜ×ÑÓ!ò 	ˆð	Ø�z‰z˜&Ô!ØŸI™I�	Øô �v˜vÔ&Ø—‘˜A”øØÐð "ô �v˜vÕ&Ø—‘˜A•ð	ð Ðøô ò 	Ùð	ûô �v˜vÔ&Ø—‘˜A•ð 'ús)   ¦BÁ$BÂ	BÂBÂBÂBÂ B6Nc                 óL   —  t        «       j                  t        | «      |fi |¤ŽS ©zIReturn dataset of given stream (file-like object, string, or bytestring).)r[   rÈ   r   ©rÆ   r‚   rg   s      r   r“   r“   ”  s#   € ð Œ7‹9�>‰>œ/¨&Ó1°6ÑD¸VÑDÐDr   c                 óL   —  t        «       j                  t        | «      |fi |¤ŽS r-  )r  rÈ   r   r.  s      r   r$  r$  š  s#   € ð Œ8‹:�?‰?œ?¨6Ó2°FÑE¸fÑEÐEr   r   )rW   Úcollectionsr   r   Úoperatorr   Útablib.exceptionsr   r   r   r	   r
   Útablib.formatsr   Útablib.utilsr   Ú	__title__Ú
__author__Ú__license__Ú__copyright__Ú__docformat__r   r[   r  rÄ   r“   r$  Úregister_builtinsr   r   r   ú<module>r;     sˆ   ðñõ $Ý Ý ÷õ õ $Ý (à€	Ø€
Ø€Ø>€Ø"€÷B8ñ B8÷JKñ K÷\M/ñ M/ò`ó"EóFð €× Ñ Õ r   