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


Python heartbeat.Heartbeat类代码示例

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


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

示例1: setUp

 def setUp(self):
     self.challenge = Heartbeat.challenge_type().\
         fromdict(
             MockValues
             .get_challenges_response['challenges'][0]['challenge'])
     self.heartbeat = Heartbeat.fromdict(
         MockValues.connect_response['heartbeat'])
     self.tag = Heartbeat.tag_type().fromdict(
         MockValues.get_chunks_response['chunks'][0]['tag'])
     self.expiration = datetime.utcnow(
     ) + timedelta(int(MockValues.get_chunks_response['chunks'][0]['due']))
     self.client = mock.MagicMock()
     self.manager = ThreadManager()
     self.test_hash = 'hash'
     self.test_size = 100
     self.test_seed = 'seed'
     self.contract = DownstreamContract(self.client,
                                        self.test_hash,
                                        self.test_seed,
                                        self.test_size,
                                        self.challenge,
                                        self.expiration,
                                        self.tag,
                                        self.manager,
                                        os.path.join('data', 'chunks'))
     self.contract.generate_data()
开发者ID:wiggzz,项目名称:downstream-farmer,代码行数:26,代码来源:test_unit.py

示例2: make_kernel

def make_kernel(namespace, kernel_factory, 
                out_stream_factory=None, display_hook_factory=None):
    """ Creates a kernel, redirects stdout/stderr, and installs a display hook
    and exception handler.
    """
    # Re-direct stdout/stderr, if necessary.
    if namespace.no_stdout or namespace.no_stderr:
        blackhole = file(os.devnull, 'w')
        if namespace.no_stdout:
            sys.stdout = sys.__stdout__ = blackhole
        if namespace.no_stderr:
            sys.stderr = sys.__stderr__ = blackhole

    # Install minimal exception handling
    sys.excepthook = FormattedTB(mode='Verbose', color_scheme='NoColor', 
                                 ostream=sys.__stdout__)

    # Create a context, a session, and the kernel sockets.
    io.raw_print("Starting the kernel at pid:", os.getpid())
    context = zmq.Context()
    # Uncomment this to try closing the context.
    # atexit.register(context.close)
    session = Session(username=u'kernel')

    reply_socket = context.socket(zmq.XREP)
    xrep_port = bind_port(reply_socket, namespace.ip, namespace.xrep)
    io.raw_print("XREP Channel on port", xrep_port)

    pub_socket = context.socket(zmq.PUB)
    pub_port = bind_port(pub_socket, namespace.ip, namespace.pub)
    io.raw_print("PUB Channel on port", pub_port)

    req_socket = context.socket(zmq.XREQ)
    req_port = bind_port(req_socket, namespace.ip, namespace.req)
    io.raw_print("REQ Channel on port", req_port)

    hb = Heartbeat(context, (namespace.ip, namespace.hb))
    hb.start()
    hb_port = hb.port
    io.raw_print("Heartbeat REP Channel on port", hb_port)

    # Helper to make it easier to connect to an existing kernel, until we have
    # single-port connection negotiation fully implemented.
    io.raw_print("To connect another client to this kernel, use:")
    io.raw_print("-e --xreq {0} --sub {1} --rep {2} --hb {3}".format(
        xrep_port, pub_port, req_port, hb_port))

    # Redirect input streams and set a display hook.
    if out_stream_factory:
        sys.stdout = out_stream_factory(session, pub_socket, u'stdout')
        sys.stderr = out_stream_factory(session, pub_socket, u'stderr')
    if display_hook_factory:
        sys.displayhook = display_hook_factory(session, pub_socket)

    # Create the kernel.
    kernel = kernel_factory(session=session, reply_socket=reply_socket, 
                            pub_socket=pub_socket, req_socket=req_socket)
    kernel.record_ports(xrep_port=xrep_port, pub_port=pub_port,
                        req_port=req_port, hb_port=hb_port)
    return kernel
开发者ID:addisonc,项目名称:ipython,代码行数:60,代码来源:entry_point.py

示例3: make_kernel

