ACC SHELL

Path : /usr/lib/python/
File Upload :
Current File : //usr/lib/python/csv.pyc

Ñò
nÄMc@sÆdZddkZddklZddklZlZlZlZl	Z	l
Z
lZlZl
Z
lZlZlZlZlZddklZyddklZWn#ej
oddklZnXddd	d
ddd
dddddddddddddgZdd"d„ƒYZdefd„ƒYZe	deƒdefd„ƒYZe	deƒdd#d„ƒYZdd$d „ƒYZyeWnej
o
eZnXdd%d!„ƒYZdS(&s+
csv.py - read/write/investigate CSV files
iÿÿÿÿN(treduce(tErrort__version__twritertreadertregister_dialecttunregister_dialecttget_dialectt
list_dialectstfield_size_limitt
QUOTE_MINIMALt	QUOTE_ALLtQUOTE_NONNUMERICt
QUOTE_NONEt__doc__(tDialect(tStringIOR
RRR
RRRtexcelt	excel_tabR	RRRRRtSnifferRRt
DictReadert
DictWritercBsVeZdZdZeZdZdZdZ	dZ
dZdZdZ
d„Zd„ZRS(sÇDescribe an Excel dialect.

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

    tcCs+|itjo
t|_n|iƒdS(N(t	__class__RtTruet_validt	_validate(tself((s/usr/lib/python2.6/csv.pyt__init__-s
cCs<yt|ƒWn'tj
o}tt|ƒƒ‚nXdS(N(t_Dialectt	TypeErrorRtstr(Rte((s/usr/lib/python2.6/csv.pyR2sN(t__name__t
__module__Rt_nametFalseRtNonet	delimitert	quotechart
escapechartdoublequotetskipinitialspacetlineterminatortquotingRR(((s/usr/lib/python2.6/csv.pyRs	cBs2eZdZdZdZeZeZdZ	e
ZRS(s;Describe the usual properties of Excel-generated CSV files.t,t"s
(R!R"RR&R'RR)R$R*R+R
R,(((s/usr/lib/python2.6/csv.pyR9scBseZdZdZRS(sEDescribe the usual properties of Excel-generated TAB-delimited files.s	(R!R"RR&(((s/usr/lib/python2.6/csv.pyRCss	excel-tabcBsPeZddddd„Zd„Zed„ƒZeid„ƒZd„ZRS(RcOsI||_||_||_t||||Ž|_||_d|_dS(Ni(t_fieldnamestrestkeytrestvalRtdialecttline_num(Rtft
fieldnamesR0R1R2targstkwds((s/usr/lib/python2.6/csv.pyRJs				cCs|S(N((R((s/usr/lib/python2.6/csv.pyt__iter__SscCsV|idjo0y|iiƒ|_Wq@tj
oq@Xn|ii|_|iS(N(R/R%Rtnextt
StopIterationR3(R((s/usr/lib/python2.6/csv.pyR5Vs	cCs
||_dS(N(R/(Rtvalue((s/usr/lib/python2.6/csv.pyR5`scCsì|idjo|in|iiƒ}|ii|_x!|gjo|iiƒ}q<Wtt|i|ƒƒ}t|iƒ}t|ƒ}||jo||||i<n7||jo)x&|i|D]}|i||<qÍWn|S(Ni(	R3R5RR9tdicttziptlenR0R1(Rtrowtdtlftlrtkey((s/usr/lib/python2.6/csv.pyR9ds"


N(	R!R"R%RR8tpropertyR5tsetterR9(((s/usr/lib/python2.6/csv.pyRIs		
cBs5eZdddd„Zd„Zd„Zd„ZRS(RtraiseRcOs[||_||_|iƒdjotd|‚n||_t||||Ž|_dS(NRFtignores-extrasaction (%s) must be 'raise' or 'ignore'(RFsignore(R5R1tlowert
ValueErrortextrasactionR(RR4R5R1RJR2R6R7((s/usr/lib/python2.6/csv.pyR|s			cCsž|idjo]g}|D]!}||ijo||qq~}|otddi|ƒƒ‚qmng}|iD]}||i||iƒq{~S(NRFs(dict contains fields not in fieldnames: s, (RJR5RItjointgetR1(Rtrowdictt_[1]tktwrong_fieldst_[2]RC((s/usr/lib/python2.6/csv.pyt
_dict_to_list‡s5cCs|ii|i|ƒƒS(N(RtwriterowRR(RRM((s/usr/lib/python2.6/csv.pyRSscCs=g}x$|D]}|i|i|ƒƒq
W|ii|ƒS(N(tappendRRRt	writerows(RtrowdictstrowsRM((s/usr/lib/python2.6/csv.pyRU’s
(R!R"RRRRSRU(((s/usr/lib/python2.6/csv.pyR{s

		cBs>eZdZd„Zdd„Zd„Zd„Zd„ZRS(se
    "Sniffs" the format of a CSV file (i.e. delimiter, quotechar)
    Returns a Dialect object.
    cCsdddddg|_dS(NR-s	t;t t:(t	preferred(R((s/usr/lib/python2.6/csv.pyR£scCsŽ|i||ƒ\}}}|p|i||ƒ\}}n|p
td‚ndtfd„ƒY}||_|pd|_||_|S(sI
        Returns a dialect (or None) corresponding to the sample
        sCould not determine delimiterR2cBs eZdZdZeZeZRS(tsniffeds
(R!R"R#R+R
R,R$R)(((s/usr/lib/python2.6/csv.pyR2¶sR.(t_guess_quote_and_delimitert_guess_delimiterRRR&R'R*(Rtsamplet
delimitersR'R&R*R2((s/usr/lib/python2.6/csv.pytsniff¨s	
		cCsüg}xEdD]=}ti|titiBƒ}|i|ƒ}|oPq
q
W|pdSh}h}d}x|D]}	|idd}
|	|
}|o|i|dƒd||<ny|id	d}
|	|
}Wntj
o
qsnX|o8|djp
||jo|i|dƒd||<ny|id
d}
Wntj
o
qsnX|	|
o|d7}qsqsWt	|d„|i
ƒƒ}|oFt	|d„|i
ƒƒ}
||
|j}|
d
jo
d}
qïn
d}
d}||
|fS(s
        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.
        sF(?P<delim>[^\w
"'])(?P<space> ?)(?P<quote>["']).*?(?P=quote)(?P=delim)sC(?:^|
)(?P<quote>["']).*?(?P=quote)(?P<delim>[^\w
"'])(?P<space> ?)sD(?P<delim>>[^\w
"'])(?P<space> ?)(?P<quote>["']).*?(?P=quote)(?:$|
)s*(?:^|
)(?P<quote>["']).*?(?P=quote)(?:$|
)RitquoteitdelimtspacecSs ||||jo|p|S(((tatbtquotes((s/usr/lib/python2.6/csv.pyt<lambda>ôscSs ||||jo|p|S(((ReRftdelims((s/usr/lib/python2.6/csv.pyRhøss
(sF(?P<delim>[^\w
"'])(?P<space> ?)(?P<quote>["']).*?(?P=quote)(?P=delim)sC(?:^|
)(?P<quote>["']).*?(?P=quote)(?P<delim>[^\w
"'])(?P<space> ?)sD(?P<delim>>[^\w
"'])(?P<space> ?)(?P<quote>["']).*?(?P=quote)(?:$|
)s*(?:^|
)(?P<quote>["']).*?(?P=quote)(?:$|
)N(RNi(tretcompiletDOTALLt	MULTILINEtfindallR%t
groupindexRLtKeyErrorRtkeys(RtdataR`tmatchestrestrtregexpRgRitspacestmtnRCR'RcR*((s/usr/lib/python2.6/csv.pyR]ÅsZ	
!
cCs1td|idƒƒ}g}tdƒD]}|t|ƒq)~}tdt|ƒƒ}d}h}h}	h}
dt|t|ƒƒ}}x¢|t|ƒjoŽ|d7}xk|||!D]\}
xS|D]K}|i|hƒ}|
i|ƒ}|i|dƒd||<|||<qÉWq¼WxÓ|i	ƒD]Å}||i
ƒ}t|ƒdjo|dddjoq)nt|ƒdjo_td„|ƒ|	|<|i|	|ƒ|	|d|	|dtd„|ƒdf|	|<q)|d|	|<q)W|	i
ƒ}t
||ƒ}d}d	}x©t|
ƒdjo•||joˆxw|D]o\}}|ddjoR|ddjoA|d||jo(|djp
||jo||
|<q³qDqDW|d
8}qWt|
ƒdjoE|
i	ƒd}|di|ƒ|did|ƒj}||fS|}||7}q‘W|
pdSt|
ƒdjo`x]|iD]N}||
i	ƒjo5|di|ƒ|did|ƒj}||fSq\Wng}|
i
ƒD]\}}|||fqÃ~}|iƒ|d
d}|di|ƒ|did|ƒj}||fS(s¼
        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 freqencies 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.
        s
ii
iicSs |d|djo|p|S(i((ReRf((s/usr/lib/python2.6/csv.pyRh4scSsd|d|dfS(ii((ReRf((s/usr/lib/python2.6/csv.pyRh:sgð?gÍÌÌÌÌÌì?g{®Gáz„?s%c RiÿÿÿÿN(Ri(tfilterR%tsplittrangetchrtminR>RLtcountRqtitemsRtremovetfloatR[tsort(RRrR`RNtctasciitchunkLengtht	iterationt
charFrequencytmodesRitstarttendtlinetchart
metaFrequencytfreqRtmodeListttotaltconsistencyt	thresholdROtvRcR*R@RQ((s/usr/lib/python2.6/csv.pyR^s†-

(	
	 "
3
c
Cs*tt|ƒ|i|ƒƒ}|iƒ}t|ƒ}h}xt|ƒD]}d||<qIWd}x	|D]}|djoPn|d7}t|ƒ|joqjnxÂ|iƒD]´}	xYtt	t
tgD]5}
y|
||	ƒPWqÌtt
fj
oqÌXqÌWt||	ƒ}
|
t	jo
t}
n|
||	jo*||	djo|
||	<qg||	=q³q³WqjWd}x¨|iƒD]š\}	}t|ƒtdƒjo3t||	ƒ|jo|d7}q|d8}q‚y|||	ƒWn#ttfj
o|d7}q‚X|d8}q‚W|djS(Niii(RRRaR9R>R{R%RqtinttlongRtcomplexRIt
OverflowErrorRttypeR(
RR_trdrtheadertcolumnstcolumnTypestitcheckedR?tcoltthisTypet	hasHeadertcolType((s/usr/lib/python2.6/csv.pyt
has_headernsX




	


N(	R!R"RRR%RaR]R^R£(((s/usr/lib/python2.6/csv.pyRžs		@	i((((( RRjt	functoolsRt_csvRRRRRRRRR	R
RRR
RRt	cStringIORtImportErrort__all__RRRRR–t	NameErrorRR(((s/usr/lib/python2.6/csv.pyt<module>s2^	

2

ACC SHELL 2018