Example #1
0
 def fill(self, dico):
     expanded_dico = {}
     logger = logging.getLogger(__name__)
     logger.debug("++ self.message %s\n" % (self.message))
     self._fill(dico, self.message, expanded_dico,
                self.PROTOBUF_CLASS.DESCRIPTOR)
     return dict2pb(self.PROTOBUF_CLASS, expanded_dico)
Example #2
0
    def test_create_from_zmq_with_list():
        destination = "fake_id"
        playing = '"false"'
        seconds = 42
        yaml_content = """
message: !CaptureGameState
    destination: "{destination}"
    message:
        playing: {playing}
        seconds: {seconds}
        teams:
            - name: "{{looser_team}}"
              score: 0
              num_players: 2
              players:
                  - "looser_robot 1"
                  - "looser_robot 2"
            - name: "{{winner_team}}"
              score: 0
              num_players: 2
              players:
                  - "winner_robot 1"
                  - "{{winner_robot_two}}"
""".format(destination=destination, playing=playing, seconds=seconds)
        data = yaml.load(yaml_content, Loader=yaml.FullLoader)
        message = data["message"]
        looser_team = "Loosers"
        winner_team = "Winners"
        winner_robot_two = "winner robot 2"
        zmq_message = message.encode_zmq_message({
            'looser_team':
            looser_team,
            'winner_team':
            winner_team,
            'winner_robot_two':
            winner_robot_two
        })
        capture = y2p.Capture.create_from_zmq(zmq_message)
        pb_message = dict2pb(pb_server_game.GameState, capture.message)
        assert_equal(pb_message.teams[0].name, looser_team)
        assert_equal(pb_message.teams[1].name, winner_team)
        assert_equal(pb_message.teams[1].players[1], winner_robot_two)
Example #3
0
 def test_3(self):
     """Play with the underlying library (not really a test)."""
     message = pb_controller.Hello()
     name = "JAMBON"
     message.name = name
     dico = pb2dict(message)
     message = pb_controller.Input()
     left = 0.2
     right = -0.5
     weapon1 = False
     weapon2 = True
     message.move.left = left
     message.move.right = right
     message.fire.weapon1 = weapon1
     message.fire.weapon2 = weapon2
     dico = pb2dict(message)
     message2 = dict2pb(pb_controller.Input, dico)
     assert_equal(left, message2.move.left)
     assert_equal(right, message2.move.right)
     assert_equal(weapon1, message2.fire.weapon1)
     assert_equal(weapon2, message2.fire.weapon2)
Example #4
0
def doHttpBidRequest(channel, url, body, header={}):
    module = __import__(channel)

    _url = urlparse(url)
    pb = module.createRequest()

    pbBody = pbjson.dict2pb(pb, body)

    binBody = pbBody.SerializeToString()

    httpClient = None
    responseBody = None
    try:
        headers = {
            "Content-type": "application/x-www-form-urlencoded",
            "Host": "iqiyi.adtree.cn"
        }

        httpClient = httplib.HTTPConnection(_url.hostname,
                                            _url.port,
                                            timeout=30)
        httpClient.request("POST", _url.path, binBody, headers)

        response = httpClient.getresponse()
        #print response.status
        #print response.reason
        responseBody = response.read()
        #print response.getheaders()
    finally:
        if httpClient:
            httpClient.close()

    response = module.createResponse()()
    response.ParseFromString(responseBody)

    return pbjson.pb2dict(response)
Example #5
0
 def load(self):
     self._message = dict2pb(self.PROTOBUF_CLASS, self.message)