Hacked By AnonymousFox

Current Path : /proc/thread-self/root/proc/self/root/opt/alt/python35/lib64/python3.5/__pycache__/
Upload File :
Current File : //proc/thread-self/root/proc/self/root/opt/alt/python35/lib64/python3.5/__pycache__/csv.cpython-35.pyc



��Yf?�@s�dZddlZddlmZmZmZmZmZmZm	Z	m
Z
mZmZm
Z
mZmZmZddlmZddlmZdddd	d
ddd
ddddddddddddgZGdd�d�ZGdd
�d
e�Zed
e�Gdd�de�Zede�Gdd�de�Zed e�Gd!d�d�ZGd"d�d�ZyeWnek
r�eZYnXGd#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)�StringIOrrr
rrrr�excel�	excel_tabr
rrrrr	�Snifferrr�
DictReader�
DictWriterc@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|_|j�dS)NT)�	__class__r�_valid�	_validate)�self�r�(/opt/alt/python35/lib64/python3.5/csv.py�__init__)s	zDialect.__init__cCsLyt|�Wn7tk
rG}ztt|���WYdd}~XnXdS)N)�_Dialect�	TypeErrorr�str)r�errrr.szDialect._validate)�__name__�
__module__�__qualname__r�_namer�	delimiter�	quotecharZ
escapechar�doublequote�skipinitialspace�lineterminator�quotingrrrrrrrsc@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,rrrrr5sc@seZdZdZdZdS)rzEDescribe the usual properties of Excel-generated TAB-delimited files.�	N)r#r$r%rr'rrrrr?sz	excel-tabc@s:eZdZdZdZdZdZdZdZe	Z
dS)�unix_dialectz:Describe the usual properties of Unix-generated CSV files.r-r.TF�
N)r#r$r%rr'r(r)r*r+rr,rrrrr0Dsr0Zunixc@sgeZdZdddddd�Zdd�Zedd��Zejd	d��Zd
d�ZdS)rNrcOsI||_||_||_t||||�|_||_d|_dS)Nr)�_fieldnames�restkey�restvalr�dialect�line_num)r�f�
fieldnamesr3r4r5�args�kwdsrrrrPs				zDictReader.__init__cCs|S)Nr)rrrr�__iter__YszDictReader.__iter__cCsP|jdkr:yt|j�|_Wntk
r9YnX|jj|_|jS)N)r2�nextr�
StopIterationr6)rrrrr8\s
zDictReader.fieldnamescCs
||_dS)N)r2)r�valuerrrr8fscCs�|jdkr|jt|j�}|jj|_x|gkrUt|j�}q7Wtt|j|��}t|j�}t|�}||kr�||d�||j<n7||kr�x(|j|d�D]}|j||<q�W|S)Nr)	r6r8r<r�dict�zip�lenr3r4)r�row�dZlfZlr�keyrrr�__next__jszDictReader.__next__)	r#r$r%rr;�propertyr8�setterrErrrrrOs	
c@sUeZdZddddd�Zdd�Zdd	�Zd
d�Zdd
�ZdS)rr�raisercOsY||_||_|j�dkr4td|��||_t||||�|_dS)NrH�ignorez-extrasaction (%s) must be 'raise' or 'ignore')rHrI)r8r4�lower�
ValueError�extrasactionr)rr7r8r4rLr5r9r:rrrr�s		
	zDictWriter.__init__cCs,tt|j|j��}|j|�dS)N)r?r@r8�writerow)r�headerrrr�writeheader�szDictWriter.writeheadercsq�jdkrT�fdd��D�}|rTtddjdd�|D������fdd��jD�S)	NrHcs%g|]}|�jkr|�qSr)r8)�.0�k)rrr�
<listcomp>�s	z,DictWriter._dict_to_list.<locals>.<listcomp>z(dict contains fields not in fieldnames: z, cSsg|]}t|��qSr)�repr)rP�xrrrrR�s	c3s$|]}�j|�j�VqdS)N)�getr4)rPrD)�rowdictrrr�	<genexpr>�sz+DictWriter._dict_to_list.<locals>.<genexpr>)rLrK�joinr8)rrVZwrong_fieldsr)rVrr�
_dict_to_list�s zDictWriter._dict_to_listcCs|jj|j|��S)N)rrMrY)rrVrrrrM�szDictWriter.writerowcCs|jjt|j|��S)N)r�	writerows�maprY)rZrowdictsrrrrZ�szDictWriter.writerowsN)r#r$r%rrOrYrMrZrrrrr�s	c@sUeZdZdZdd�Zddd�Zdd�Zd	d
�Zdd�ZdS)
rze
    "Sniffs" the format of a CSV file (i.e. delimiter, quotechar)
    Returns a Dialect object.
    cCsdddddg|_dS)Nr-r/�;� �:)�	preferred)rrrrr�szSniffer.__init__NcCs�|j||�\}}}}|s<|j||�\}}|sNtd��Gdd�dt�}||_||_|pd|_||_|S)zI
        Returns a dialect (or None) corresponding to the sample
        zCould not determine delimiterc@s"eZdZdZdZeZdS)zSniffer.sniff.<locals>.dialectZsniffedz
