#NEWLINE# @ classmethod #NEWLINE# @ gen . coroutine #NEWLINE# def _CheckCopyTargets( cls , action , client , user_id , viewpoint_id , target_ep_dicts ) : #NEWLINE# #INDENT# 'Compiles a list of target episode and post ids that do not exist or are removed. These\n    episodes and posts will not be copied as part of the operation.\n\n    Returns the set of target episode and post ids that will be (re)created by the caller.\n    ' #NEWLINE# episode_keys = [ ] #NEWLINE# post_keys = [ ] #NEWLINE# for ep_dict in target_ep_dicts : #NEWLINE# #INDENT# episode_keys . append ( DBKey ( ep_dict [ 'episode_id' ] , None ) ) #NEWLINE# for photo_id in ep_dict [ 'photo_ids' ] : #NEWLINE# #INDENT# post_keys . append ( DBKey ( ep_dict [ 'episode_id' ] , photo_id ) ) #NEWLINE# #UNINDENT# #UNINDENT# ( episodes , posts ) = ( yield [ gen . Task ( Episode . BatchQuery , client , episode_keys , None , must_exist = False ) , gen . Task ( Post . BatchQuery , client , post_keys , None , must_exist = False ) ] ) #NEWLINE# new_ids = set ( ) #NEWLINE# post_iter = iter ( posts ) #NEWLINE# for ( ep_dict , episode ) in zip ( target_ep_dicts , episodes ) : #NEWLINE# #INDENT# if ( episode is None ) : #NEWLINE# #INDENT# new_ids . add ( episode_keys [ 'episode_id' ] ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# assert ( episode . user_id == user_id ) , ( episode , user_id ) #NEWLINE# if ( episode . parent_ep_id != ep_dict [ 'parent_ep_id' ] ) : #NEWLINE# #INDENT# raise InvalidRequestError ( ( 'Cannot %s to episode "%s". It was created from a different parent episode.' % ( action , ep_dict [ 'episode_id' ] ) ) ) #NEWLINE# #UNINDENT# if ( episode . viewpoint_id != viewpoint_id ) : #NEWLINE# #INDENT# raise InvalidRequestError ( ( 'Cannot %s to episode "%s". It is not in viewpoint "%s".' % ( action , episode . episode_id , viewpoint_id ) ) ) #NEWLINE# #UNINDENT# #UNINDENT# for photo_id in ep_dict [ 'photo_ids' ] : #NEWLINE# #INDENT# post = next ( post_iter ) #NEWLINE# if ( ( post is None ) or post . IsRemoved ( ) ) : #NEWLINE# #INDENT# new_ids . add ( Post . ConstructPostId ( ep_dict [ 'episode_id' ] , photo_id ) ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# raise gen . Return ( new_ids )