관리-도구
편집 파일: csv.cpython-311.opt-1.pyc
� ���P�t*��w��������������������������d�Z�ddlZddlmZmZmZmZmZmZm Z m Z mZmZm Z mZmZm�Z��ddlmZ�ddlmZ�g�d�Z�G�d��d������������Z�G�d ��d e������������Z�ed e��������������G�d��de������������Z�ed e��������������G�d��de������������Z�ede��������������G�d��d������������Z�G�d��d������������Z �e�n #�e$�r�eZY�nw�xY�w�G�d��d������������ZdS�)z+ csv.py - read/write/investigate CSV files �����N)�Error�__version__�writer�reader�register_dialect�unregister_dialect�get_dialect� list_dialects�field_size_limit� QUOTE_MINIMAL� QUOTE_ALL�QUOTE_NONNUMERIC� QUOTE_NONE�__doc__)�Dialect)�StringIO)r���r ���r���r���r���r���r����excel� excel_tabr���r���r���r���r ���r ����Snifferr���r���� DictReader� DictWriter�unix_dialectc��������������������B�����e�Zd�ZdZdZdZdZdZdZdZ dZ dZdZd��Z d��ZdS�)r���z�Describe a CSV dialect. This must be subclassed (see csv.excel). Valid attributes are: delimiter, quotechar, escapechar, doublequote, skipinitialspace, lineterminator, quoting. ��FNc������������������\�����|�j���������t����������k����rd|�_��������|�������������������������������������d�S�)NT)� __class__r����_valid� _validate��selfs��� �*/opt/alt/python311/lib64/python3.11/csv.py�__init__zDialect.__init__*���s,�������>�W�$�$��D�K�������������c����������������������� �t����������|��������������d�S�#�t����������$�r!}t����������t����������|�������������������������d�}~ww�xY�w�N)�_Dialect� TypeErrorr����str)r ����es��� r!���r���zDialect._validate/���sG������ ��T�N�N�N�N�N���� �� �� ���A���-�-������ ���s������ >�9�>)�__name__� __module__�__qualname__r����_namer���� delimiter� quotechar� escapechar�doublequote�skipinitialspace�lineterminator�quotingr"���r�����r#���r!���r���r������sl������������������ �E� �F��I��I��J��K����N��G������ �� �� �� �� r#���r���c��������������������*�����e�Zd�ZdZdZdZdZdZdZe Z dS�)r���z;Describe the usual properties of Excel-generated CSV files.�,�"TF� N)r*���r+���r,���r���r.���r/���r1���r2���r3���r���r4���r5���r#���r!���r���r���6���s3��������������E�E��I��I��K����N��G�G�Gr#���r���c�������������������������e�Zd�ZdZdZdS�)r���zEDescribe the usual properties of Excel-generated TAB-delimited files.� N)r*���r+���r,���r���r.���r5���r#���r!���r���r���@���s��������������O�O��I�I�Ir#���r���z excel-tabc��������������������*�����e�Zd�ZdZdZdZdZdZdZe Z dS�)r���z:Describe the usual properties of Unix-generated CSV files.r7���r8���TF� N)r*���r+���r,���r���r.���r/���r1���r2���r3���r ���r4���r5���r#���r!���r���r���E���s3��������������D�D��I��I��K����N��G�G�Gr#���r����unixc��������������������\�����e�Zd�Z � �dd�Zd��Zed����������������Zej��������d����������������Zd��ZdS�) r���Nr���c������������������x�����||�_���������||�_��������||�_��������t����������||g|�R�i�|��|�_��������||�_��������d|�_��������d�S��Nr���)�_fieldnames�restkey�restvalr����dialect�line_num)r ����f� fieldnamesrC���rD���rE����args�kwdss��� r!���r"���zDictReader.__init__Q���sK������%����������Q��7�$�7�7�7�$�7�7�������� � � r#���c�����������������������|�S�r%���r5���r���s��� r!����__iter__zDictReader.__iter__Z���s�������r#���c�����������������������|�j����������+ �t����������|�j��������������������|�_���������n#�t����������$�r�Y�nw�xY�w|�j��������j��������|�_��������|�j���������S�r%���)rB����nextr���� StopIterationrF���r���s��� r!���rH���zDictReader.fieldnames]���sZ��������#� �#'���#4�#4�� � �� �� �� �� ��� ������,�� ���s����#�� 0�0c�����������������������||�_���������d�S�r%���)rB���)r ����values��� r!���rH���zDictReader.fieldnamesg���s������ ����r#���c����������������������|�j���������dk����r|�j���������t����������|�j��������������������}|�j��������j���������|�_���������|g�k����rt����������|�j��������������������}|g�k�����t ����������t����������|�j��������|������������������������}t ����������|�j��������������������}t ����������|������������}||k�����r||d�����������||�j��������<���n"||k����r|�j��������|d�����������D�]}|�j��������||<���� |S�rA���) rF���rH���rN���r����dict�zip�lenrC���rD���)r ����row�d�lf�lr�keys��� r!����__next__zDictReader.__next__k���s��������=�A����O�O��4�;������,�� � ��R�i�i��t�{�#�#�C���R�i�i���T�_�c�*�*�+�+�� ��� !� !�� ��X�X�� ��7�7�!�"�#�#�h�A�d�l�O�O� �"�W�W���r�s�s�+�� &�� &�����#����r#���)NNNr���) r*���r+���r,���r"���rL����propertyrH����setterr[���r5���r#���r!���r���r���P���s���������������AE� ��������������� �� ���X� ����!��!����!���������r#���r���c��������������������2�����e�Zd�Z � �d d�Zd��Zd��Zd��Zd��Zd S�)r���r����raiser���c�����������������������||�_���������||�_��������|�����������������������������������dvrt����������d|z���������������||�_��������t����������||g|�R�i�|��|�_��������d�S�)N)r_����ignorez-extrasaction (%s) must be 'raise' or 'ignore')rH���rD����lower� ValueError�extrasactionr���)r ���rG���rH���rD���rd���rE���rI���rJ���s��� r!���r"���zDictWriter.__init__����sr������$�����������':�:�:��L�+�,��-��-�� -�(����Q��7�$�7�7�7�$�7�7����r#���c������������������z�����t����������t����������|�j��������|�j��������������������������������}|����������������������|������������S�r%���)rS���rT���rH����writerow)r ����headers��� r!����writeheaderzDictWriter.writeheader����s/�������c�$�/�4�?�;�;�<�<���}�}�V�$�$�$r#���c�����������������������������j���������dk����rM��������������������������������������j��������z ��}|r/t����������dd���������������������d��|D���������������������������z�������������������fd���j��������D���������������S�)Nr_���z(dict contains fields not in fieldnames: z, c������������������,�����g�|�]}t����������|��������������S�r5���)�repr)�.0�xs��� r!���� <listcomp>z,DictWriter._dict_to_list.<locals>.<listcomp>����s������-L�-L�-L�!�d�1�g�g�-L�-L�-Lr#���c��������������3����N����K����|�]}�����������������������|�j��������������������V���� d�S�r%���)�getrD���)rl���rZ����rowdictr ���s��� ��r!���� <genexpr>z+DictWriter._dict_to_list.<locals>.<genexpr>����s3�����������J�J�3����C���.�.�J�J�J�J�J�Jr#���)rd����keysrH���rc����join)r ���rq����wrong_fieldss���`` r!���� _dict_to_listzDictWriter._dict_to_list����s������������'�'�"�<�<�>�>�D�O�;�L��� O� �!K�#'�9�9�-L�-L�|�-L�-L�-L�#M�#M�"N��O��O��O�J�J�J�J�J�$�/�J�J�J�Jr#���c������������������\�����|�j������������������������������|����������������������|������������������������S�r%���)r���rf���rv���)r ���rq���s��� r!���rf���zDictWriter.writerow����s&�������{�#�#�D�$6�$6�w�$?�$?�@�@�@r#���c������������������\�����|�j������������������������������t����������|�j��������|������������������������S�r%���)r���� writerows�maprv���)r ����rowdictss��� r!���ry���zDictWriter.writerows����s%�������{�$�$�S��);�X�%F�%F�G�G�Gr#���N)r���r_���r���)r*���r+���r,���r"���rh���rv���rf���ry���r5���r#���r!���r���r�������su��������������?F� �8��8��8��8�%��%��%�K��K��K�A��A��A�H��H��H��H��Hr#���r���c��������������������2�����e�Zd�ZdZd��Zdd�Zd��Zd��Zd��ZdS�) r���ze "Sniffs" the format of a CSV file (i.e. delimiter, quotechar) Returns a Dialect object. c�����������������������g�d�|�_���������d�S�)N)r7���r;����;� �:)� preferredr���s��� r!���r"���zSniffer.__init__����s������3�3�3����r#���Nc�����������������������|�����������������������||������������\��}}}}|s|����������������������||������������\��}}|st����������d��������������G�d��dt����������������������}||_��������||_��������|pd|_��������||_��������|S�)zI Returns a dialect (or None) corresponding to the sample zCould not determine delimiterc�������������������������e�Zd�ZdZdZeZdS�)�Sniffer.sniff.<locals>.dialect�sniffedr9���N)r*���r+���r,���r-���r3���r���r4���r5���r#���r!���rE���r��������s���������������E�#�N�#�G�G�Gr#���rE���r8���)�_guess_quote_and_delimiter�_guess_delimiterr���r���r1���r.���r/���r2���)r ����sample� delimitersr/���r1���r.���r2���rE���s��� r!����sniffz Sniffer.sniff����s���������2�2�6�:�F�F�� <� �;� �+;��� L�*.�*?�*?��@J�+L��+L�'�I�'���� 9��7�8�8�8� $�� $�� $�� $�� $�g�� $�� $�� $��*���%���%�,����#3�� ��r#���c������������������J����g�}dD�]G}t����������j��������|t�����������j��������t�����������j��������z��������������}|���������������������|������������}|r�n�H|sdS�i�}i�}d}|j��������} |D�]�} | d���������dz ��}| |���������}|r|���������������������|d������������dz���||<��� �| d���������dz ��}| |���������}n#�t����������$�r�Y��Tw�xY�w|r"|�||v�r|���������������������|d������������dz���||<��� �| d���������dz ��}n#�t����������$�r�Y���w�xY�w| |���������r|dz ��}��t����������||j��������� ������������} |r+t����������||j��������� ������������}||���������|k����}|d k����rd}nd}d}t����������j��������dt����������j ��������|������������| d �z��t�����������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. )zI(?P<delim>[^\w\n"\'])(?P<space> ?)(?P<quote>["\']).*?(?P=quote)(?P=delim)zG(?:^|\n)(?P<quote>["\']).*?(?P=quote)(?P<delim>[^\w\n"\'])(?P<space> ?)zG(?P<delim>[^\w\n"\'])(?P<space> ?)(?P<quote>["\']).*?(?P=quote)(?:$|\n)z-(?:^|\n)(?P<quote>["\']).*?(?P=quote)(?:$|\n))r���FNr���r����quote�����delimN�space�rZ���r=���r���z]((%(delim)s)|^)\W*%(quote)s[^%(delim)s\n]*%(quote)s[^%(delim)s\n]*%(quote)s\W*((%(delim)s)|$))r����r����TF)�re�compile�DOTALL� MULTILINE�findall� groupindexrp����KeyError�max�escape�search)r ����datar�����matches�restr�regexp�quotes�delims�spacesr�����m�nrZ���r/���r����r2���� dq_regexpr1���s��� r!���r����z"Sniffer._guess_quote_and_delimiter����sQ��������H�� �� �E���Z��r�y�2�<�'?�@�@�F��n�n�T�*�*�G��� ��� ���� (�'�'��������&� ��� �� �A��7�#�a�'�A��A�$�C��� 5�$�j�j��a�0�0�1�4��s�� ��w�'�!�+����d������ �� �� ��� ������ 5� �*�c�Z�.?�.?�$�j�j��a�0�0�1�4��s�� ��w�'�!�+������ �� �� ��� ������t�� ��!������F�J�/�/�/� ��� !���F�J�/�/�/�E�%�e�}��6����}�}������E� ����J��(*� �%�(8�(8�)�L�L� M�NP�l�\��\� �����D�!�!�� ��K�K��K��;��/?�@�@s$����B(�( B5�4B5�C)�) C6�5C6c������������������.����t����������t����������d|���������������������d������������������������������������}d��t����������d������������D���������������}t ����������dt����������|������������������������}d}i�}i�}i�}d|} } | t����������|������������k������r�|dz ��}|| | ����������D�]S}|D�]N}|���������������������|i�������������} |���������������������|������������}| ���������������������|d������������dz���| |<���| ||<����O�T|�����������������������������������D�]�}t����������||���������� ����������������������������������������������}t����������|������������dk����r|d���������d���������dk����r�Ot����������|������������dk����rjt����������|d��� ������������||<���|���������������������||����������������������||���������d���������||���������d���������t����������d ��|D���������������������������z ��f||<�����|d���������||<�����|� ����������������������������������}t����������t ����������||z��t����������|������������������������������������}d}d}t����������|������������dk����r^||k����rX|D�]7\��}}|d���������dk����r&|d���������dk����r|d���������|z��|k����r|�||v�r|||<����8|d z��}t����������|������������dk����r||k�����Xt����������|������������dk����rft����������|�����������������������������������������������d���������}|d������������������������������|������������|d������������������������������d|z��������������k����}||fS�| } | |z ��} | t����������|������������k��������|sdS�t����������|������������dk����ra|�j��������D�]Y}||�����������������������������������v�rA|d������������������������������|������������|d������������������������������d|z��������������k����}||fc�S��Zd��|� ����������������������������������D���������������}|������������������������������������|d���������d���������}|d������������������������������|������������|d������������������������������d|z��������������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. Nr=���c������������������,�����g�|�]}t����������|��������������S�r5���)�chr)rl����cs��� r!���rn���z,Sniffer._guess_delimiter.<locals>.<listcomp>-��s������,�,�,�A��Q���,�,�,r#�������� ���r���r����c�����������������������|�d���������S�)Nr����r5���)rm���s��� r!����<lambda>z*Sniffer._guess_delimiter.<locals>.<lambda>G��s ������1�Q�4��r#���r����c��������������3����&���K����|�]}|d����������V���� dS�)r����Nr5���)rl����items��� r!���rr���z+Sniffer._guess_delimiter.<locals>.<genexpr>L��s&����������(C�(C�T��a��(C�(C�(C�(C�(C�(Cr#���g�������?g�������?g{�G�z�?z%c )r���r���c�����������������������g�|�] \��}}||f�� S�r5���r5���)rl����k�vs��� r!���rn���z,Sniffer._guess_delimiter.<locals>.<listcomp>v��s ������3�3�3�5�A�a�!�A��3�3�3r#������)�list�filter�split�range�minrU���rp����countrs����itemsr�����remove�sum�floatr�����sort)r ���r����r�����ascii�chunkLength� iteration� charFrequency�modesr�����start�end�line�char� metaFrequency�freqr�����modeList�total�consistency� thresholdr����r����r����r2���rW���s��� r!���r����zSniffer._guess_delimiter��sf�����&��F�4����D�!1�!1�2�2�3�3��,�,��s���,�,�,����"�c�$�i�i�(�(��� �� �������s���c�$�i�i�����N�I��U�3�Y��� 8�� 8��!��8��8�D�$1�$5�$5�d�B�$?�$?�M��:�:�d�+�+�D�*7�*;�*;�D�!�*D�*D�q�*H�M�$�'�*7�M�$�'�'� 8��&�*�*�,�,�� +�� +���]�4�0�6�6�8�8�9�9���u�:�:��?�?�u�Q�x��{�a�'7�'7���u�:�:��>�>�"%�e���"@�"@�"@�E�$�K���L�L��t��-�-�-�#(��;�q�>�5��;�q�>�%(�(C�(C�U�(C�(C�(C�%C�%C�4D��#E�E�$�K�K��#(��(�E�$�K�K���{�{�}�}�H��#�k�I�5�s�4�y�y�A�A�B�B�E��K��I��f�+�+��"�"�{�i�'?�'?�$��*��*�D�A�q���t�a�x�x�A�a�D�1�H�H��q�T�%�Z�K�7�7�'�/�1� �?�?�()�F�1�I���t�#�� ��f�+�+��"�"�{�i�'?�'?���6�{�{�a����V�[�[�]�]�+�+�A�.��$(��G�M�M�%�$8�$8�$(��G�M�M�%�%�-�$@�$@�%A� ��/�0�0���E��;��C�c��c�$�i�i���f��� ��7���v�;�;��?�?��^�� 1�� 1������ � �%�%�(,�Q�� � �a�(8�(8�(,�Q�� � �e�a�i�(@�(@�)A�$��/�0�0�0�0��&��4�3�F�L�L�N�N�3�3�3�� � � �����b� �!��� ��G�M�M�%�0�0� ��G�M�M�%�%�-�8�8�9���'�(�(r#���c������������������b����t����������t����������|������������|����������������������|������������������������}t����������|������������}t ����������|������������}i�}t����������|������������D�]}d�||<����d}|D�]�}|dk����r�n�|dz ��}t ����������|������������|k����r�#t ����������|�����������������������������������������������D�]e} t����������} ��| || ����������������������n,#�t����������t����������f$�r�t ����������|| ���������������������} Y�nw�xY�w| || ���������k����r|| ����������| || <����b|| =��f��d}|�����������������������������������D�]}\��} }t����������|������������t����������d������������k����r%t ����������|| ���������������������|k����r|dz ��}�D|dz��}�J ��||| ����������������������|dz��}�b#�t����������t����������f$�r�|dz ��}Y��zw�xY�w|dk����S�)Nr�������r����)r���r���r����rN���rU���r����r����rs����complexrc���� OverflowErrorr�����typer'���) r ���r�����rdrrg����columns�columnTypes�i�checkedrV����col�thisType� hasHeader�colTypes ��� r!���� has_headerzSniffer.has_header��s�������X�f�%�%�t�z�z�&�'9�'9�:�:���c�����f�+�+�����w���6�6�A�$��Q������� -�� -�C���|�|����q�L�G��3�x�x�7�"�"���K�,�,�.�.�/�/�� -�� -��"��-��H�S��X�&�&�&�&��"�M�2��-��-��-�"�3�s�8�}�}�H�H�H�-������{�3�/�/�/�"�3�'�/�+3��C�(�(��(��,�� -�$�� �'�-�-�/�/�� #�� #�L�C���G�}�}��Q���'�'��v�c�{�#�#�w�.�.���N�I�I���N�I�I�#��G�F�3�K�(�(�(����N�I�I���#�I�.��#��#��#���N�I�I�I�#���� ��1�}�s$����:C�&C5�4C5�8F�F(�'F(r%���) r*���r+���r,���r���r"���r����r����r����r����r5���r#���r!���r���r�������sy�����������������4��4��4� �������:IA��IA��IA�Xd)��d)��d)�N=��=��=��=��=r#���r���)r���r�����_csvr���r���r���r���r���r���r ���r ���r���r���r ���r���r���r���r&����ior����__all__r���r���r���r���r���r����� NameErrorr����r���r5���r#���r!����<module>r�������s��������� � � � ���������������������������������������������������������������� �%��$��$��$��$��$������������������� �� �� �� �� �� �� �� �>���������G������������%�� �� �� ����������������������i��(��(��(����������7��������������&��&��&�/��/��/��/��/��/��/��/�dH��H��H��H��H��H��H��H�<��G�G����������G�G�G�����W��W��W��W��W��W��W��W��W��Ws����-B0��0B:�9B: