ok

Mini Shell

Direktori : /proc/thread-self/root/opt/alt/python39/lib64/python3.9/__pycache__/
Upload File :
Current File : //proc/thread-self/root/opt/alt/python39/lib64/python3.9/__pycache__/csv.cpython-39.pyc

a

���e?�@sdZddlZddlmZmZmZmZmZmZm	Z	m
Z
mZmZm
Z
mZmZmZddlmZddlmZgd�ZGdd�d�ZGd	d
�d
e�Zed
e�Gdd�de�Zed
e�Gdd�de�Zede�Gdd�d�ZGdd�d�ZzeWne�yeZYn0Gdd�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)rrr
rrrr�excel�	excel_tabr
rrrrr	�Snifferrr�
DictReader�
DictWriter�unix_dialectc@sDeZdZdZdZdZdZdZdZdZ	dZ
dZdZdd�Z
dd�ZdS)	rz�Describe a CSV dialect.

    This must be subclassed (see csv.excel).  Valid attributes are:
    delimiter, quotechar, escapechar, doublequote, skipinitialspace,
    lineterminator, quoting.

    �FNcCs|jtkrd|_|��dS)NT)�	__class__r�_valid�	_validate��self�r�(/opt/alt/python39/lib64/python3.9/csv.py�__init__*s
zDialect.__init__c
CsBzt|�Wn0ty<}ztt|���WYd}~n
d}~00dS�N)�_Dialect�	TypeErrorr�str)r�errrr/szDialect._validate)�__name__�
__module__�__qualname__r�_namer�	delimiter�	quotecharZ
escapechar�doublequote�skipinitialspace�lineterminator�quotingr rrrrrrsrc@s(eZdZdZdZdZdZdZdZe	Z
dS)rz;Describe the usual properties of Excel-generated CSV files.�,�"TF�
N)r&r'r(rr*r+r,r-r.rr/rrrrr6src@seZdZdZdZdS)rzEDescribe the usual properties of Excel-generated TAB-delimited files.�	N)r&r'r(rr*rrrrr@srz	excel-tabc@s(eZdZdZdZdZdZdZdZe	Z
dS)rz:Describe the usual properties of Unix-generated CSV files.r0r1TF�
N)r&r'r(rr*r+r,r-r.rr/rrrrrEsrZunixc@s@eZdZddd�Zdd�Zedd��Zejd	d��Zd
d�ZdS)
rNrcOs<||_||_||_t||g|�Ri|��|_||_d|_dS�Nr)�_fieldnames�restkey�restvalr�dialect�line_num)r�f�
fieldnamesr7r8r9�args�kwdsrrrr QszDictReader.__init__cCs|Sr!rrrrr�__iter__ZszDictReader.__iter__cCs>|jdur.zt|j�|_Wnty,Yn0|jj|_|jSr!)r6�nextr�
StopIterationr:rrrrr<]s

zDictReader.fieldnamescCs
||_dSr!)r6)r�valuerrrr<gscCs�|jdkr|jt|j�}|jj|_|gkr8t|j�}q$tt|j|��}t|j�}t|�}||krv||d�||j<n&||kr�|j|d�D]}|j||<q�|Sr5)	r:r<r@r�dict�zip�lenr7r8)r�row�dZlfZlr�keyrrr�__next__ks



zDictReader.__next__)NNNr)	r&r'r(r r?�propertyr<�setterrIrrrrrPs�
	
	
rc@s6eZdZddd�Zdd�Zdd	�Zd
d�Zdd
�ZdS)rr�raisercOsH||_||_|��dvr$td|��||_t||g|�Ri|��|_dS)N)rL�ignorez-extrasaction (%s) must be 'raise' or 'ignore')r<r8�lower�
ValueError�extrasactionr)rr;r<r8rPr9r=r>rrrr �s�zDictWriter.__init__cCstt|j|j��}|�|�Sr!)rCrDr<�writerow)r�headerrrr�writeheader�szDictWriter.writeheadercsN�jdkr8����j}|r8tdd�dd�|D������fdd��jD�S)NrLz(dict contains fields not in fieldnames: z, cSsg|]}t|��qSr)�repr)�.0�xrrr�
<listcomp>��z,DictWriter._dict_to_list.<locals>.<listcomp>c3s|]}��|�j�VqdSr!)�getr8)rUrH��rowdictrrr�	<genexpr>�rXz+DictWriter._dict_to_list.<locals>.<genexpr>)rP�keysr<rO�join)rr[Zwrong_fieldsrrZr�
_dict_to_list�s
�zDictWriter._dict_to_listcCs|j�|�|��Sr!)rrQr_)rr[rrrrQ�szDictWriter.writerowcCs|j�t|j|��Sr!)r�	writerows�mapr_)rZrowdictsrrrr`�szDictWriter.writerowsN)rrLr)r&r'r(r rSr_rQr`rrrrr�s�

