Did I find the right examples for you? yes no      Crawl my project      Python Jobs

All Samples(36)  |  Call(35)  |  Derive(0)  |  Import(1)

src/d/h/DHTBot-HEAD/dhtbot/protocols/krpc_sender.py   DHTBot(Download)
    def sendKRPC(self, krpc, address):
        encoded_packet = krpc_coder.encode(krpc)
        self.transport.write(encoded_packet, address)
 
    def sendQuery(self, query, address, timeout):

src/d/h/DHTBot-HEAD/dhtbot/test/coding/test_krpc_coder.py   DHTBot(Download)
from twisted.trial import unittest
 
from dhtbot.coding.krpc_coder import (
        encode, decode, _chunkify, _decode_addresses,
        InvalidKRPCError)
from dhtbot.coding import basic_coder
from dhtbot.krpc_types import Query, Response, Error
from dhtbot.contact import Node
 
encode_and_decode = lambda krpc: decode(encode(krpc))
    def test_encode_validPing(self):
        q = self.q
        q.rpctype = "ping"
        encoding = encode(q)
        expected_encoding = ('d1:ad2:id20:\x00\x00\x00\x00\x01\x00\x00' +
    def test_encode_validFindNode(self):
        q = self.q
        q.target_id = self.test_target_id
        q.rpctype = "find_node"
        encoding = encode(q)
    def test_encode_validGetPeers(self):
        q = self.q
        q.target_id = self.test_target_id
        q.rpctype = "get_peers"
        encoding = encode(q)

src/d/h/DHTBot-HEAD/dhtbot/test/extensions/test_rate_limiter.py   DHTBot(Download)
        self.query._from = 15
        self.query._transaction_id = 99
        self.packet = krpc_coder.encode(self.query)
        # Patch in hardcoded value for the bandwidth
        # limits so that changing the constants will
        self.query._from = 15
        self.query._transaction_id = 99
        self.packet = krpc_coder.encode(self.query)
        # Patch in hardcoded value for the bandwidth
        # limits so that changing the constants will
        # One packet should be accepted without problems
        rate_limited_proto.datagramReceived(
                krpc_coder.encode(self.query), self.address)
        self.assertEquals(1, counter.count)
        counter.reset()
        # The second packet should be dropped
        rate_limited_proto.datagramReceived(
                krpc_coder.encode(self.query), self.address)
        self.clock.set(1)
        rate_limited_proto.datagramReceived(
                krpc_coder.encode(self.query), self.address)
        self.assertEquals(1, counter.count)
 

src/d/h/DHTBot-HEAD/dhtbot/test/protocols/test_krpc_responder.py   DHTBot(Download)
        expected_response._transaction_id = 15
        expected_response.rpctype = "ping"
        kresponder.datagramReceived(krpc_coder.encode(incoming_query),
                                    test_address)
        actual_response = kresponder.sendResponse.response
        expected_response.nodes = node_list
 
        kresponder.datagramReceived(krpc_coder.encode(incoming_query),
                                    test_address)
        actual_response = kresponder.sendResponse.response
            self.fail("Too many or too few nodes!")
 
        kresponder.datagramReceived(krpc_coder.encode(incoming_query),
                                    test_address)
        actual_response = kresponder.sendResponse.response
        # simulating the incoming query and capture
        # the outgoing response
        kresponder.datagramReceived(krpc_coder.encode(incoming_query),
                                    test_address)
        actual_response = kresponder.sendResponse.response
        for peer in peers:
            kresponder._datastore.put(incoming_query.target_id, peer)
        kresponder.datagramReceived(krpc_coder.encode(incoming_query),
                                    test_address)
        actual_response = kresponder.sendResponse.response

src/d/h/DHTBot-HEAD/dhtbot/test/protocols/test_krpc_sender.py   DHTBot(Download)
 
        # Pass in the krpc
        k_messenger.datagramReceived(krpc_coder.encode(krpc), address)
        self.assertEquals(num_calls, counter.count)
 
        response = query.build_response()
        response._from = 9
        k_messenger.datagramReceived(krpc_coder.encode(response), address)
        _restore_reactor()
        self.assertEquals(1, counter.count)
        d.addCallback(self._response_equality, response)
        d.addCallback(counter)
        encoded_response = krpc_coder.encode(response)
        self.k_messenger.datagramReceived(encoded_response, address)
        self.assertEquals(1, counter.count)
        d.addErrback(self._error_equality, error)
        d.addErrback(counter)
        encoded_error = krpc_coder.encode(error)
        self.k_messenger.datagramReceived(encoded_error, address)
        self.assertEquals(1, counter.count)