def make_kernel(namespace, kernel_factory, 
                out_stream_factory=None, display_hook_factory=None):
    """ Creates a kernel, redirects stdout/stderr, and installs a display hook
    and exception handler.
    """
    # If running under pythonw.exe, the interpreter will crash if more than 4KB
    # of data is written to stdout or stderr. This is a bug that has been with
    # Python for a very long time; see http://bugs.python.org/issue706263.
    if sys.executable.endswith('pythonw.exe'):
        blackhole = file(os.devnull, 'w')
        sys.stdout = sys.stderr = blackhole
        sys.__stdout__ = sys.__stderr__ = blackhole 

    # Install minimal exception handling
    sys.excepthook = FormattedTB(mode='Verbose', color_scheme='NoColor', 
                                 ostream=sys.__stdout__)

    # Create a context, a session, and the kernel sockets.
    io.raw_print("Starting the kernel at pid:", os.getpid())
    context = zmq.Context()
    # Uncomment this to try closing the context.
    # atexit.register(context.close)
    session = Session(username=u'kernel')

    reply_socket = context.socket(zmq.XREP)
    xrep_port = bind_port(reply_socket, namespace.ip, namespace.xrep)
    io.raw_print("XREP Channel on port", xrep_port)

    pub_socket = context.socket(zmq.PUB)
    pub_port = bind_port(pub_socket, namespace.ip, namespace.pub)
    io.raw_print("PUB Channel on port", pub_port)

    req_socket = context.socket(zmq.XREQ)
    req_port = bind_port(req_socket, namespace.ip, namespace.req)
    io.raw_print("REQ Channel on port", req_port)

    hb = Heartbeat(context, (namespace.ip, namespace.hb))
    hb.start()
    hb_port = hb.port
    io.raw_print("Heartbeat REP Channel on port", hb_port)

    # Helper to make it easier to connect to an existing kernel, until we have
    # single-port connection negotiation fully implemented.
    io.raw_print("To connect another client to this kernel, use:")
    io.raw_print("-e --xreq {0} --sub {1} --rep {2} --hb {3}".format(
        xrep_port, pub_port, req_port, hb_port))

    # Redirect input streams and set a display hook.
    if out_stream_factory:
        sys.stdout = out_stream_factory(session, pub_socket, u'stdout')
        sys.stderr = out_stream_factory(session, pub_socket, u'stderr')
    if display_hook_factory:
        sys.displayhook = display_hook_factory(session, pub_socket)

    # Create the kernel.
    kernel = kernel_factory(session=session, reply_socket=reply_socket, 
                            pub_socket=pub_socket, req_socket=req_socket)
    kernel.record_ports(xrep_port=xrep_port, pub_port=pub_port,
                        req_port=req_port, hb_port=hb_port)
    return kernel
开发者ID:08saikiranreddy,项目名称:ipython,代码行数:60,代码来源:entry_point.py

示例4: setUp

 def setUp(self):
     self.challenge = Heartbeat.challenge_type()()
     self.tag = Heartbeat.tag_type()()
     self.expiration = datetime.utcnow()+timedelta(seconds=60)
     self.contract = Contract('hash',
                              'seed',
                              12345,
                              self.challenge,
                              self.expiration,
                              self.tag)
开发者ID:nameone,项目名称:downstream-farmer,代码行数:10,代码来源:tests-unit.py

示例5: run

def run(func, args):
    config.init('../xmpp.conf')
    client_jid = config.get('users', 'client_jid')
    client_password = config.get('users', 'client_password')
    server_jid = config.get('users', 'server_jid')
    session = Remote.new_session(client_jid, client_password)
    endpoint = session.new_proxy(server_jid + '/rpc', TestRunner)
    job = Future()
    heartbeat = Heartbeat(job, endpoint.ping, session)
    heartbeat.start()
    getattr(endpoint.async(job), func)(*args)
开发者ID:jejuboy,项目名称:hats-xmpp,代码行数:11,代码来源:client.py

示例6: Chunk

class Chunk(object):
    def __init__(self, file_path, num_challenges, root_seed):
        self.secret = "mysecret"
        self.target_file = Heartbeat(file_path, self.secret)
        self.target_file.generate_challenges(num_challenges, root_seed)

    def challenge(self):
        return self.target_file.random_challenge()

    def response(self, answer):
        return self.target_file.check_answer(answer)
开发者ID:rrydman,项目名称:heartbeat,代码行数:11,代码来源:test-functional.py

