AlkantarClanX12

Your IP : 13.58.45.238


Current Path : /opt/alt/python37/lib64/python3.7/__pycache__/
Upload File :
Current File : //opt/alt/python37/lib64/python3.7/__pycache__/csv.cpython-37.opt-1.pyc

B

� f4?�@sLdZddlZddlmZmZmZmZmZmZm	Z	m
Z
mZmZm
Z
mZmZmZddlmZddlmZddlmZddd	d
ddd
ddddddddddddddgZGdd�d�ZGdd�de�Zede�Gdd�de�Zede�Gd d�de�Zed!e�Gd"d�d�ZGd#d�d�ZyeWnek
�r8eZYnXGd$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)�OrderedDict)�StringIOrr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/python37/lib64/python3.7/csv.py�__init__+s
zDialect.__init__c
Cs@yt|�Wn.tk
r:}ztt|���Wdd}~XYnXdS)N)�_Dialect�	TypeErrorr�str)r�errrr0szDialect._validate)�__name__�
__module__�__qualname__r�_namer�	delimiter�	quotecharZ
escapechar�doublequote�skipinitialspace�lineterminator�quotingr rrrrrrsc@s(eZdZdZdZdZdZdZdZe	Z
dS)rz;Describe the usual properties of Excel-generated CSV files.�,�"TFz
N)r%r&r'rr)r*r+r,r-rr.rrrrr7sc@seZdZdZdZdS)rzEDescribe the usual properties of Excel-generated TAB-delimited files.�	N)r%r&r'rr)rrrrrAsz	excel-tabc@s(eZdZdZdZdZdZdZdZe	Z
dS)rz:Describe the usual properties of Unix-generated CSV files.r/r0TF�
N)r%r&r'rr)r*r+r,r-rr.rrrrrFsZunixc@s@eZdZddd�Zdd�Zedd��Zejd	d��Zd
d�ZdS)
rNrcOs6||_||_||_t||f|�|�|_||_d|_dS)Nr)�_fieldnames�restkey�restvalr�dialect�line_num)r�f�
fieldnamesr4r5r6�args�kwdsrrrr RszDictReader.__init__cCs|S)Nr)rrrr�__iter__[szDictReader.__iter__cCs@|jdkr0yt|j�|_Wntk
r.YnX|jj|_|jS)N)r3�nextr�
StopIterationr7)rrrrr9^s

zDictReader.fieldnamescCs
||_dS)N)r3)r�valuerrrr9hscCs�|jdkr|jt|j�}|jj|_x|gkr:t|j�}q&Wtt|j|��}t|j�}t|�}||krz||d�||j<n*||kr�x |j|d�D]}|j||<q�W|S)Nr)	r7r9r=rr�zip�lenr4r5)r�row�dZlfZlr�keyrrr�__next__ls




zDictReader.__next__)NNNr)	r%r&r'r r<�propertyr9�setterrErrrrrQs

c@s6eZdZddd�Zdd�Zdd	�Zd
d�Zdd
�ZdS)rr�raisercOsB||_||_|��dkr$td|��||_t||f|�|�|_dS)N)rH�ignorez-extrasaction (%s) must be 'raise' or 'ignore')r9r5�lower�
ValueError�extrasactionr)rr8r9r5rLr6r:r;rrrr �szDictWriter.__init__cCs tt|j|j��}|�|�dS)N)�dictr@r9�writerow)r�headerrrr�writeheader�szDictWriter.writeheadercsN�jdkr8����j}|r8tdd�dd�|D������fdd��jD�S)NrHz(dict contains fields not in fieldnames: z, cSsg|]}t|��qSr)�repr)�.0�xrrr�
<listcomp>�sz,DictWriter._dict_to_list.<locals>.<listcomp>c3s|]}��|�j�VqdS)N)�getr5)rRrD)�rowdictrrr�	<genexpr>�sz+DictWriter._dict_to_list.<locals>.<genexpr>)rL�keysr9rK�join)rrVZwrong_fieldsr)rVrr�
_dict_to_list�s
zDictWriter._dict_to_listcCs|j�|�|��S)N)rrNrZ)rrVrrrrN�szDictWriter.writerowcCs|j�t|j|��S)N)r�	writerows�maprZ)rZrowdictsrrrr[�szDictWriter.writerowsN)rrHr)r%r&r'r rPrZrNr[rrrrr�s
	c@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.
    cCsdddddg|_dS)Nr/r1�;� �:)�	preferred)rrrrr �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>.dialectZsniffedz