rc@s:eZdZdZdd�Zd
dd�Zdd�Zd	d
�Zdd�ZdS)rze
    "Sniffs" the format of a CSV file (i.e. delimiter, quotechar)
    Returns a Dialect object.
    cCsgd�|_dS)N)r0r3�;� �:)�	preferredrrrrr �szSniffer.__init__NcCsd|�||�\}}}}|s(|�||�\}}|s4td��Gdd�dt�}||_||_|pVd|_||_|S)zI
        Returns a dialect (or None) corresponding to the sample
        zCould not determine delimiterc@seZdZdZdZeZdS)zSniffer.sniff.<locals>.dialectZsniffedr2N)r&r'r(r)r.rr/rrrrr9�sr9r1)�_guess_quote_and_delimiter�_guess_delimiterrrr,r*r+r-)r�sample�
delimitersr+r,r*r-r9rrr�sniff�s
�
�
z
Sniffer.sniffc	Cs�g}dD]*}t�|tjtjB�}|�|�}|rq4q|s<dSi}i}d}|j}	|D]�}
|	dd}|
|}|r�|�|d�d||<z|	dd}|
|}Wnty�YqRYn0|r�|dus�||vr�|�|d�d||<z|	dd}Wnt�yYqRYn0|
|rR|d7}qRt||jd	�}
|�rTt||jd	�}|||k}|d
k�r\d}nd}d}t�dt�	|�|
d
�tj�}|�
|��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))rFNrr�quote��delimNZspace�rHr4rz]((%(delim)s)|^)\W*%(quote)s[^%(delim)s\n]*%(quote)s[^%(delim)s\n]*%(quote)s\W*((%(delim)s)|$))rmrkTF)�re�compile�DOTALL�	MULTILINE�findall�
groupindexrY�KeyError�max�escape�search)r�datariZmatchesZrestrZregexpZquotes�delims�spacesrt�m�nrHr+rmr-Z	dq_regexpr,rrrrf�s`




��z"Sniffer._guess_quote_and_delimitercCsttd|�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�|dddkr�q�t|�dk�rLt
|d	d
�d�||<|�||�||d||dtdd
�|D��f||<q�|d||<q�|�	�}t
t||t|���}d}d}t|�dk�r�||k�r�|D]T\}}|ddk�r�|ddk�r�|d||k�r�|du�s�||v�r�|||<�q�|d8}�q�t|�dk�rDt|���d}|d�|�|d�d|�k}||fS|
}	|
|7}
qN|�s\dSt|�dk�r�|jD]@}||��v�rp|d�|�|d�d|�k}||fS�qpdd�|�	�D�}|��|dd}|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.
        Nr4cSsg|]}t|��qSr)�chr)rU�crrrrW-rXz,Sniffer._guess_delimiter.<locals>.<listcomp>��
rrlcSs|dS)Nrlr)rVrrr�<lambda>GrXz*Sniffer._guess_delimiter.<locals>.<lambda>rncss|]}|dVqdS)rlNr)rU�itemrrrr\LrXz+Sniffer._guess_delimiter.<locals>.<genexpr>g�?g�������?g{�G�z�?z%c )rrcSsg|]\}}||f�qSrr)rU�k�vrrrrWvrX���)�list�filter�split�range�minrErY�countr]�itemsrv�remove�sum�floatre�sort)rryri�asciiZchunkLengthZ	iterationZ
charFrequencyZmodesrz�start�end�line�charZ
metaFrequencyZfreqr�ZmodeList�totalZconsistencyZ	thresholdr�r�rmr-rGrrrrgs�

����

��zSniffer._guess_delimiterc
Cs�tt|�|�|��}t|�}t|�}i}t|�D]}d||<q0d}|D]�}|dkrVq�|d7}t|�|krlqFt|���D]v}	tt	t
fD]2}
z|
||	�Wq�Wq�ttfy�Yq�0q�t||	�}
|
||	krx||	dur�|
||	<qx||	=qxqFd}|�
�D]z\}	}t|�td�k�r>t||	�|k�r4|d7}n|d8}q�z|||	�Wn ttf�yn|d7}Yq�0|d8}q�|dkS)Nr�rl)rrrjr@rEr�r�r]�intr��complexrO�
OverflowErrorr��typer#)
rrhZrdrrR�columnsZcolumnTypes�i�checkedrF�colZthisTypeZ	hasHeaderZcolTyperrr�
has_headersH






zSniffer.has_header)N)	r&r'r(rr rjrfrgr�rrrrr�s
Lgr)rroZ_csvrrrrrrrr	r
rrr
rrr"�ior�__all__rrrrrr��	NameErrorr�rrrrr�<module>s&@


2


Zerion Mini Shell 1.0