示例7: test_connect_sign

 def test_connect_sign(self):
     self.client.msg = 'test message'
     self.client.sig = 'HyzVUenXXo4pa+kgm1vS8PNJM83eIXFC5r0q86FGbqFcdla6rcw'
     '72/ciXiEPfjli3ENfwWuESHhv6K9esI0dl5I='
     self.client.address = '19qVgG8C6eXwKMMyvVegsi3xCsKyk3Z3jV'
     self.client.token = None
     with mock.patch('downstream_farmer.client.requests.post') as patch:
         patch.return_value.json.return_value = MockValues.connect_response
         self.client.connect()
     patch.assert_called_with('{0}/new/{1}'.format(self.server_url
                                                   .strip('/') + self
                                                   .api_path, self
                                                   .client.address),
                              data=json.dumps({
                                  "message": self.client.msg,
                                  "signature": self.client.sig
                              }),
                              headers={
         'Content-Type': 'application/json'
     },
         verify=None)
     self.assertEqual(
         self.client.token, MockValues.connect_response['token'])
     self.assertEqual(self.client.heartbeat,
                      Heartbeat.fromdict(MockValues
                                         .connect_response['heartbeat']))
开发者ID:wiggzz,项目名称:downstream-farmer,代码行数:26,代码来源:test_unit.py

示例8: test_heartbeat_and_challenge

    def test_heartbeat_and_challenge(self):
        file1 = Heartbeat(self.file_path, "mysecret")
        file1.generate_challenges(10, self.root_seed)
        challenge = file1.random_challenge()

        # Create hash_response from seed and duplicate file
        file2 = Heartbeat(self.file_path2)
        answer = file2.meet_challenge(challenge)
        self.assertTrue(file1.check_answer(answer))

        # Create hash_answer from seed and edited file
        file3 = Heartbeat(self.file_path3)
        answer = file3.meet_challenge(challenge)

        # This should not match
        self.assertFalse(file1.check_answer(answer))
开发者ID:rrydman,项目名称:heartbeat,代码行数:16,代码来源:test-functional.py

示例9: test_connect_working

 def test_connect_working(self):
     with mock.patch('downstream_farmer.client.requests.get') as patch:
         inst = patch.return_value
         inst.json.return_value = MockValues.connect_response
         self.client.connect(self.server_url)
     self.assertEqual(self.client.token,MockValues.connect_response['token'])
     self.assertEqual(self.client.heartbeat,
                      Heartbeat.fromdict(MockValues.connect_response['heartbeat']))
开发者ID:nameone,项目名称:downstream-farmer,代码行数:8,代码来源:tests-unit.py

示例10: setUp

 def setUp(self):
     self.server_url = 'https://test.url/'
     self.api_path = '/api/downstream/v1'
     self.size = 100
     self.address = base58.b58encode_check(b'\x00' + os.urandom(20))
     self.token = binascii.hexlify(os.urandom(16)).decode('ascii')
     self.msg = ''
     self.sig = ''
     self.thread_manager = ShellApplication()
     self.contract_thread = ManagedThread()
     self.chunk_dir = os.path.join('data', 'chunks')
     self.client = DownstreamClient(self.server_url,
                                    self.token,
                                    self.address,
                                    self.size,
                                    self.msg,
                                    self.sig,
                                    self.thread_manager,
                                    self.chunk_dir)
     self.client.session = mock.MagicMock()
     self.test_contract = \
         DownstreamContract(self.client,
                            MockValues.get_chunks_response[
                                'chunks'][0]['file_hash'],
                            MockValues.get_chunks_response[
                                'chunks'][0]['seed'],
                            MockValues.get_chunks_response[
                                'chunks'][0]['size'],
                            Heartbeat.challenge_type().fromdict(
                                MockValues
                                .get_chunks_response
                                ['chunks'][0]['challenge']),
                            datetime.utcnow() + timedelta(
                                seconds=int(
                                    MockValues
                                    .get_chunks_response
                                    ['chunks'][0]['due'])),
                            Heartbeat.tag_type().fromdict(
                                MockValues
                                .get_chunks_response
                                ['chunks'][0]['tag']),
                            self.thread_manager,
                            self.chunk_dir)
     self.test_heartbeat = Heartbeat.fromdict(
         MockValues.connect_response['heartbeat'])
开发者ID:NinjaDevelper,项目名称:downstream-farmer,代码行数:45,代码来源:test_unit.py

