当前位置: 首页>>代码示例>>Python>>正文


Python register.StateRegister类代码示例

本文整理汇总了Python中filerockclient.serversession.states.register.StateRegister的典型用法代码示例。如果您正苦于以下问题:Python StateRegister类的具体用法?Python StateRegister怎么用?Python StateRegister使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了StateRegister类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _handle_message_SYNC_ENCRYPTED_FILES_IVS

    def _handle_message_SYNC_ENCRYPTED_FILES_IVS(self, message):
        """We have asked the server to send the IVs for some of the
        encrypted files, here they are. Now it's possible to proceed
        with the synchronization as usual.

        ServerSession needs the etag for both the cleartext and the
        encrypted versions of an encrypted file to correctly detect
        changes. If the storage cache is not available then we need
        to encrypt the files again in order to read their etag. The
        same IVs used the encrypt the first time must be used.

        Basically ServerSession receives this message only if there
        are some encrypted files but there is no storage cache available
        for them.
        """
        self.logger.debug(u"Recomputing the etag for encrypted conflicted pathnames...")
        server_ivs = message.getParameter('ivs')
        server_ivs_notNone = {
            key: server_ivs[key]
            for key in filter(
                lambda key: server_ivs[key] is not None, server_ivs
            )
        }

        try:
            self.logger.debug("I'm going to recalculate all encrypted etags")
            enc_etags = CryptoHelpers.recalc_encrypted_etag(
                                                    server_ivs_notNone,
                                                    self._context.warebox,
                                                    self._context.cfg,
                                                    self._context.must_die)
            self.logger.debug("Encrypted etags recalculated")
        except ExecutionInterrupted:
            self.logger.debug(u'ExecutionInterrupted, terminating...')
            self._set_next_state(StateRegister.get('DisconnectedState'))
            return
        #self.logger.debug(u"Finished recomputing the etag for encrypted conflicted pathnames.")
        #self.logger.debug('IVs received from server\n %r' % server_ivs)
        #self.logger.debug('IVs NotNone\n %r' % server_ivs_notNone)
        #self.logger.debug('encrypted Etag\n %r' % enc_etags)
        #self.logger.debug('Remote Etag\n %r' % self._context.startup_synchronization.remote_etag)
        self._context.startup_synchronization.update_conflicts_of_encrypted_pathnames(enc_etags)

        try:
            if self._check_hash_mismatch():
                self._start_syncing()
            else:
#                self._internal_facade.terminate()
                self._context._internal_facade.pause()
        except HashMismatchException as excp:
            self.logger.critical('Integrity Error %s' % excp)
            self._set_next_state(StateRegister.get('IntegrityErrorState'))
开发者ID:alepharchives,项目名称:FileRock-Client,代码行数:52,代码来源:sync_diff.py

示例2: setup_fixtures

def setup_fixtures(adapter_mock, workerpool_mock, connection_lifekeeper,
                   disconnectedstate_cls_mock, downloadstate_cls_mock):

    from filerockclient.serversession.states.register import StateRegister

    components = setup_server_session(
                        __file__,
                        adapter_mock, workerpool_mock, connection_lifekeeper,
                        disconnectedstate_cls_mock, downloadstate_cls_mock)

    # Note: the StateRegister singleton has been initialized by
    # ServerSession's constructor
    syncstart_state = StateRegister.get('SyncStartState')

    # DisconnectedState is the default initial state, but we want to start
    # from SyncStartState
    disconnected_state_mock = disconnectedstate_cls_mock()
    disconnected_state_mock.do_execute.return_value = syncstart_state

    def fail():
        msg = "ServerSession has attempted to start downloading although an" \
              " integrity error was expected"
        assert_true(False, msg)

    # If we get into SyncDownloadingLeavesState, it means we have
    # passed the integrity check. But we shouldn't had to!
    download_state_mock = downloadstate_cls_mock()
    download_state_mock.do_execute.side_effect = fail

    def ask_user(what, content, client_basis, server_basis):
        if what == 'accept_sync':
            msg = "The user has been asked to accept the synchronization" \
              " although an integrity error was expected"
            assert_true(False, msg)
        return 'ok'

    # If the sync dialog is shown to the user, it means we have
    # passed the integrity check. But we shouldn't had to!
    components['mock']['ui_controller'].ask_for_user_input.side_effect = ask_user

    def terminate():
        components['real']['server_session'].terminate()
        return integrity_failure_state

    # If the integrity check fails, it's fine
    integrity_failure_state = StateRegister.get('BasisMismatchState')
    integrity_failure_state.do_execute = MagicMock(side_effect=terminate)
    components['mock']['integrity_failure_state'] = integrity_failure_state
    components['mock']['downloading_state'] = download_state_mock

    return components