N)r%r&r'r(r-rr.rrrrr6�sr6r0)�_guess_quote_and_delimiter�_guess_delimiterrrr+r)r*r,)r�sample�
delimitersr*r+r)r,r6rrr�sniff�s

z
Sniffer.sniffc	Cs�g}x0dD](}t�|tjtjB�}|�|�}|r
Pq
W|s>dSi}i}d}|j}	x�|D]�}
|	dd}|
|}|r�|�|d�d||<y|	dd}|
|}Wntk
r�wVYnX|r�|dks�||kr�|�|d�d||<y|	dd}Wntk
�rwVYnX|
|rV|d7}qVWt||jd	�}
|�rZt||jd	�}|||k}|d
k�rbd}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)rDr2rz]((%(delim)s)|^)\W*%(quote)s[^%(delim)s\n]*%(quote)s[^%(delim)s\n]*%(quote)s\W*((%(delim)s)|$))rhrfTF)�re�compile�DOTALL�	MULTILINE�findall�
groupindexrU�KeyError�max�escape�search)r�datardZmatchesZrestrZregexpZquotes�delimsZspacesrn�m�nrDr*rhr,Z	dq_regexpr+rrrra�sZ



z"Sniffer._guess_quote_and_delimitercCsttd|�d���}dd�td�D�}tdt|��}d}i}i}i}d|}	}
�x|	t|�k�rj|d7}xT||	|
�D]D}x>|D]6}|�|i�}
|�|�}|
�|d�d|
|<|
||<q�WqvWx�|��D]�}t||�	��}t|�dkr�|dddkr�q�t|�dk�rZt
|d	d
�d�||<|�||�||d||dtdd
�|D��f||<q�|d||<q�W|�	�}t
t||t|���}d}d}x�t|�dk�r||k�rx\|D]T\}}|ddk�r�|ddk�r�|d||k�r�|dk�s�||k�r�|||<�q�W|d8}�q�Wt|�dk�r\t|���d}|d�|�|d�d|�k}||fS|
}	|
|7}
qRW|�svdSt|�dk�r�xF|jD]<}||��k�r�|d�|�|d�d|�k}||fS�q�Wdd�|�	�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.
        Nr2cSsg|]}t|��qSr)�chr)rR�crrrrT.sz,Sniffer._guess_delimiter.<locals>.<listcomp>��
rrgcSs|dS)Nrgr)rSrrr�<lambda>H�z*Sniffer._guess_delimiter.<locals>.<lambda>)rDcss|]}|dVqdS)rgNr)rR�itemrrrrWMsz+Sniffer._guess_delimiter.<locals>.<genexpr>g�?g�������?g{�G�z�?z%c )rrcSsg|]\}}||f�qSrr)rR�k�vrrrrTws���)�list�filter�split�range�minrArU�countrX�itemsrp�remove�sum�floatr`�sort)rrsrd�asciiZchunkLengthZ	iterationZ
charFrequencyZmodesrt�start�end�line�charZ
metaFrequencyZfreqr�ZmodeListZtotalZconsistencyZ	thresholdr~rrhr,rCrrrrbst


zSniffer._guess_delimiterc
Cs�tt|�|�|��}t|�}t|�}i}xt|�D]}d||<q2Wd}x�|D]�}|dkrZP|d7}t|�|krpqLx�t|���D]x}	xJtt	t
gD]0}
y|
||	�PWq�ttfk
r�Yq�Xq�Wt||	�}
|
||	kr~||	dkr�|
||	<q~||	=q~WqLWd}x�|�
�D]~\}	}t|�td�k�rLt||	�|k�rB|d7}n|d8}n<y|||	�Wn"ttfk
�r~|d7}Yn
X|d8}�qW|dkS)Nr�rg)rrrer=rAr�r�rX�intr��complexrK�
OverflowErrorr��typer")
rrcZrdrrO�columnsZcolumnTypes�i�checkedrB�colZthisTypeZ	hasHeaderZcolTyperrr�
has_header�sJ





zSniffer.has_header)N)	r%r&r'rr rerarbr�rrrrr�s
Lg) rriZ_csvrrrrrrrr	r
rrr
rrr!�collectionsr�ior�__all__rrrrrr��	NameErrorr�rrrrr�<module>s2@



2