%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /usr/local/lib/python3.8/__pycache__/
Upload File :
Create Path :
Current File : //usr/local/lib/python3.8/__pycache__/csv.cpython-38.pyc

U

na?@s@dZddlZddlmZmZmZmZmZmZm	Z	m
Z
mZmZm
Z
mZmZmZddlmZddlmZdddd	d
ddd
dddddddddddddgZGdddZGdd
d
eZed
eGdddeZedeGdddeZed eGd!ddZGd"ddZzeWnek
r,eZYnXGd#ddZdS)$z+
csv.py - read/write/investigate CSV files
N)Error__version__writerreaderregister_dialectunregister_dialectget_dialect
list_dialectsfield_size_limit
QUOTE_MINIMAL	QUOTE_ALLQUOTE_NONNUMERIC
QUOTE_NONE__doc__)Dialect)StringIOrrr
rrrrexcel	excel_tabr
rrrrr	Snifferrr
DictReader
DictWriterunix_dialectc@sDeZdZdZdZdZdZdZdZdZ	dZ
dZdZddZ
ddZdS)	rzDescribe 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	_validateselfr/usr/local/lib/python3.8/csv.py__init__*s
zDialect.__init__c
Cs@zt|Wn.tk
r:}ztt|W5d}~XYnXdSN)_Dialect	TypeErrorrstr)rerrrr/szDialect._validate)__name__
__module____qualname__r_namer	delimiter	quotecharZ
escapechardoublequoteskipinitialspacelineterminatorquotingr rrrrrrsc@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/rrrrr6sc@seZdZdZdZdS)rzEDescribe the usual properties of Excel-generated TAB-delimited files.	N)r&r'r(rr*rrrrr@sz	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/rrrrrEsZunixc@s@eZdZdddZddZeddZejd	dZd
dZdS)
rNrcOs6||_||_||_t||f|||_||_d|_dSNr)_fieldnamesrestkeyrestvalrdialectline_num)rf
fieldnamesr7r8r9argskwdsrrrr QszDictReader.__init__cCs|Sr!rrrrr__iter__ZszDictReader.__iter__cCs@|jdkr0zt|j|_Wntk
r.YnX|jj|_|jSr!)r6nextr
StopIterationr:rrrrr<]s

zDictReader.fieldnamescCs
||_dSr!)r6)rvaluerrrr<gscCs|jdkr|jt|j}|jj|_|gkr8t|j}q$tt|j|}t|j}t|}||krv||d||j<n&||kr|j|dD]}|j||<q|Sr5)	r:r<r@rdictziplenr7r8)rrowdZlfZlrkeyrrr__next__ks



zDictReader.__next__)NNNr)	r&r'r(r r?propertyr<setterrIrrrrrPs
	
	
c@s6eZdZdddZddZdd	Zd
dZdd
ZdS)rrraisercOsB||_||_|dkr$td|||_t||f|||_dS)N)rLignorez-extrasaction (%s) must be 'raise' or 'ignore')r<r8lower
ValueErrorextrasactionr)rr;r<r8rPr9r=r>rrrr szDictWriter.__init__cCstt|j|j}||Sr!)rCrDr<writerow)rheaderrrrwriteheaderszDictWriter.writeheadercsNjdkr8j}|r8tdddd|DfddjDS)NrLz(dict contains fields not in fieldnames: z, cSsg|]}t|qSr)repr).0xrrr
<listcomp>sz,DictWriter._dict_to_list.<locals>.<listcomp>c3s|]}|jVqdSr!)getr8)rUrHrowdictrrr	<genexpr>sz+DictWriter._dict_to_list.<locals>.<genexpr>)rPkeysr<rOjoin)rrZZwrong_fieldsrrYr
_dict_to_lists
zDictWriter._dict_to_listcCs|j||Sr!)rrQr^)rrZrrrrQszDictWriter.writerowcCs|jt|j|Sr!)r	writerowsmapr^)rZrowdictsrrrr_szDictWriter.writerowsN)rrLr)r&r'r(r rSr^rQr_rrrrrs