示例11: init_heartbeat

 def init_heartbeat(self):
     """start the heart beating"""
     # heartbeat doesn't share context, because it mustn't be blocked
     # by the GIL, which is accessed by libzmq when freeing zero-copy messages
     hb_ctx = zmq.Context()
     self.heartbeat = Heartbeat(hb_ctx, (self.transport, self.ip, self.hb_port))
     self.hb_port = self.heartbeat.port
     self.log.debug("Heartbeat REP Channel on port: %i" % self.hb_port)
     self.heartbeat.start()
开发者ID:NYC-Pyladies,项目名称:ipython,代码行数:9,代码来源:kernelapp.py

示例12: setUp

 def setUp(self):
     self.server_url = 'https://test.url/'
     self.api_path = '/api/downstream/v1'
     self.size = 100
     self.address = base58.b58encode_check(b'\x00' + os.urandom(20))
     self.token = binascii.hexlify(os.urandom(16)).decode('ascii')
     self.msg = ''
     self.sig = ''
     self.api = API()
     self.client = DownstreamClient(self.server_url,
                                    self.token,
                                    self.address,
                                    self.size,
                                    self.msg,
                                    self.sig,
                                    self.api)
     self.test_contract = DownstreamContract(self.client,
                                             MockValues.get_chunk_response[
                                                 'file_hash'],
                                             MockValues.get_chunk_response[
                                                 'seed'],
                                             MockValues.get_chunk_response[
                                                 'size'],
                                             Heartbeat.challenge_type()
                                             .fromdict(
                                                 MockValues.
                                                 get_chunk_response['challe'
                                                                    'nge']),
                                             datetime.utcnow() +
                                             timedelta(
                                                 seconds=int(
                                                     MockValues.
                                                     get_chunk_response['du'
                                                                        'e']
                                                 )),
                                             Heartbeat.tag_type().fromdict(
                                                 MockValues
                                                 .get_chunk_response['ta'
                                                                     'g'],
                                             ),
                                             self.api)
     self.test_heartbeat = Heartbeat.fromdict(
         MockValues.connect_response['heartbeat'])
开发者ID:mstg,项目名称:downstream-farmer,代码行数:43,代码来源:test_unit.py

示例13: test_usage

    def test_usage(self):
        beat = Heartbeat()

        public_beat = beat.get_public()

        with open("files/test.txt", "rb") as file:
            (tag, state) = beat.encode(file)

        challenge = beat.gen_challenge(state)

        with open("files/test.txt", "rb") as file:
            proof = public_beat.prove(file, challenge, tag)

        is_valid = beat.verify(proof, challenge, state)
        if is_valid:
            print("file is stored by the server")
        else:
            print("file proof invalid")

        self.assertTrue(is_valid)
开发者ID:eandbsoftware,项目名称:heartbeat,代码行数:20,代码来源:tests_unit_heartbeat.py

示例14: __init__

    def __init__(self):
        if MOCK_HARDWARE:
            from hardware_mock import HardwareMock

            self._hardware = HardwareMock()
        else:
            from hardware import Hardware

            self._hardware = Hardware()

        if MOCK_HEARTBEAT:
            self._heartbeat = HeartbeatMock()
        else:
            self._heartbeat = Heartbeat()

        if MOCK_DATA:
            self._sensor_service = SensorServiceMock()
            self._registration_service = RegistrationServiceMock()
        else:
            self._sensor_service = SensorService()
            self._registration_service = RegistrationService()
开发者ID:aliok,项目名称:meetingRoomKiosk,代码行数:21,代码来源:sensor.py

示例15: init_heartbeat

    def init_heartbeat(self):
        """start the heart beating"""
        # heartbeat doesn't share context, because it mustn't be blocked
        # by the GIL, which is accessed by libzmq when freeing zero-copy messages
        hb_ctx = zmq.Context()
        self.heartbeat = Heartbeat(hb_ctx, (self.transport, self.ip, self.hb_port))
        self.hb_port = self.heartbeat.port
        self.log.debug("Heartbeat REP Channel on port: %i"%self.hb_port)
        self.heartbeat.start()

        # Helper to make it easier to connect to an existing kernel.
        # set log-level to critical, to make sure it is output
        self.log.critical("To connect another client to this kernel, use:")
开发者ID:99plus2,项目名称:ipython,代码行数:13,代码来源:kernelapp.py


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