�&ǐk�@'bJ�h�ۊL'}T� :��'2�Z#$��n�a��� �>a��`��_3d�Qpt�/�P -��#5�,�M��� �pA:©�q�����NW��ډ�A���� �9nʺج���� �TSM��{J6?7��r�@�\����D��� �׶���s�f�TJj?"��D��`?��̒� b�#�%�C*v�$�{�$����5Ծ�F�s��y�e/8��h-�f�̰&(����Gj�L:U� 2�� ����v�_k����Y��gp,�k�WF�R������_C�R��N@���R�@�ߔ?A�w9���F("iNa-S���Q�o�3tDMLh*�#4k�T/iQ��Y*�G��m����)��8�hBm/�I�,g�ﯖ���Z��}�Cz�q@´��d.����L�ŕ�,��1�Z�܌�: ̪���F+J-'��c�tvJ8��]Q-��b��y �6;*J`r_�d ��'�G ~p��)'�C,�%F��E(��2�k�����lР�z�!�=t ��_�0��f7��� ;�p�|�U �%sz,DictWriter._dict_to_list..c3s|]}j|jVqdS)N)getr5)rRrD)rowdictrrr sz+DictWriter._dict_to_list..)rLkeysr9rKjoin)rrVZ wrong_fieldsr)rVrr _dict_to_lists  zDictWriter._dict_to_listcCs|jj|j|S)N)rrNrZ)rrVrrrrNszDictWriter.writerowcCs|jjt|j|S)N)r writerowsmaprZ)rZrowdictsrrrr[szDictWriter.writerowsN)rrHr)r%r&r'r rPrZrNr[rrrrrs  c@s:eZdZdZddZd ddZddZd d Zd d ZdS)rze "Sniffs" the format of a CSV file (i.e. delimiter, quotechar) Returns a Dialect object. cCsdddddg|_dS)Nr/r1; :) preferred)rrrrr szSniffer.__init__NcCsd|j||\}}}}|s(|j||\}}|s4tdGdddt}||_||_|pVd|_||_|S)zI Returns a dialect (or None) corresponding to the sample zCould not determine delimiterc@seZdZdZdZeZdS)zSniffer.sniff..dialectZsniffedz N)r%r&r'r(r-r r.rrrrr6sr6r0)_guess_quote_and_delimiter_guess_delimiterrrr+r)r*r,)rsample delimitersr*r+r)r,r6rrrsniffs  z Sniffer.sniffcCsg}x0dD](}tj|tjtjB}|j|}|r Pq W|s>dSi}i}d}|j} x|D]} | d d } | | } | r|j| dd || <y| d d } | | } Wntk rwVYnX| r|dks| |kr|j| dd || <y| d d } Wntk rwVYnX| | rV|d 7}qVWt||jd } |rZt||jd }|||k}|dkrbd}nd}d}tjdtj || dtj}|j |rd}nd}| |||fS)a Looks for text enclosed between two identical quotes (the probable quotechar) which are preceded and followed by the same character (the probable delimiter). For example: ,'some text', The quote with the most wins, same with the delimiter. If there is no quotechar the delimiter can't be determined this way. I(?P[^\w\n"\'])(?P ?)(?P["\']).*?(?P=quote)(?P=delim)G(?:^|\n)(?P["\']).*?(?P=quote)(?P[^\w\n"\'])(?P ?)G(?P[^\w\n"\'])(?P ?)(?P["\']).*?(?P=quote)(?:$|\n)-(?:^|\n)(?P["\']).*?(?P=quote)(?:$|\n)rFNrquotedelimZspace)rDr2z]((%(delim)s)|^)\W*%(quote)s[^%(delim)s\n]*%(quote)s[^%(delim)s\n]*%(quote)s\W*((%(delim)s)|$))rlrjT)rfrgrhri)rFNr) recompileDOTALL MULTILINEfindall groupindexrUKeyErrormaxescapesearch)rdatardZmatchesZrestrZregexpZquotesdelimsZspacesrrmnrDr*rlr,Z dq_regexpr+rrrras`          z"Sniffer._guess_quote_and_delimitercCsttd|jd}ddtdD}tdt|}d}i}i}i}dt|t|} } x| t|krn|d7}xT|| | D]D} x>|D]6} |j| i} | j| }| j|dd| |<| || <qWqWx|jD]} t|| j }t|dkr|dddkrqt|dkrht |d d d || <|j || || d|| dt d d |Df|| <q|d|| <qW|j }t ||}d}d}xt|dkr||krx\|D]T\}}|ddkr|ddkr|d||kr|dks||kr|||<qW|d8}qWt|dkr`t|jd}|dj||djd|k}||fS| } | |7} q\W|szdSt|dkrxF|jD]<}||jkr|dj||djd|k}||fSqWdd|j D}|j|dd}|dj||djd|k}||fS)a The delimiter /should/ occur the same number of times on each row. However, due to malformed data, it may not. We don't want an all or nothing approach, so we allow for small variations in this number. 1) build a table of the frequency of each character on every line. 2) build a table of frequencies of this frequency (meta-frequency?), e.g. 'x occurred 5 times in 10 rows, 6 times in 1000 rows, 7 times in 2 rows' 3) use the mode of the meta-frequency to determine the /expected/ frequency for that character 4) find out how often the character actually meets that goal 5) the character that best meets its goal is the delimiter For performance reasons, the data is evaluated in chunks, so it can try and evaluate the smallest portion of the data possible, evaluating additional chunks as necessary. Nr2cSsg|] }t|qSr)chr)rRcrrrrT.sz,Sniffer._guess_delimiter.. rrkcSs|dS)Nrkr)rSrrrHsz*Sniffer._guess_delimiter..)rDcss|]}|dVqdS)rkNr)rRitemrrrrWMsz+Sniffer._guess_delimiter..g?g?g{Gz?z%c rcSsg|]\}}||fqSrr)rRkvrrrrTws)rr)listfiltersplitrangeminrArUcountrXitemsrtremovesumfloatr`sort)rrwrdasciiZ chunkLengthZ iterationZ charFrequencyZmodesrxstartendlinecharZ metaFrequencyZfreqrZmodeListZtotalZ consistencyZ thresholdrrrlr,rCrrrrbst           zSniffer._guess_delimiterc Cstt||j|}t|}t|}i}xt|D] }d||<q2Wd}x|D]}|dkrZP|d7}t||krpqLxt|jD]x} xJtt t gD]0} y| || PWqt t fk rYqXqWt|| } | || kr~|| dkr| || <q~|| =q~WqLWd} x|j D]~\} } t| tdkrLt|| | krB| d7} n| d8} ns2@       2