N)r#r$r%r&r+rr,rrrrr5�sr5r.)�_guess_quote_and_delimiter�_guess_delimiterrrr)r'r(r*)r�sample�
delimitersr(r)r'r*r5rrr�sniff�s				z
Sniffer.sniffcCsg}x@dD]8}tj|tjtjB�}|j|�}|r
Pq
W|sSdSi}i}d}|j}	x�|D]�}
|	d	d
}|
|}|r�|j|d�d
||<y|	dd
}|
|}Wntk
r�wuYnX|r|dks||kr|j|d�d
||<y|	dd
}Wntk
rHwuYnX|
|ru|d
7}quWt|d
|j�}
|r�t|d
|j�}|||k}|dkr�d}nd}d}tjddtj	|�d	|
itj�}|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.
        �F(?P<delim>[^\w
"'])(?P<space> ?)(?P<quote>["']).*?(?P=quote)(?P=delim)�C(?:^|
)(?P<quote>["']).*?(?P=quote)(?P<delim>[^\w
"'])(?P<space> ?)�D(?P<delim>>[^\w
"'])(?P<space> ?)(?P<quote>["']).*?(?P=quote)(?:$|
)�*(?:^|
)(?P<quote>["']).*?(?P=quote)(?:$|
)rFNrZquote��delimZspacerDr1z]((%(delim)s)|^)\W*%(quote)s[^%(delim)s\n]*%(quote)s[^%(delim)s\n]*%(quote)s\W*((%(delim)s)|$)T)rerfrgrh)rFNr)�re�compile�DOTALL�	MULTILINE�findall�
groupindexrU�KeyError�max�escape�search)r�datarcZmatchesZrestrZregexpZquotes�delimsZspacesrp�m�nrDr(rjr*Z	dq_regexpr)rrrr`�s`
	




	%	z"Sniffer._guess_quote_and_delimitercCs�ttd|jd���}dd�td�D�}tdt|��}d}i}i}i}dt|t|��}	}
x�|	t|�kr |d7}xn||	|
�D]\}xS|D]K}|j|i�}
|j|�}|
j|d�d|
|<|
||<q�Wq�Wx�|j�D]�}t||j	��}t|�dkrb|dddkrbqt|�dkr�t
|d	d
d��||<|j||�||d||dtdd
�|D��f||<q|d||<qW|j	�}t
||�}d}d}x�t|�dkr�||kr�xj|D]b\}}|ddkr=|ddkr=|d||kr=|dks�||kr=|||<q=W|d8}qWt|�dkr
t|j��d}|dj|�|djd|�k}||fS|
}	|
|7}
q�W|s+dSt|�dkr�xW|jD]L}||j�krG|dj|�|djd|�k}||fSqGWdd�|j	�D�}|j�|dd}|dj|�|djd|�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.
        Nr1cSsg|]}t|��qSr)�chr)rP�crrrrR,s	z,Sniffer._guess_delimiter.<locals>.<listcomp>��
rrirDcSs|dS)Nrir)rTrrr�<lambda>Fsz*Sniffer._guess_delimiter.<locals>.<lambda>css|]}|dVqdS)riNr)rP�itemrrrrWKsz+Sniffer._guess_delimiter.<locals>.<genexpr>g�?g�������?g{�G�z�?z%c rcSs"g|]\}}||f�qSrr)rPrQ�vrrrrRus	)rr���)�list�filter�split�range�minrArU�count�keys�itemsrr�remove�sum�floatr_�sort)rrurc�asciiZchunkLengthZ	iterationZ
charFrequencyZmodesrv�start�end�line�charZ
metaFrequencyZfreqr�ZmodeListZtotalZconsistencyZ	thresholdrQrrjr*rCrrrrast

&$! 

zSniffer._guess_delimiterc
Cs�tt|�|j|��}t|�}t|�}i}xt|�D]}d||<qIWd}x�|D]�}|dkr}P|d7}t|�|kr�qjx�t|j��D]�}	xUtt	t
gD]4}
y|
||	�PWq�ttfk
r�Yq�Xq�Wt||	�}
|
||	kr�||	dkr:|
||	<q�||	=q�WqjWd}x�|j
�D]�\}	}t|�td�kr�t||	�|kr�|d7}q�|d8}q\y|||	�Wn"ttfk
r�|d7}Yq\X|d8}q\W|dkS)Nr�ri)rrrdr<rAr�r�r��intr��complexrK�
OverflowErrorr��typer )
rrbZrdrrN�columnsZcolumnTypes�iZcheckedrB�colZthisTypeZ	hasHeaderZcolTyperrr�
has_header~sJ


	


zSniffer.has_header)	r#r$r%rrrdr`rar�rrrrr�sLg)rrkZ_csvrrrrrrrr	r
rrr
rrr�ior�__all__rrr0rrr��	NameErrorr�rrrrr�<module>s.^	


2


Hacked By AnonymousFox1.0, Coded By AnonymousFox