U S��WX- � @ s� d Z ddlZddlZddlZddlZddlmZ zddlmZ W n ek r` ddl mZ Y nX ddl T ddl mZ ddl mZ ddl m Z e r�eZd Znd ZG dd� de�Zd d� ZG dd� de�ZG dd� de�Zddd�Zej e_ 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 e Zd Zedd� �ZdS )� _CSVReaderc k sj d}t |t�rt|d�}n,t |t�r4|}|�d� n|}|�d� d}tj|f|�}|V |rf|�� d S )NF�rr T)� isinstance� basestring�openr �seek�csv�reader�close)�self�file_or_name� reader_kwargs�is_file�fhr � r � /csv_utils.py� get_reader'