开发者ID:adamnemecek,项目名称:FileRock-Client,代码行数:51,代码来源:sync_integrity_test.py

示例3: _handle_message_COMMIT_DONE

    def _handle_message_COMMIT_DONE(self, message):
        """Everything went well, the server has completed the commit.

        Check the resulting basis sent by the server against our
        candidate basis, if it's valid then finalize the commit by
        updating all internal data structures.
        Finally go into the sync phase, the session can begin at last.
        """
        self.logger.info(u'Commit done')
        server_basis = message.getParameter('new_basis')
        candidate_basis = self._load_candidate_basis()
        previous_basis = self._load_trusted_basis()
        self.logger.debug(u"Server basis: %s" % server_basis)
        self.logger.debug(u"Candidate basis: %s" % candidate_basis)
        self.logger.debug(u"Last trusted basis: %s" % previous_basis)

        # Check the server basis against the candidate basis
        self._context.integrity_manager.setCurrentBasis(candidate_basis)
        self._check_integrity(server_basis)

        # Everything OK, persist the new trusted basis and related metadata
        operations = self._context.transaction_cache.get_all_records()
        operations = [(op_id, op) for (op_id, op, _) in operations]
        self._persist_integrity_metadata(previous_basis,
                                         server_basis,
                                         operations)
        self._context.integrity_manager.setCurrentBasis(server_basis)

        self.logger.info(u"Pending commit successfully recovered.")
        self.logger.info(u"Updated basis: %s" % server_basis)
        self._update_user_interfaces(message)
        self._set_next_state(StateRegister.get('ReadyForServiceState'))
        self._context._input_queue.put(
                                Command('STARTSYNCPHASE'), 'sessioncommand')
开发者ID:alepharchives,项目名称:FileRock-Client,代码行数:34,代码来源:commit.py

示例4: _on_complete_operation

 def _on_complete_operation(self, operation):
     with self._lock:
         self._num_finished_operations += 1
         num_finished = self._num_finished_operations
         num_received = self._num_received_operations
         if self._received_all_operations and num_received == num_finished:
             self._set_next_state(StateRegister.get("SyncDoneState"))
开发者ID:pombredanne,项目名称:FileRock-Client,代码行数:7,代码来源:sync_download.py

示例5: _handle_command_HANDSHAKE

 def _handle_command_HANDSHAKE(self, message):
     """Positive reply from the server, tell him the protocol version
     that we can support.
     """
     self._context.output_message_queue.put(
         PROTOCOL_VERSION('PROTOCOL_VERSION', {'version': 1}))
     self._set_next_state(StateRegister.get('ProtocolVersionState'))
开发者ID:LucaLanziani,项目名称:FileRock-Client,代码行数:7,代码来源:pre_authentication.py

示例6: _on_entering

    def _on_entering(self):
        """ServerSession waits for all operations currently handled by
        workers to be completed, afterwards it begins the commit.

        Integrity of the transaction is checked and the "candidate basis"
        (the expected basis after our modifications to the storage) is
        computed.
        """
        self.logger.debug(u"Committing the current transaction...")
        self.logger.debug(u"Waiting for the transaction to be finished...")
        self._context.transaction_manager.wait_until_finished()
        self.logger.debug(u"Transaction is finished!")
        self.logger.info(u"Committing the following pathnames:")
        operations = self._context.transaction_manager.get_completed_operations()
        for (op_id, op) in operations:
            self.logger.info(u'    %s "%s"' % (op.verb, op.pathname))
            self.logger.debug(u"    id=%s %s" % (op_id, op))
        self._check_transaction_integrity(operations)
        candidate_basis = self._context.integrity_manager.getCandidateBasis()
        self._context._persist_candidate_basis(candidate_basis)
        self.logger.info("Candidate basis: %s" % candidate_basis)
        self._update_transaction_cache(operations)
        completed_operations_id = [op_id for (op_id, _) in operations]
        self._context.output_message_queue.put(COMMIT_START(
            "COMMIT_START", {'achieved_operations': completed_operations_id}))
        self._set_next_state(StateRegister.get('CommitStartState'))
开发者ID:adamnemecek,项目名称:FileRock-Client,代码行数:26,代码来源:commit.py

