<s> from __future__ import print_function <EOL> from __future__ import unicode_literals <EOL> import contextlib <EOL> import os <EOL> try : <EOL> from urllib . parse import quote as urlquote <EOL> except ImportError : <EOL> from urllib import quote as urlquote <EOL> class ImportAPI ( object ) : <EOL> def import_data ( self , db , table , format , bytes_or_stream , size , unique_id = None ) : <EOL> """<STR_LIT>""" <EOL> if unique_id is not None : <EOL> path = "<STR_LIT>" % ( urlquote ( str ( db ) ) , urlquote ( str ( table ) ) , urlquote ( str ( unique_id ) ) , urlquote ( str ( format ) ) ) <EOL> else : <EOL> path = "<STR_LIT>" % ( urlquote ( str ( db ) ) , urlquote ( str ( table ) ) , urlquote ( str ( format ) ) ) <EOL> kwargs = { } <EOL> with self . put ( path , bytes_or_stream , size , ** kwargs ) as res : <EOL> code , body = res . status , res . read ( ) <EOL> if code / <NUM_LIT:100> != <NUM_LIT:2> : <EOL> self . raise_error ( "<STR_LIT>" , res , body ) <EOL> js = self . checked_json ( body , [ "<STR_LIT>" ] ) <EOL> time = float ( js [ "<STR_LIT>" ] ) <EOL> return time <EOL> def import_file ( self , db , table , format , file , unique_id = None , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> with contextlib . closing ( self . _prepare_file ( file , format , ** kwargs ) ) as fp : <EOL> size = os . fstat ( fp . fileno ( ) ) . st_size <EOL> return self . import_data ( db , table , "<STR_LIT>" , fp , size , unique_id = unique_id ) </s>
