[ Avaa Bypassed ]




Upload:

Command:

hmhc3928@18.216.32.251: ~ $


R6�WX-�@skdZddlZddlZddlZddlZddlmZyddlmZWn"ek
r~ddl	mZYnXddl
Tddl
mZddl
mZddl
m
Z
e
r�eZd	Znd
ZGdd�de�Zd
d�ZGdd�de�ZGdd�de�Zddd
dddd	dd�Zeje_d
d
d
ddd�ZdS)a
Peewee helper for loading CSV data into a database.

Load the users CSV file into the database and return a Model for accessing
the data:

    from playhouse.csv_loader import load_csv
    db = SqliteDatabase(':memory:')
    User = load_csv(db, 'users.csv')

Provide explicit field types and/or field names:

    fields = [IntegerField(), IntegerField(), DateTimeField(), DecimalField()]
    field_names = ['from_acct', 'to_acct', 'timestamp', 'amount']
    Payments = load_csv(db, 'payments.csv', fields, field_names)
�N)�contextmanager)�StringIO)�*)�Database)�Func)�PY3FTc@s"eZdZedd��ZdS)�
_CSVReadercks�d}t|t�r't|d�}n>t|t�rL|}|jd�n|}|jd�d}tj||�}|V|r�|j�dS)NF�rrT)�
isinstance�
basestring�openr�seek�csv�reader�close)�self�file_or_name�
reader_kwargs�is_file�fhr�r�
/csv_utils.py�
get_reader's
z_CSVReader.get_readerN)�__name__�
__module__�__qualname__rrrrrrr&srcs��fdd�}|S)Ncs��fdd�|_|S)Ncs
���S)Nrr)�field_class�field_kwargsrr�<lambda>:sz2convert_field.<locals>.decorator.<locals>.<lambda>)�field)�fn)rrrr�	decorator9sz convert_field.<locals>.decoratorr)rrr!r)rrr�
convert_field8sr"c@seZdZdZddgZddgZdddd	�Zd
d�Zee	dd
�dd��Z
eedd
�dd��Zee
dd�dd��Zeedd�dd��Zeedd�dd��Zdd�Zdd�Zdd�Zd S)!�RowConvertera
    Simple introspection utility to convert a CSV file into a list of headers
    and column types.

    :param database: a peewee Database object.
    :param bool has_header: whether the first row of CSV is a header row.
    :param int sample_size: number of rows to introspect
    z%Y-%m-%dz%m/%d/%Yz%Y-%m-%d %H:%M:%Sz%Y-%m-%d %H:%M:%S.%fT�
cCs||_||_||_dS)N)�database�
has_header�sample_size)rr%r&r'rrr�__init__Os		zRowConverter.__init__cCsEx>|D]6}ytjj||�Wntk
r8YqXdSqWdS)NT)�datetime�strptime�
ValueError)r�value�formats�fmtrrr�matches_dateTs

zRowConverter.matches_date�defaultrcCs
|j�S)N)�isdigit)rr,rrr�
is_integer]szRowConverter.is_integercCs1yt|�Wnttfk
r(YnXdSdS)NT)�floatr+�	TypeError)rr,rrr�is_floatas
zRowConverter.is_floatZnullcCs|j||j�S)N)r/�datetime_formats)rr,rrr�is_datetimejszRowConverter.is_datetimecCs|j||j�S)N)r/�date_formats)rr,rrr�is_datenszRowConverter.is_date�cCsdS)NTr)rr,rrrr0rszRowConverter.defaultc	Ks�g}|j}|j||��T}|jr7|d7}x7t|�D])\}}|j|�||jkrDPqDWWdQRX|jr�|d|dd�}}n#dd�tt|d��D�}||fS)aq
        Extract `self.sample_size` rows from the CSV file and analyze their
        data-types.

        :param str file_or_name: A string filename or a file handle.
        :param reader_kwargs: Arbitrary parameters to pass to the CSV reader.
        :returns: A 2-tuple containing a list of headers and list of rows
                  read from the CSV file.
        �NrcSsg|]}d|�qS)zfield_%dr)�.0�irrr�
<listcomp>�s	z-RowConverter.extract_rows.<locals>.<listcomp>)r'rr&�	enumerate�append�range�len)	rrr�rowsZrows_to_readrr=�row�headerrrr�extract_rowsvs
		

	#zRowConverter.extract_rowscCs"|j|j|j|j|jgS)z6Return a list of functions to use when testing values.)r9r7r2r5r0)rrrr�
get_checks�s
zRowConverter.get_checksc	s�t|�}|j�}g}x}t|�D]o\}}dd�|D�}xM|D]E�t�fdd�|D��}t|�rQ|j�j��PqQWq+W|S)a
        Analyze the given rows and try to determine the type of value stored.

        :param list rows: A list-of-lists containing one or more rows from a
                          csv file.
        :returns: A list of peewee Field objects for each column in the CSV.
        cSs"g|]}|dkr|�qS)r:r)r<�valrrrr>�s	z(RowConverter.analyze.<locals>.<listcomp>c3s|]}�|�VqdS)Nr)r<rH)�checkrr�	<genexpr>�sz'RowConverter.analyze.<locals>.<genexpr>)�ziprGr?�set�allr@r)	rrCZ
transposedZchecksZcolumn_typesr=�columnZcol_vals�resultsr)rIr�analyze�s
	zRowConverter.analyzeN)rrr�__doc__r8r6r(r/r"�IntegerFieldr2Z
FloatFieldr5Z
DateTimeFieldr7Z	DateFieldr9Z	BareFieldr0rFrGrPrrrrr#>s					r#c	@sseZdZdZddddddddd�Zdd	�Zd
d�Zdd
�Zdd�Zdd�Z	dS)�Loaderat
    Load the contents of a CSV file into a database and return a model class
    suitable for working with the CSV data.

    :param db_or_model: a peewee Database instance or a Model class.
    :param file_or_name: the filename of the CSV file *or* a file handle.
    :param list fields: A list of peewee Field() instances appropriate to
        the values in the CSV file.
    :param list field_names: A list of names to use for the fields.
    :param bool has_header: Whether the first row of the CSV file is a header.
    :param int sample_size: Number of rows to introspect if fields are not
        defined.
    :param converter: A RowConverter instance to use.
    :param str db_table: Name of table to store data in (if not specified, the
        table name will be derived from the CSV filename).
    :param reader_kwargs: Arbitrary arguments to pass to the CSV reader.
    NTr$Fc
Ksj||_||_||_||_||_||_|
|_t|t�rZ||_	n't|t
�rud|_	n|j|_	t|t�r�||_
d|_|p�tjjtjj|j	��d|_n�||_|jjj
|_
|jjj|_|jjj|_|jjj|_|jjjrf|	rf|jdd�|_|jdd�|_dS)Nzdata.csvrr;)r�fields�field_namesr&r'�	converterrr
r�filenamer�namerr%�model�os�path�splitext�basename�db_table�_metaZ
sorted_fieldsZsorted_field_namesZauto_increment)r�db_or_modelrrTrUr&r'rVr^�	pk_in_csvrrrrr(�s2									+	zLoader.__init__cCstjdd|j��S)Nz
[^a-z0-9]+�_)�re�sub�lower)r�srrr�clean_field_name�szLoader.clean_field_namecCs(|jp't|jd|jd|j�S)Nr&r')rVr#r%r&r')rrrr�
get_converter�s		zLoader.get_convertercs��j���j�j�j�\}}|rE�j|��_n�fdd�|D��_�js��fdd�|D��_dS)Ncsg|]}�jj��qSr)r0r)r<rb)rVrrr>�s	z&Loader.analyze_csv.<locals>.<listcomp>csg|]}�j|��qSr)rg)r<�col)rrrr>�s	)rhrFrrrPrTrU)rrErCr)rVrr�analyze_csv�s	zLoader.analyze_csvcCs�|jr|jStt||��}d|krAt�|d<n t|dt�rat�|d<t|jj�t	f|�}|j
|j_
|j|j_|S)N�idZ_auto_pk)rY�dictrKZPrimaryKeyFieldr
rR�typer^�titleZModelr%r_)rrUrTZattrs�klassrrr�get_model_class�s	
zLoader.get_model_classcss�js�j��jrL�jrLdd�tt�j��D��_�j�j�j�}|�}�js�t	|�}�fdd�|D��_n�jr�t	|��j
�j�j�}�jj���|j
d�xu|D]m}i}xEt�j|�D]1\}}|rtr6|jd�}|||<qW|r�|j|�j�q�WWdQRXWdQRX|S)NcSsg|]}d|�qS)zfield_%dr)r<r=rrrr>
s	zLoader.load.<locals>.<listcomp>csg|]}�j|��qSr)rg)r<ri)rrrr>s	Tzutf-8)rTrjrUr&rArBrrr�nextrpr%ZtransactionZcreate_tablerK�decode_value�decode�insertZexecute)rZ
reader_objrrDZ
ModelClassrt�
field_namer,r)rr�loads0	
%			


