�&ǐ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 �%rrrr s zDictWriter.__init__cCstt|j|j}||Sr!)rCrDr<writerow)rheaderrrr writeheaderszDictWriter.writeheadercsNjdkr8j}|r8tdddd|DfddjDS)NrLz(dict contains fields not in fieldnames: z, cSsg|] }t|qSr)repr).0xrrr sz,DictWriter._dict_to_list..c3s|]}|jVqdSr!)getr8)rUrHrowdictrrr sz+DictWriter._dict_to_list..)rPkeysr<rOjoin)rrZZ wrong_fieldsrrYr _dict_to_lists zDictWriter._dict_to_listcCs|j||Sr!)rrQr^)rrZrrrrQszDictWriter.writerowcCs|jt|j|Sr!)r writerowsmapr^)rZrowdictsrrrr_szDictWriter.writerowsN)rrLr)r&r'r(r rSr^rQr_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)Nr0r3; :) preferredrrrrr szSniffer.__init__NcCsd|||\}}}}|s(|||\}}|s4tdGdddt}||_||_|pVd|_||_|S)zI Returns a dialect (or None) corresponding to the sample zCould not determine delimiterc@seZdZdZdZeZdS)zSniffer.sniff..dialectZsniffedr2N)r&r'r(r)r.r r/rrrrr9sr9r1)_guess_quote_and_delimiter_guess_delimiterrrr,r*r+r-)rsample delimitersr+r,r*r-r9rrrsniffs  z Sniffer.sniffc Csg}dD]*}t|tjtjB}||}|rq4q|s[^\w\n"\'])(?P ?)(?P["\']).*?(?P=quote)(?P=delim)zG(?:^|\n)(?P["\']).*?(?P=quote)(?P[^\w\n"\'])(?P ?)zG(?P[^\w\n"\'])(?P ?)(?P["\']).*?(?P=quote)(?:$|\n)z-(?:^|\n)(?P["\']).*?(?P=quote)(?:$|\n))rFNrrquotedelimNZspacerHr4rz]((%(delim)s)|^)\W*%(quote)s[^%(delim)s\n]*%(quote)s[^%(delim)s\n]*%(quote)s\W*((%(delim)s)|$))rlrjTF) recompileDOTALL MULTILINEfindall groupindexrXKeyErrormaxescapesearch)rdatarhZmatchesZrestrZregexpZquotesdelimsZspacesrsmnrHr+rlr-Z dq_regexpr,rrrres`           z"Sniffer._guess_quote_and_delimitercCsttd|d}ddtdD}tdt|}d}i}i}i}d|} } | t|krR|d7}|| | D]@} |D]6} || i} | | }| |dd| |<| || <qxqp|D]} t||  }t|dkr|dddkrqt|dkrLt |d d d || <| || || d|| dt d d |Df|| <q|d|| <q| }t t||t|}d}d}t|dkr||kr|D]T\}}|ddkr|ddkr|d||kr|dks||kr|||<q|d8}qt|dkrDt|d}|d||dd|k}||fS| } | |7} qN|s\dSt|dkr|jD]@}||krp|d||dd|k}||fSqpdd| D}||dd}|d||dd|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. Nr4cSsg|] }t|qSr)chr)rUcrrrrW-sz,Sniffer._guess_delimiter.. rrkcSs|dS)Nrkr)rVrrrGz*Sniffer._guess_delimiter..rmcss|]}|dVqdS)rkNr)rUitemrrrr[Lsz+Sniffer._guess_delimiter..g?g?g{Gz?z%c )rrcSsg|]\}}||fqSrr)rUkvrrrrWvs)listfiltersplitrangeminrErXcountr\itemsruremovesumfloatrdsort)rrxrhasciiZ chunkLengthZ iterationZ charFrequencyZmodesrystartendlinecharZ metaFrequencyZfreqrZmodeListZtotalZ consistencyZ thresholdrrrlr-rGrrrrfs               zSniffer._guess_delimiterc Cstt|||}t|}t|}i}t|D] }d||<q0d}|D]}|dkrVq|d7}t||krlqFt|D]x} tt t fD]4} z| || WqWqt t fk rYqXqt|| } | || krx|| dkr| || <qx|| =qxqFd} | D]~\} } t| tdkr@t|| | kr6| d7} n| d8} nsJ@     2