3

hNa#@s<ddZddZddZddZdd	Zd
dZdd
ZdS)cCs|ddlm}ddl}d}d}g}||}|j||||jdd}x8|D]0}i}	x|jD]\}
}||	|
<qVW|j|	qDW|S)N)StringIO,"T)	delimiterZ	quotecharZquotingZskipinitialspace)iorcsvZ
DictReaderZ	QUOTE_ALLitemsappend)	csvStringrrdelimquote	list_dictZcsvFileZlist_list_tupleZ
list_tupledictcol_name	col_valuer3/home/s/sultans/web/python/demo/etl/util/convert.pycsv2objs
rcCsddl}|jd}g}i}|jd|d}xtdt|dD]}d}d}xF||D]:}	|	dksh|	dkrv|rrd}nd	}|	d
kr|rd}	||	7}qTW|jd|}
d}xN|
D]F}|jdd
|}|jdd|}|jdd|}||}
|||
<|d7}qW|j|i}q>W|S)Nr
z\s*,\s*Fr'Tr~)resplitrangelensubr	)r
rlinesr
r	col_namesidxZ
col_stringreplacechar
col_valuesirrrrrcsv2obj_custom(s8


r%cCsddl}|j|}|S)Nr)jsonloads)Z
jsonStringr&r
rrrjson2objOs
r(c	Cslddl}|jd}g}i}xL|D]D}|jd|}|rR|jd}|jd}|||<q |r |j|i}q W|S)Nrrz<(.+?)>(.*?)</.+?>r)rrsearchgroupr	)	Z	xmlStringrrr
rlinefoundrrrrrxml2obj\s





r.cCsd}|dj}|dj|d7}xX|D]P}x,|jD] \}}d|kr6d|d||<q6W|j}|dj|7}|d7}q(W|S)Nrrz, rrr)keysjoinrvalues)r
rrrrrr#rrrobj2csvvs
r2cCsddl}|j|dd}|S)Nr)indent)r&dumps)r
r&rrrobj2jsonsr6c
Cstd}d}|d7}xV|D]N}|d7}x8|jD],\}}|d7}|d|d|d|d	7}q,W|d
7}qW|d7}|S)Nrz<?xml version='1.0'?>
z<root> 
z    <row> 
z        <>z</z> 
z    </row> 
z	</root> 
)r)r
Zxmlrnamevaluerrrobj2xmls
 r;N)rr%r(r.r2r6r;rrrr<module>s'