示例7: _handle_command_OPERATIONSFINISHED

 def _handle_command_OPERATIONSFINISHED(self, command):
     """Receiving this command means that all the internal operations
     have been served. Wait until all of them are complete.
     """
     self._set_next_state(StateRegister.get('SyncWaitingForCompletionState'))
     cmd = Command('GOTOONCOMPLETION')
     cmd.next_state = 'SyncDoneState'
     self._context._input_queue.put(cmd, 'sessioncommand')
开发者ID:adamnemecek,项目名称:FileRock-Client,代码行数:8,代码来源:sync.py

示例8: _handle_message_REPLICATION_START

 def _handle_message_REPLICATION_START(self, message):
     """The server is ready to leave the sync phase, too. Let's
     start the Replication & Transfer phase.
     """
     self._set_next_state(
         StateRegister.get('EnteringReplicationAndTransferState'))
     self._context._input_queue.put(
         Command('UPDATEBEFOREREPLICATION'), 'sessioncommand')
开发者ID:adamnemecek,项目名称:FileRock-Client,代码行数:8,代码来源:sync.py

示例9: _start_syncing

 def _start_syncing(self):
     """The list of modification to perform has been accepted, make
     the synchronization phase start.
     """
     self._context.integrity_manager.setCurrentBasis(self.server_basis.encode())
     self._context._internal_facade.set_global_status(GStatuses.C_NOTALIGNED)
     self._context.startup_synchronization.execute()
     self._context.startup_synchronization.generate_downlink_events()
     self._set_next_state(StateRegister.get('SyncDownloadingLeavesState'))
开发者ID:adamnemecek,项目名称:FileRock-Client,代码行数:9,代码来源:sync.py

示例10: _handle_message_PROTOCOL_VERSION_AGREEMENT

    def _handle_message_PROTOCOL_VERSION_AGREEMENT(self, message):
        """The server replied to our greeting message and then closed
        the connection. Is our client version obsolete?

        Note: this is just post-disconnection handling, the natural
        handler would be ProtocolVersionState.
        """
        state = StateRegister.get('ProtocolVersionState')
        state._check_protocol_mismatch(message)
开发者ID:LucaLanziani,项目名称:FileRock-Client,代码行数:9,代码来源:pre_authentication.py

示例11: on_commit_necessary_to_proceed

 def on_commit_necessary_to_proceed(self):
     """Session can decide to commit the current transaction. It
     happens if the transaction has got too large, if it's passed too
     much time from the last commit or if a commit is needed to honor
     some session constraint.
     """
     self.logger.info(
         u"The application has decided that a commit is necessary")
     self._set_next_state(
         StateRegister.get('WaitingForUnauthorizedOperationsState'))
开发者ID:alepharchives,项目名称:FileRock-Client,代码行数:10,代码来源:replication_and_transfer.py

示例12: test_nothing_to_sync_from_clean_state

def test_nothing_to_sync_from_clean_state(
                        adapter_mock, workerpool_mock, connection_lifekeeper,
                        disconnectedstate_cls_mock, downloadstate_cls_mock):

    from filerockclient.serversession.states.register import StateRegister
    from FileRockSharedLibraries.Communication.Messages import SYNC_FILES_LIST

    components = setup_server_session(
                        __file__,
                        adapter_mock, workerpool_mock, connection_lifekeeper,
                        disconnectedstate_cls_mock, downloadstate_cls_mock)

    # Note: the StateRegister singleton has been initialized by
    # ServerSession's constructor
    syncstart_state = StateRegister.get('SyncStartState')

    def terminate():
        components['real']['server_session'].terminate()
        return syncstart_state

    # DisconnectedState is the default initial state, but we want to start
    # from SyncStartState
    disconnected_state_mock = disconnectedstate_cls_mock()
    disconnected_state_mock.do_execute.return_value = syncstart_state

    # Stop the test when we get to SyncDownloadingLeavesState
    download_state_mock = downloadstate_cls_mock()
    download_state_mock.do_execute.side_effect = terminate

    # There is nothing in the warebox
    components['mock']['warebox'].get_content.return_value = []

    # Send ServerSession a scenario with no data on the storage.
    components['real']['metadata'].set('trusted_basis', 'TRUSTEDBASIS')
    msg = SYNC_FILES_LIST('SYNC_FILES_LIST', {
                'basis': 'TRUSTEDBASIS',
                'dataset': [],
                'last_commit_client_id': '0',
                'last_commit_client_hostname': 'myhostname',
                'last_commit_client_platform': 'myplatform',
                'last_commit_timestamp': 'mytimestamp',
                'user_quota': '0',
                'used_space': '100'
                })
    components['real']['input_queue'].put(msg, 'servermessage')

    components['real']['server_session'].start()
    components['real']['server_session'].join()

    # No data on the storage, in the warebox or in the storage cache.
    # We expect that nothing has happened.
    assert_false(components['mock']['ui_controller'].ask_for_user_input.called)
    assert_equal(components['real']['storage_cache'].get_all(), [])
    assert_true(components['real']['input_queue'].empty(['operation']))
