@@ -197,13 +197,14 @@ async def _clone(self, s3_bucket, s3_object_key):
197197 self .log .info (f"Processing clone of { s3_object_key } " )
198198 try :
199199 obj = await client .get_object (Bucket = s3_bucket , Key = s3_object_key )
200+ content = (await obj ['Body' ].read ()).decode ('utf-8' )
200201 except ClientError as e :
201202 status_code = e .response ['ResponseMetadata' ].get ('HTTPStatusCode' )
202203 raise web .HTTPError (status_code , e .args [0 ])
203204
204205 self .log .info (f"Obtained contents for { s3_object_key } " )
205206
206- return obj
207+ return obj , content
207208
208209 @web .authenticated
209210 async def post (self ):
@@ -237,9 +238,9 @@ async def post(self):
237238 )
238239
239240 self .log .info (f"About to clone from { s3_object_key } " )
240- obj = await self ._clone (s3_bucket , s3_object_key )
241+ obj , content = await self ._clone (s3_bucket , s3_object_key )
241242
242- content_model = await self .build_content_model (obj , target_path )
243+ content_model = self .build_content_model (content , target_path )
243244
244245 self .log .info (f"Completing clone for { s3_object_key } " )
245246 self .contents_manager .save (content_model , content_model ['path' ])
@@ -250,15 +251,15 @@ async def post(self):
250251 self .set_header ('Content-Type' , 'application/json' )
251252 self .finish (resp_model )
252253
253- async def build_content_model (self , obj , target_path ):
254+ def build_content_model (self , content , target_path ):
254255 """Helper that takes a response from S3 and creates a ContentsAPI compatible model.
255256
256257 If the file at target_path already exists, this increments the file name.
257258
258259 Parameters
259260 ----------
260- obj : dict
261- Response object from S3
261+ content : str
262+ string encoded file content
262263 target_path : str
263264 The the path we wish to clone to, may be incremented if already present.
264265
@@ -268,8 +269,6 @@ async def build_content_model(self, obj, target_path):
268269 Jupyter Contents API compatible model
269270 """
270271 path = self .contents_manager .increment_filename (target_path )
271- content = await obj ['Body' ].read ()
272- content = content .decode ('utf-8' )
273272 if os .path .splitext (path )[1 ] in [".ipynb" , ".jpynb" ]:
274273 model = build_notebook_model (content , path )
275274 else :
0 commit comments