#NEWLINE# @ gen . coroutine #NEWLINE# def _Check( self ) : #NEWLINE# #INDENT# "Check and prepare for remove.\n    Along with checks, builds two lists for the Update phase.\n    1) self._contacts_to_delete: list of contacts which have been superseded by more recent\n        contacts with the same contact_id and because they no longer serve any purpose should\n        be deleted.  These may exist due to lack of transactional atomicity when replacing\n        a contact as part of removal or upload.  If too many removed contacts are or will exist, this\n        list will also contain all of the removed contacts as well as any contacts that are\n        part of the removal request.\n    2) self._contacts_to_remove: list of contacts which should be transitioned to 'removed', but\n        currently are not in the 'removed' state.\n    " #NEWLINE# for request_contact_id in self . _request_contact_ids : #NEWLINE# #INDENT# if ( Contact . GetContactSourceFromContactId ( request_contact_id ) not in Contact . UPLOAD_SOURCES ) : #NEWLINE# #INDENT# raise InvalidRequestError ( BAD_CONTACT_SOURCE , Contact . GetContactSourceFromContactId ( request_contact_id ) ) #NEWLINE# #UNINDENT# #UNINDENT# ( existing_contacts_dict , self . _contacts_to_delete ) = ( yield RemoveContactsOperation . _GetAllContactsWithDedup ( self . _client , self . _user_id ) ) #NEWLINE# removed_contact_count = 0 #NEWLINE# for existing_contact in existing_contacts_dict . itervalues ( ) : #NEWLINE# #INDENT# if existing_contact . IsRemoved ( ) : #NEWLINE# #INDENT# removed_contact_count += 1 #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( existing_contact . contact_id in self . _request_contact_ids ) : #NEWLINE# #INDENT# self . _contacts_to_remove . append ( existing_contact ) #NEWLINE# removed_contact_count += 1 #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# if ( removed_contact_count >= Contact . MAX_REMOVED_CONTACTS_LIMIT ) : #NEWLINE# #INDENT# self . _removed_contacts_reset = True #NEWLINE# #UNINDENT# if ( self . _op . checkpoint is None ) : #NEWLINE# #INDENT# ( yield self . _op . SetCheckpoint ( self . _client , { #NEWLINE# #INDENT# 'removed_contacts_reset' : self . _removed_contacts_reset , #NEWLINE# #UNINDENT# } ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( not self . _removed_contacts_reset ) : #NEWLINE# #INDENT# self . _removed_contacts_reset = self . _op . checkpoint [ 'removed_contacts_reset' ] #NEWLINE# #UNINDENT# #UNINDENT# if self . _removed_contacts_reset : #NEWLINE# #INDENT# for existing_contact in existing_contacts_dict . itervalues ( ) : #NEWLINE# #INDENT# if ( existing_contact . IsRemoved ( ) or ( existing_contact . contact_id in self . _request_contact_ids ) ) : #NEWLINE# #INDENT# self . _contacts_to_delete . append ( existing_contact )