开发者ID:adamnemecek,项目名称:FileRock-Client,代码行数:54,代码来源:sync_operations_test.py

示例13: _handle_command_UPDATEBEFOREREPLICATION

 def _handle_command_UPDATEBEFOREREPLICATION(self, command):
     """Initialize all data structures and components.
     """
     storage_content = self._context.storage_cache.get_all_records()
     self._update_client_status(storage_content)
     self._update_filesystem_watcher(storage_content)
     self._context.filesystem_watcher.resume_execution()
     self.logger.info(u'Started filesystem monitoring.')
     self._context.refused_declare_count = 0
     self._context.id = 0
     self._try_set_global_status_aligned()
     self._set_next_state(StateRegister.get('ReplicationAndTransferState'))
开发者ID:alepharchives,项目名称:FileRock-Client,代码行数:12,代码来源:replication_and_transfer.py

示例14: _on_entering

    def _on_entering(self):
        """Acquire network resources and try to connect.

        The connection is authenticated by the mean of the server
        certificate, so it is trusted.
        """
        self.logger.info(u"Connecting to server...")
        self._context._internal_facade.set_global_status(GStatuses.NC_CONNECTING)
        if self._context.acquire_network_resources():
            self.logger.info(u"Server has successfully authenticated itself")
            self._context.num_connection_attempts = 0
            self._context._internal_facade.reset_pause_timer()
            self._set_next_state(StateRegister.get('ConnectedState'))
            self._context._input_queue.put(Command('HANDSHAKE'), 'sessioncommand')
        else:
            self._context._internal_facade.set_global_status(GStatuses.NC_NOSERVER)
            if self._context.num_connection_attempts > self._context.max_connection_attempts:
                self.logger.error(u'Server has been unreachable for too long, giving up.')
                return self._context._internal_facade.pause_and_restart()
            self._set_next_state(StateRegister.get('DisconnectedState'))
            self._context._input_queue.put(Command('CONNECT'), 'sessioncommand')
开发者ID:LucaLanziani,项目名称:FileRock-Client,代码行数:21,代码来源:pre_authentication.py

示例15: _handle_message_CHALLENGE_VERIFY_RESPONSE

 def _handle_message_CHALLENGE_VERIFY_RESPONSE(self, message):
     """Received a reply to our challenge. Did the server authenticate
     us? If not, maybe another client is already connected to this
     account.
     """
     auth_result = message.getParameter('result')
     if auth_result:
         self.logger.info(u"Client has successfully authenticated itself.")
         self._context.output_message_queue.put(READY_FOR_SERVICE('READY_FOR_SERVICE'))
         self._context.session_id = message.get_session_id()
         self.logger.debug(
             u"Received Session id %s from server" % self._context.session_id)
         self._context.keepalive_timer.resume_execution()
         self._set_next_state(StateRegister.get('ReadyForServiceState'))
     else:
         self.logger.error(u"Server rejected client authentication.")
         self._context._internal_facade.set_global_status(GStatuses.NC_NOTAUTHORIZED)
         if message.is_other_client_connected():
             client = message.get_other_connected_client()
             if client["client_id"]==0:
                 other_client_message = u"Your web client is already connected"
             else:
                 other_client_message = \
                     u"Client number %s from computer %s already connected" \
                     % (client["client_id"], client["hostname"])
             self.logger.warning(other_client_message)
             self._context.disconnect_other_client = True
             force_disconnection = self._context._ui_controller.ask_for_user_input(
                 "other_client_connected", client["client_id"],
                 client["hostname"])
             if not force_disconnection == 'ok':
                 self._context._internal_facade.pause()
                 return
             else:
                 self._context.current_state._set_next_state(
                     StateRegister.get('DisconnectedState'))
                 self._context._input_queue.put(Command('CONNECT'), 'sessioncommand')
                 return
         else:
             relink_user(self)
开发者ID:LucaLanziani,项目名称:FileRock-Client,代码行数:40,代码来源:pre_authentication.py


注:本文中的filerockclient.serversession.states.register.StateRegister类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。