OwlCyberSecurity - MANAGER
Edit File: csv.cpython-38.opt-1.pyc
U ����e5d?����������������������@���s@��d�Z�ddlZddlmZmZmZmZmZmZm Z m Z mZmZm Z mZmZm�Z��ddlmZ�ddlmZ�dddd d ddd dddddddddddddgZG�dd��d�ZG�dd ��d e�Zed e��G�dd��de�Zede��G�dd��de�Zed e��G�d!d��d�ZG�d"d��d�Zze�W�n�ek �r,���eZY�nX�G�d#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)�StringIOr���r���r ���r���r���r���r����excel� excel_tabr ���r���r���r���r���r ����Snifferr���r���� DictReader� DictWriter�unix_dialectc�������������������@���sD���e�Zd�ZdZdZdZdZdZdZdZ dZ dZdZdd��Z dd��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�����������������C���s���|�j�tkrd|�_|�����d�S�)NT)� __class__r����_valid� _validate��self��r����/usr/lib64/python3.8/csv.py�__init__*���s���� zDialect.__init__c�������������� ���C���s@���zt�|���W�n.�tk r:�}�ztt|���W�5�d�}~X�Y�nX�d�S��N)�_Dialect� TypeErrorr����str)r����er���r���r���r���/���s����zDialect._validate)�__name__� __module__�__qualname__r����_namer���� delimiter� quotecharZ escapechar�doublequote�skipinitialspace�lineterminator�quotingr ���r���r���r���r���r���r������s���c�������������������@���s(���e�Zd�ZdZdZdZdZdZdZe Z dS�)r���z;Describe the usual properties of Excel-generated CSV files.�,�"TF� N)r&���r'���r(���r���r*���r+���r,���r-���r.���r���r/���r���r���r���r���r���6���s���c�������������������@���s���e�Zd�ZdZdZdS�)r���zEDescribe the usual properties of Excel-generated TAB-delimited files.� N)r&���r'���r(���r���r*���r���r���r���r���r���@���s���z excel-tabc�������������������@���s(���e�Zd�ZdZdZdZdZdZdZe Z dS�)r���z:Describe the usual properties of Unix-generated CSV files.r0���r1���TF� N)r&���r'���r(���r���r*���r+���r,���r-���r.���r���r/���r���r���r���r���r���E���s���Zunixc�������������������@���s@���e�Zd�Zddd�Zdd��Zedd���Zejd d���Zd d��ZdS�) r���Nr���c�����������������O���s6���||�_�||�_||�_t||f|�|�|�_||�_d|�_d�S��Nr���)�_fieldnames�restkey�restvalr����dialect�line_num)r����f� fieldnamesr7���r8���r9����args�kwdsr���r���r���r ���Q���s����zDictReader.__init__c�����������������C���s���|�S�r!���r���r���r���r���r����__iter__Z���s����zDictReader.__iter__c�����������������C���s@���|�j�d�kr0zt|�j�|�_�W�n�tk r.���Y�nX�|�jj|�_|�j�S�r!���)r6����nextr���� StopIterationr:���r���r���r���r���r<���]���s���� zDictReader.fieldnamesc�����������������C���s ���||�_�d�S�r!���)r6���)r����valuer���r���r���r<���g���s����c�����������������C���s����|�j�dkr|�j�t|�j�}|�jj�|�_�|g�kr8t|�j�}q$tt|�j|��}t|�j�}t|�}||k�rv||d���||�j<�n&||kr�|�j|d���D�]}|�j||<�q�|S�r5���) r:���r<���r@���r����dict�zip�lenr7���r8���)r����row�dZlfZlr�keyr���r���r����__next__k���s���� zDictReader.__next__)NNNr���) r&���r'���r(���r ���r?����propertyr<����setterrI���r���r���r���r���r���P���s������ c�������������������@���s6���e�Zd�Zddd�Zdd��Zdd ��Zd d��Zdd ��ZdS�)r���r����raiser���c�����������������O���sB���||�_�||�_|���dkr$td|���||�_t||f|�|�|�_d�S�)N)rL����ignorez-extrasaction (%s) must be 'raise' or 'ignore')r<���r8����lower� ValueError�extrasactionr���)r���r;���r<���r8���rP���r9���r=���r>���r���r���r���r �������s�����zDictWriter.__init__c�����������������C���s���t�t|�j|�j��}|��|�S�r!���)rC���rD���r<����writerow)r����headerr���r���r����writeheader����s����zDictWriter.writeheaderc��������������������sN����j�dkr8������j�}|r8tdd�dd��|D���������fdd��jD��S�)NrL���z(dict contains fields not in fieldnames: z, c�����������������S���s���g�|�]}t�|��qS�r���)�repr)�.0�xr���r���r���� <listcomp>����s�����z,DictWriter._dict_to_list.<locals>.<listcomp>c�����������������3���s���|�]}����|�j�V��qd�S�r!���)�getr8���)rU���rH�����rowdictr���r���r���� <genexpr>����s�����z+DictWriter._dict_to_list.<locals>.<genexpr>)rP����keysr<���rO����join)r���rZ���Zwrong_fieldsr���rY���r���� _dict_to_list����s���� �zDictWriter._dict_to_listc�����������������C���s���|�j��|��|��S�r!���)r���rQ���r^���)r���rZ���r���r���r���rQ�������s����zDictWriter.writerowc�����������������C���s���|�j��t|�j|��S�r!���)r���� writerows�mapr^���)r���Zrowdictsr���r���r���r_�������s����zDictWriter.writerowsN)r���rL���r���)r&���r'���r(���r ���rS���r^���rQ���r_���r���r���r���r���r�������s������ c�������������������@���s:���e�Zd�ZdZdd��Zd dd�Zdd��Zd d ��Zdd��ZdS�)r���ze "Sniffs" the format of a CSV file (i.e. delimiter, quotechar) Returns a Dialect object. c�����������������C���s���dddddg|�_�d�S�)Nr0���r3����;� �:)� preferredr���r���r���r���r �������s����zSniffer.__init__Nc�����������������C���sd���|���||�\}}}}|s(|��||�\}}|s4td��G�dd��dt�}||_||_|pVd|_||_|S�)zI Returns a dialect (or None) corresponding to the sample zCould not determine delimiterc�������������������@���s���e�Zd�ZdZdZeZdS�)zSniffer.sniff.<locals>.dialectZsniffedr2���N)r&���r'���r(���r)���r.���r���r/���r���r���r���r���r9�������s���r9���r1���)�_guess_quote_and_delimiter�_guess_delimiterr���r���r,���r*���r+���r-���)r����sample� delimitersr+���r,���r*���r-���r9���r���r���r����sniff����s���� � � z Sniffer.sniffc�������������� ���C���s���g�}dD�]*}t��|t�jt�jB��}|�|�}|r�q4q|s<dS�i�}i�}d}|j} |D�]�} | d�d�}| |�}|r�|�|d�d�||<�z| d�d�}| |�}W�n�tk r����Y�qRY�nX�|r�|dks�||kr�|�|d�d�||<�z| d�d�}W�n�tk �r���Y�qRY�nX�| |�rR|d7�}qRt||jd �} |�rXt||jd �}||�|k}|d k�r`d}nd}d}t��dt�� |�| d ��t�j�}|� |��r�d}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�����delimNZspace�rH���r4���r���z]((%(delim)s)|^)\W*%(quote)s[^%(delim)s\n]*%(quote)s[^%(delim)s\n]*%(quote)s\W*((%(delim)s)|$))rl���rj���TF)�re�compile�DOTALL� MULTILINE�findall� groupindexrX����KeyError�max�escape�search)r����datarh���ZmatchesZrestrZregexpZquotes�delimsZspacesrs����m�nrH���r+���rl���r-���Z dq_regexpr,���r���r���r���re�������s`���� ��z"Sniffer._guess_quote_and_delimiterc�����������������C���s���t�td|�d���}dd��td�D��}tdt|��}d}i�}i�}i�}d|�} } | t|�k��rR|d7�}|| | ��D�]@}|D�]6}|�|i��} |�|�}| �|d�d�| |<�| ||<�qxqp|���D�]�}t�||�� ���}t|�dkr�|d�d�dkr�q�t|�dk�rLt |d d ��d�||<�|�||���||�d�||�d�tdd ��|D����f||<�q�|d�||<�q�|� ��}t t||�t|���}d}d}t|�dk�r�||k�r�|D�]T\}}|d�dk�r�|d�dk�r�|d�|�|k�r�|dk�s�||k�r�|||<��q�|d8�}�q�t|�dk�rDt�|����d�}|d��|�|d��d|��k}||fS�| } | |7�} qN|�s\dS�t|�dk�r�|�jD�]@}||���k�rp|d��|�|d��d|��k}||f��S��qpdd��|� ��D��}|����|d�d�}|d��|�|d��d|��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. Nr4���c�����������������S���s���g�|�]}t�|��qS�r���)�chr)rU����cr���r���r���rW���-��s�����z,Sniffer._guess_delimiter.<locals>.<listcomp>����� ���r���rk���c�����������������S���s���|�d�S�)Nrk���r���)rV���r���r���r����<lambda>G�������z*Sniffer._guess_delimiter.<locals>.<lambda>rm���c�����������������s���s���|�]}|d��V��qdS�)rk���Nr���)rU����itemr���r���r���r[���L��s�����z+Sniffer._guess_delimiter.<locals>.<genexpr>g�������?g�������?g{�G�z�?z%c )r���r���c�����������������S���s���g�|�]\}}||f�qS�r���r���)rU����k�vr���r���r���rW���v��s��������)�list�filter�split�range�minrE���rX����countr\����itemsru����remove�sum�floatrd����sort)r���rx���rh����asciiZchunkLengthZ iterationZ charFrequencyZmodesry����start�end�line�charZ metaFrequencyZfreqr����ZmodeListZtotalZconsistencyZ thresholdr����r����rl���r-���rG���r���r���r���rf�����s����� ���� ��zSniffer._guess_delimiterc����������� ������C���s���t�t|�|��|��}t|�}t|�}i�}t|�D�]}d�||<�q0d}|D�]�}|dkrV�q�|d7�}t|�|krlqFt|����D�]x} tt t fD�]4} z| || ���W��q�W�q��ttfk r����Y�q�X�q�t|| ��} | || �krx|| �d�kr�| || <�qx|| =�qxqFd}|� ��D�]~\} }t|�td�k�r@t|| ��|k�r6|d7�}n|d8�}n<z||| ���W�n"�ttfk �rr���|d7�}Y�n X�|d8�}�q�|dkS�)Nr�������rk���)r���r���ri���r@���rE���r����r����r\����intr�����complexrO���� OverflowErrorr�����typer#���) r���rg���ZrdrrR����columnsZcolumnTypes�i�checkedrF����colZthisTypeZ hasHeaderZcolTyper���r���r���� has_header��sJ���� � zSniffer.has_header)N) r&���r'���r(���r���r ���ri���re���rf���r����r���r���r���r���r�������s��� Lg)r���rn���Z_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���r���r���r���r����<module>���sJ���@������������� 2