%zLoader.load)
rrrrQr(rgrhrjrprvrrrrrS�s	#
rSr$c	KsLtd|d|d|d|d|d|d|d|d	||	�	}
|
j�S)
Nr`rrTrUr&r'rVr^ra)rSrv)r`rrTrUr&r'rVr^rar�loaderrrr�load_csv's	rxcCs?t|t�r-t||r!dp$d�}n|}|rI|jdd�|pptj|ddddd	tj�}|rg}xrt|j�D]a\}	}
|
j	r�|j
|
j	�q�t|
ttf�r�|j
|
j
�q�|j
d
|	�q�W|j|�x'|j�j�D]}|j|�qW|r;|j�|S)z'
    Create a CSV dump of a query.
    �a�wr��	delimiter�,Z	quotechar�"Zquotingzcol_%s)r
rrr
r�writerZ
QUOTE_MINIMALr?�_selectZ_aliasr@ZFieldrrXZwriterowZtuples�iteratorr)ZqueryrZinclude_headerZ
close_filer@Z
csv_writerrrrE�idxZnoderDrrr�dump_csv9s0	

r�)rQrr)rZrc�
contextlibrr�ImportError�ioZpeeweerrr�strrrr�objectrr"r#rSrxr�rrrr�<module>s6

	qx	

Filemanager

Name Type Size Permission Actions
__init__.cpython-35.opt-1.pyc File 95 B 0644
__init__.cpython-35.pyc File 95 B 0644
apsw_ext.cpython-35.opt-1.pyc File 7.47 KB 0644
apsw_ext.cpython-35.pyc File 7.47 KB 0644
berkeleydb.cpython-35.opt-1.pyc File 3.2 KB 0644
berkeleydb.cpython-35.pyc File 3.2 KB 0644
csv_loader.cpython-35.opt-1.pyc File 135 B 0644
csv_loader.cpython-35.pyc File 135 B 0644
csv_utils.cpython-35.opt-1.pyc File 11.43 KB 0644
csv_utils.cpython-35.pyc File 11.43 KB 0644
dataset.cpython-35.opt-1.pyc File 13.38 KB 0644
dataset.cpython-35.pyc File 13.38 KB 0644
db_url.cpython-35.opt-1.pyc File 3.16 KB 0644
db_url.cpython-35.pyc File 3.16 KB 0644
djpeewee.cpython-35.opt-1.pyc File 5.76 KB 0644
djpeewee.cpython-35.pyc File 5.76 KB 0644
fields.cpython-35.opt-1.pyc File 12.7 KB 0644
fields.cpython-35.pyc File 12.7 KB 0644
flask_utils.cpython-35.opt-1.pyc File 5.93 KB 0644
flask_utils.cpython-35.pyc File 5.97 KB 0644
gfk.cpython-35.opt-1.pyc File 6.02 KB 0644
gfk.cpython-35.pyc File 6.02 KB 0644
hybrid.cpython-35.opt-1.pyc File 2.15 KB 0644
hybrid.cpython-35.pyc File 2.15 KB 0644
kv.cpython-35.opt-1.pyc File 6.77 KB 0644
kv.cpython-35.pyc File 6.77 KB 0644
migrate.cpython-35.opt-1.pyc File 22.68 KB 0644
migrate.cpython-35.pyc File 22.68 KB 0644
pool.cpython-35.opt-1.pyc File 7.96 KB 0644
pool.cpython-35.pyc File 7.96 KB 0644
postgres_ext.cpython-35.opt-1.pyc File 16.86 KB 0644
postgres_ext.cpython-35.pyc File 16.86 KB 0644
read_slave.cpython-35.opt-1.pyc File 1.75 KB 0644
read_slave.cpython-35.pyc File 1.75 KB 0644
reflection.cpython-35.opt-1.pyc File 18.58 KB 0644
reflection.cpython-35.pyc File 18.58 KB 0644
shortcuts.cpython-35.opt-1.pyc File 5.65 KB 0644
shortcuts.cpython-35.pyc File 5.65 KB 0644
signals.cpython-35.opt-1.pyc File 3.04 KB 0644
signals.cpython-35.pyc File 3.04 KB 0644
sqlcipher_ext.cpython-35.opt-1.pyc File 4.52 KB 0644
sqlcipher_ext.cpython-35.pyc File 4.52 KB 0644
sqlite_ext.cpython-35.opt-1.pyc File 36.56 KB 0644
sqlite_ext.cpython-35.pyc File 36.65 KB 0644
sqlite_udf.cpython-35.opt-1.pyc File 16.76 KB 0644
sqlite_udf.cpython-35.pyc File 16.76 KB 0644
test_utils.cpython-35.opt-1.pyc File 4.03 KB 0644
test_utils.cpython-35.pyc File 4.08 KB 0644