c@s:eZdZdZddZd
ddZddZd	d
ZddZdS)rze
    "Sniffs" the format of a CSV file (i.e. delimiter, quotechar)
    Returns a Dialect object.
    cCsdddddg|_dS)Nr0r3; :)	preferredrrrrr szSniffer.__init__NcCsd|||\}}}}|s(|||\}}|s4tdGdddt}||_||_|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/rrrrr9sr9r1)_guess_quote_and_delimiter_guess_delimiterrrr,r*r+r-)rsample
delimitersr+r,r*r-r9rrrsniffs


z
Sniffer.sniffc	Csg}dD]*}t|tjtjB}||}|rq4q|s<dSi}i}d}|j}	|D]}
|	dd}|
|}|r||dd||<z|	dd}|
|}Wntk
rYqRYnX|r|dks||kr||dd||<z|	dd}Wntk
rYqRYnX|
|rR|d7}qRt||jd	}
|rXt||jd	}|||k}|d
kr`d}nd}d}tdt	||
d
tj}|
|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))rFNrrquotedelimNZspacerHr4rz]((%(delim)s)|^)\W*%(quote)s[^%(delim)s\n]*%(quote)s[^%(delim)s\n]*%(quote)s\W*((%(delim)s)|$))rlrjTF)recompileDOTALL	MULTILINEfindall
groupindexrXKeyErrormaxescapesearch)rdatarhmatchesZrestrZregexpZquotesdelimsZspacesrsmnrHr+rlr-Z	dq_regexpr,rrrres`




z"Sniffer._guess_quote_and_delimitercCsttd|d}ddtdD}tdt|}d}i}i}i}d|}	}
|	t|krR|d7}||	|
D]@}|D]6}||i}
||}|
|dd|
|<|
||<qxqp|D]}t||	}t|dkr|dddkrqt|dkrLt
|d	d
d||<|||||d||dtdd
|Df||<q|d||<q|	}t
t||t|}d}d}t|dkr||kr|D]T\}}|ddkr|ddkr|d||kr|dks||kr|||<q|d8}qt|dkrDt|d}|d||dd|k}||fS|
}	|
|7}
qN|s\dSt|dkr|jD]@}||krp|d||dd|k}||fSqpdd|	D}||dd}|d||dd|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)rUcrrrrW-sz,Sniffer._guess_delimiter.<locals>.<listcomp>
rrkcSs|dS)Nrkr)rVrrr<lambda>Gz*Sniffer._guess_delimiter.<locals>.<lambda>rmcss|]}|dVqdS)rkNr)rUitemrrrr[Lsz+Sniffer._guess_delimiter.<locals>.<genexpr>g?g?g{Gz?z%c )rrcSsg|]\}}||fqSrr)rUkvrrrrWvs)listfiltersplitrangeminrErXcountr\itemsruremovesumfloatrdsort)rrxrhasciiZchunkLengthZ	iterationZ
charFrequencyZmodesrzstartendlinecharZ
metaFrequencyZfreqrZmodeListtotalZconsistencyZ	thresholdrrrlr-rGrrrrfs



zSniffer._guess_delimiterc
Cstt|||}t|}t|}i}t|D]}d||<q0d}|D]}|dkrVq|d7}t||krlqFt|D]x}	tt	t
fD]4}
z|
||	WqWqttfk
rYqXqt||	}
|
||	krx||	dkr|
||	<qx||	=qxqFd}|
D]~\}	}t|tdkr@t||	|kr6|d7}n|d8}n<z|||	Wn"ttfk
rr|d7}Yn
X|d8}q|dkS)Nrrk)rrrir@rErrr\intrcomplexrO
OverflowErrorrtyper#)
rrgZrdrrRcolumnsZcolumnTypesicheckedrFcolZthisTypeZ	hasHeaderZcolTyperrr
has_headersJ






zSniffer.has_header)N)	r&r'r(rr rirerfrrrrrrs
Lg)rrnZ_csvrrrrrrrr	r
rrr
rrr"ior__all__rrrrrr	NameErrorrrrrrr<module>sJ@


2


Zerion Mini Shell 1.0