#NEWLINE# def _upload_from_file_helper( self , **kw ) : #NEWLINE# #INDENT# import csv #NEWLINE# import datetime #NEWLINE# from six.moves.http_client import OK #NEWLINE# from gcloud._helpers import UTC #NEWLINE# from gcloud._testing import _NamedTemporaryFile #NEWLINE# from gcloud.bigquery.table import SchemaField #NEWLINE# WHEN_TS = 1437767599.006 #NEWLINE# WHEN = datetime . datetime . utcfromtimestamp ( WHEN_TS ) . replace ( tzinfo = UTC ) #NEWLINE# PATH = ( 'projects/%s/jobs' % ( self . PROJECT , ) ) #NEWLINE# response = { #NEWLINE# #INDENT# 'status' : OK , #NEWLINE# #UNINDENT# } #NEWLINE# conn = _Connection ( ( response , b'{}' ) ) #NEWLINE# client = _Client ( project = self . PROJECT , connection = conn ) #NEWLINE# expected_job = object ( ) #NEWLINE# if ( 'client' in kw ) : #NEWLINE# #INDENT# kw [ 'client' ] . _job = expected_job #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# client . _job = expected_job #NEWLINE# #UNINDENT# dataset = _Dataset ( client ) #NEWLINE# full_name = SchemaField ( 'full_name' , 'STRING' , mode = 'REQUIRED' ) #NEWLINE# age = SchemaField ( 'age' , 'INTEGER' , mode = 'REQUIRED' ) #NEWLINE# joined = SchemaField ( 'joined' , 'TIMESTAMP' , mode = 'NULLABLE' ) #NEWLINE# table = self . _makeOne ( self . TABLE_NAME , dataset = dataset , schema = [ full_name , age , joined ] ) #NEWLINE# ROWS = [ ( 'Phred Phlyntstone' , 32 , WHEN ) , ( 'Bharney Rhubble' , 33 , ( WHEN + datetime . timedelta ( seconds = 1 ) ) ) , ( 'Wylma Phlyntstone' , 29 , ( WHEN + datetime . timedelta ( seconds = 2 ) ) ) , ( 'Bhettye Rhubble' , 27 , None ) ] #NEWLINE# with _NamedTemporaryFile ( ) as temp : #NEWLINE# #INDENT# with open ( temp . name , 'w' ) as file_obj : #NEWLINE# #INDENT# writer = csv . writer ( file_obj ) #NEWLINE# writer . writerow ( ( 'full_name' , 'age' , 'joined' ) ) #NEWLINE# writer . writerows ( ROWS ) #NEWLINE# #UNINDENT# with open ( temp . name , 'rb' ) as file_obj : #NEWLINE# #INDENT# BODY = file_obj . read ( ) #NEWLINE# explicit_size = kw . pop ( '_explicit_size' , False ) #NEWLINE# if explicit_size : #NEWLINE# #INDENT# kw [ 'size' ] = len ( BODY ) #NEWLINE# #UNINDENT# job = table . upload_from_file ( file_obj , 'CSV' , rewind = True , ** kw ) #NEWLINE# #UNINDENT# #UNINDENT# self . assertTrue ( ( job is expected_job ) ) #NEWLINE# return ( conn . http . _requested , PATH , client )