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


Python TSerialization.serialize方法代码示例

本文整理汇总了Python中thrift.TSerialization.serialize方法的典型用法代码示例。如果您正苦于以下问题:Python TSerialization.serialize方法的具体用法?Python TSerialization.serialize怎么用?Python TSerialization.serialize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在thrift.TSerialization的用法示例。


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

示例1: main

# 需要导入模块: from thrift import TSerialization [as 别名]
# 或者: from thrift.TSerialization import serialize [as 别名]
def main():

	myapp = thrift.App(ap_name="iperf", binary_path="/usr/bin/iperf", description="Hello World Application")
	myapp.parameters =  ([thrift.Parameter(name="server", cmd='-s', type= "Flag", default_value="False"), 
		thrift.Parameter(name="client", cmd='-c', type= "String")] )


	send('def_application', TSerialization.serialize(myapp))
	send('def_group', "Servers", "kali")


	app_inst = thrift.AppInstance()
	app_inst.inst_name = "iperf_client"
	app_inst.app_name = "iperf"
	# app_inst.arguments = {"server": ""}
	app_inst.arguments = {"client": "192.168.1.37"}
	# app_inst.environment =
	# app_inst.clean_env =					
	# app_inst.map_err_to_out =

	# my_iface = thrift.Iface(if_name= "wlan0") 	# MOCKUP: This is obviously incomplete

	send('add_application', "kali", TSerialization.serialize(app_inst))
	# api_server.add_application("kali", app_inst)

	event_trigger = thrift.EventTrigger(name="kali_installed" ,enabled=True)
	event_trigger.conditions = {'kali.iperf_client': 'Installed'}

	send('def_event',TSerialization.serialize(event_trigger))


	send('start_experiment')

	# 
	time.sleep(60)
开发者ID:munozropero,项目名称:management_framework,代码行数:37,代码来源:experiment_description.py

示例2: playing_idol_on_event_actor_killed

# 需要导入模块: from thrift import TSerialization [as 别名]
# 或者: from thrift.TSerialization import serialize [as 别名]
def playing_idol_on_event_actor_killed(message_type, channel, channel_type, serialize):
  # 事件消息
  message = ccevent.role.ttypes.EventRoleKilled()

  # 消息反序列化
  TSerialization.deserialize(message, serialize)

  # 主角类型只能是玩家
  if message.type_ != ccentity.entity.ttypes.EntityType.TYPE_ACTOR:
    return None

  # 根据玩家ID获取所在副本ID
  playing_id = idol_types.PlayingManager.get_actor_playing(message.id_)
  if playing_id == None or playing_id == 0:
    return None

  # 获取副本对象
  playing = idol_types.PlayingManager.get(playing_id)
  if playing == None:
    return None

  # 获取玩家对象
  actor = playing.get_actor(message.id_)
  if actor == None:
    return None

  # 玩家死亡次数增加
  actor.inc_dead_count()

  log.log_debug("idol副本 玩家(%d) 死亡次数(%d)" % (message.id_, actor.get_dead_count()))

  # 获取请求代理
  request_proxy = variable_table.get_variable(ccvariable.ttypes.Variable.REQUEST_PROXY)

  # 先复活玩家
  request = ccrequest.scene.ttypes.RequestSceneRevive()
  request.actor_ = message.id_
  request.stay_revive_ = True
  # 序列化
  request_data = TSerialization.serialize(request)
  # 发送请求
  request_proxy.request(ccrequest.ttypes.RequestType.REQUEST_SCENE_REVIVE, \
      request_data, len(request_data))

  # 请求失败消息
  request = ccrequest.playing.ttypes.RequestPlayingFailure()
  request.playing_ = playing_id
  # 序列化
  request_data = TSerialization.serialize(request)
  # 发送请求
  request_proxy.request(ccrequest.ttypes.RequestType.REQUEST_PLAYING_FAILURE, \
      request_data, len(request_data))

  log.log_debug("idol副本 玩家(%d) 失败" % message.id_)
开发者ID:tonyhack,项目名称:buzz-server,代码行数:56,代码来源:idol_event.py

示例3: __configure

# 需要导入模块: from thrift import TSerialization [as 别名]
# 或者: from thrift.TSerialization import serialize [as 别名]
	def __configure (self, topic, ctype, field, field2=None): 	# ctype must be thrift.ConfigType = {SUBSCRIBE, SET_STATE, ASSIGN_NAME}
		# Create message header:
		msg_id = random.randint(0, 2147483647)
		timestamp = time.time()
		msg_header = thrift.MsgHeader(version=1, mtype=thrift.MessageType.CONFIGURE, msg_id=msg_id, source="ec", ts=timestamp )
		# Create message body:
		body_msg = thrift.ConfigMsg(ctype=ctype, field=field, field2=field2)
		# self.pub_socket.send(topic+'.#', zmq.SNDMORE)	
		# self.pub_socket.send(TSerialization.serialize(msg_header), zmq.SNDMORE)
		# self.pub_socket.send(TSerialization.serialize(body_msg))
		self.__send(topic+'.#', TSerialization.serialize(msg_header), TSerialization.serialize(body_msg))
开发者ID:munozropero,项目名称:management_framework,代码行数:13,代码来源:publisher.py

示例4: inform

# 需要导入模块: from thrift import TSerialization [as 别名]
# 或者: from thrift.TSerialization import serialize [as 别名]
	def inform(self, _topics, itype, cid=None, field=None, nodeinfo=None):
		# Create message header:
		msg_id = random.randint(0, 2147483647)
		timestamp = time.time()
		# CHECK: Using uid as source
		msg_header = thrift.MsgHeader(version=1, mtype=thrift.MessageType.INFORM, msg_id=msg_id, source=self.uid, ts=timestamp) 
		# Create message body:
		body_msg = thrift.InformMsg(itype=itype, cid=cid, field=field, nodeinfo=nodeinfo) # , nodeinfo=nodeinfo
		coded_body_msg = TSerialization.serialize(body_msg)
		# print "\n\n\n"
		self.pub_socket.send(_topics, zmq.SNDMORE)
		self.pub_socket.send(TSerialization.serialize(msg_header), zmq.SNDMORE)
		self.pub_socket.send(TSerialization.serialize(body_msg))
开发者ID:munozropero,项目名称:management_framework,代码行数:15,代码来源:common.py

示例5: release

# 需要导入模块: from thrift import TSerialization [as 别名]
# 或者: from thrift.TSerialization import serialize [as 别名]
	def release (self, topic, field):
		# Create message header:
		msg_id = random.randint(0, 2147483647)
		timestamp = time.time()
		msg_header = thrift.MsgHeader(version=1, mtype=thrift.MessageType.RELEASE, msg_id=msg_id, source="ec", ts=timestamp )
		# Create message body:
		body_msg = thrift.ReleaseMsg(field=field)

		# self.pub_socket.send(topic+'.#', zmq.SNDMORE)
		# self.pub_socket.send(TSerialization.serialize(msg_header), zmq.SNDMORE)
		# self.pub_socket.send(TSerialization.serialize(body_msg), zmq.SNDMORE)
		# self.pub_socket.send(TSerialization.serialize(attachment))
		self.__send(topic+'.#', TSerialization.serialize(msg_header),
		 TSerialization.serialize(body_msg), TSerialization.serialize(attachment))
开发者ID:munozropero,项目名称:management_framework,代码行数:16,代码来源:publisher.py

示例6: request

# 需要导入模块: from thrift import TSerialization [as 别名]
# 或者: from thrift.TSerialization import serialize [as 别名]
 def request(request_type, request):
     # 序列化请求
     data = TSerialization.serialize(request)
     # 发送请求
     if Request.REQUEST_PROXY.request(request_type, data, len(data)) != 0:
         return False
     return True
开发者ID:tonyhack,项目名称:buzz-server,代码行数:9,代码来源:proxy.py

示例7: add_award

# 需要导入模块: from thrift import TSerialization [as 别名]
# 或者: from thrift.TSerialization import serialize [as 别名]
def add_award(actor, template):
    log.log_debug("idol.add_award(%d, %d)" % (actor, template))

    request_proxy = variable_table.get_variable(ccvariable.ttypes.Variable.REQUEST_PROXY)

    # 获取副本配置
    playing_config = idol_types.Config.get(template)
    if playing_config == None:
        log.log_error("获取 副本配置失败(%d)" % template)
        return None

    # 请求增加副本奖励
    request = ccrequest.playing.ttypes.RequestPlayingAddAward()
    request.actor_ = actor
    request.playing_template_ = template
    # 奖励
    request.awards_ = playing_config.get_awards()
    # 抽奖
    draw_awards = playing_config.get_draw_awards()
    draw_awards_size = len(draw_awards)
    if draw_awards_size > 0:
        request.draw_award_ = draw_awards[random.randint(0, draw_awards_size - 1)]
    else:
        request.draw_award_ = ccentity.playing.ttypes.PlayingAwardField(ccentity.resource.ttypes.ResourceType.MIN, 0, 0)

    # 序列化
    request_data = TSerialization.serialize(request)
    # 发送请求
    request_proxy.request(ccrequest.ttypes.RequestType.REQUEST_PLAYING_ADD_AWARD, request_data, len(request_data))
开发者ID:tonyhack,项目名称:buzz-server,代码行数:31,代码来源:idol.py

示例8: write

# 需要导入模块: from thrift import TSerialization [as 别名]
# 或者: from thrift.TSerialization import serialize [as 别名]
    def write(self, comm, comm_filename=None):
        """
        Args:
            comm (Communication): communication to write to tar file
            comm_filename (str): desired filename of communication
                within tar file (by default the filename will be the
                communication id appended with a .concrete extension)
        """
        if comm_filename is None:
            comm_filename = comm.id + '.concrete'

        thrift_bytes = TSerialization.serialize(
            comm, protocol_factory=factory.protocolFactory)

        file_like_obj = BytesIO(thrift_bytes)

        comm_tarinfo = tarfile.TarInfo()
        comm_tarinfo.type = tarfile.REGTYPE
        comm_tarinfo.name = comm_filename
        comm_tarinfo.size = len(thrift_bytes)
        comm_tarinfo.mode = 0o644
        comm_tarinfo.mtime = time.time()
        comm_tarinfo.uid = _get_uid()
        comm_tarinfo.uname = _get_username()
        comm_tarinfo.gid = _get_gid()
        comm_tarinfo.gname = _get_groupname()

        self.tarfile.addfile(comm_tarinfo, file_like_obj)
开发者ID:hltcoe,项目名称:concrete-python,代码行数:30,代码来源:file_io.py

示例9: playing_slime_on_timer_boss

# 需要导入模块: from thrift import TSerialization [as 别名]
# 或者: from thrift.TSerialization import serialize [as 别名]
def playing_slime_on_timer_boss(id):
  # 获取副本对象
  playing = slime_types.PlayingManager.get(id)
  if playing == None:
    proxy.Logging.error("[slime] PlayingManager.get(%d) failed" % id)
    return None

  # 获取玩家对象
  actor = proxy.EntityManager.get_actor(playing.get_actor())
  if actor == None:
    proxy.Logging.error("[slime] get actor(%d) failed" % playing.get_actor())
    return None

  status = actor.get_basic_status()
  if status == ccentity.role.ttypes.RoleBasicStatus.STATUS_DIE:
    # 先复活玩家
    request = ccrequest.scene.ttypes.RequestSceneRevive()
    request.actor_ = message.id_
    request.stay_revive_ = True
    # 序列化
    request_data = TSerialization.serialize(request)
    # 发送请求
    request_proxy.request(ccrequest.ttypes.RequestType.REQUEST_SCENE_REVIVE, \
        request_data, len(request_data))

  request = ccrequest.playing.ttypes.RequestPlayingFailure()
  request.playing_ = id
  proxy.Request.request(ccrequest.ttypes.RequestType.REQUEST_PLAYING_FAILURE, request)
  proxy.Logging.debug("[slime] actor(%d) boss time expired." % playing.get_actor())
开发者ID:tonyhack,项目名称:buzz-server,代码行数:31,代码来源:slime_event.py

示例10: communication_to_json

# 需要导入模块: from thrift import TSerialization [as 别名]
# 或者: from thrift.TSerialization import serialize [as 别名]
def communication_to_json(comm):
    """
    Takes a Communication instance, returns a JSON string with the
    information in that Communication.
    """
    comm_json_string = TSerialization.serialize(comm, TJSONProtocol.TSimpleJSONProtocolFactory())
    comm_json = json.loads(comm_json_string)
    return json.dumps(comm_json, indent=2, separators=(',', ': '), ensure_ascii=False, sort_keys=True)
开发者ID:fmof,项目名称:concrete-python,代码行数:10,代码来源:json_fu.py

示例11: test_validate_received_token

# 需要导入模块: from thrift import TSerialization [as 别名]
# 或者: from thrift.TSerialization import serialize [as 别名]
    def test_validate_received_token(self):
        token = self.client.user_info(DN, "", "SecurityClientTest")
        nt.assert_true(self.client.validateReceivedToken(token))

        b = tser.serialize(token)
        token = EzSecurityToken()
        tser.deserialize(token, b)
        nt.assert_true(self.client.validateReceivedToken(token))
开发者ID:ezbake,项目名称:ezbake-security,代码行数:10,代码来源:test_client.py

示例12: register

# 需要导入模块: from thrift import TSerialization [as 别名]
# 或者: from thrift.TSerialization import serialize [as 别名]
 def register(self, instance):
   sync_log('Registering instance: %s' % instance)
   return self._zk.create(
       posixpath.join(self._path, 'member_'),
       codec.serialize(instance),
       [ZOO_OPEN_ACL_UNSAFE],
       zookeeper.SEQUENCE,
       )
开发者ID:JoeEnnever,项目名称:commons,代码行数:10,代码来源:client_test.py

示例13: serialize_to_base64

# 需要导入模块: from thrift import TSerialization [as 别名]
# 或者: from thrift.TSerialization import serialize [as 别名]
def serialize_to_base64(thrift_object):
    """
    Serializes the given Thrift object, and encodes it in base64.

    :param thrift_object: A thrift object that you want to serialize and encode.
    :return: Base64-Encoded and Serialzed Thrift object
    """
    serialized_object = TSerialization.serialize(thrift_object)
    return base64.b64encode(serialized_object)
开发者ID:crawlik,项目名称:ezbake-common-python,代码行数:11,代码来源:__init__.py

示例14: playing_idol_on_event_playing_actor_enter

# 需要导入模块: from thrift import TSerialization [as 别名]
# 或者: from thrift.TSerialization import serialize [as 别名]
def playing_idol_on_event_playing_actor_enter(message_type, channel, channel_type, serialize):
  # 获取事件交互代理
  communicator_proxy = variable_table.get_variable(ccvariable.ttypes.Variable.COMMUNICATOR_PROXY)

  # 获取请求代理
  request_proxy = variable_table.get_variable(ccvariable.ttypes.Variable.REQUEST_PROXY)

  # 事件消息
  message = ccevent.playing.ttypes.EventPlayingActorEnter()
  # 反序列化
  TSerialization.deserialize(message, serialize)

  # 关注玩家杀死NPC事件、角色被杀死事件
  communicator_proxy.follow(ccevent.ttypes.EventType.EVENT_ACTOR_KILL_NPC, \
      message.actor_, ccevent.ttypes.ChannelType.CHANNEL_ACTOR, \
      "playing_idol_on_event_actor_kill_npc")
  communicator_proxy.follow(ccevent.ttypes.EventType.EVENT_ROLE_KILLED, \
      message.actor_, ccevent.ttypes.ChannelType.CHANNEL_ACTOR, \
      "playing_idol_on_event_actor_killed")
  communicator_proxy.follow(ccevent.ttypes.EventType.EVENT_PLAYING_ACTOR_REQUEST_COMPLETE,\
      message.actor_, ccevent.ttypes.ChannelType.CHANNEL_ACTOR,\
      "playing_idol_on_event_playing_actor_request_complete")

  # 获取副本对象
  playing = idol_types.PlayingManager.get(message.playing_)
  if playing == None:
    log.log_error("idol副本 获取 playing(%d) 失败" % message.playing_)
    return None

  now = time.time()

  # 获取玩家对象
  actor = playing.get_actor(message.actor_)
  if actor == None:
    # 玩家不存在时,创建并加入副本管理器中
    actor = idol_types.Actor(message.actor_, now)
    playing.add_actor(actor)

  # 副本管理器中加入一个玩家ID到副本ID的对应关系
  idol_types.PlayingManager.add_actor(message.actor_, message.playing_)

  # 请求初始化玩家
  request = ccrequest.playing.ttypes.RequestPlayingInitializeActor()
  request.actor_ = message.actor_
  request.spend_time_ = now - actor.get_start_time()
  request.scores_ = []
  request.datas_ = []

  # 序列化消息
  request_data = TSerialization.serialize(request)

  # 发送请求
  request_proxy.request(ccrequest.ttypes.RequestType.REQUEST_PLAYING_INITIALIZE_ACTOR, \
      request_data, len(request_data))

  log.log_debug("玩家(%d) 进入 idol副本(id=%d,template=%d)" % \
      (message.actor_, message.playing_, message.template_))
开发者ID:tonyhack,项目名称:buzz-server,代码行数:59,代码来源:idol_event.py

示例15: verify

# 需要导入模块: from thrift import TSerialization [as 别名]
# 或者: from thrift.TSerialization import serialize [as 别名]
def verify(token, pubkey, owner, target=None):
    valid = False
    expires = token.response.expires

    # sort auths, formal access
    token.authorizations.externalCommunityAuthorizations.sort()
    token.authorizations.formalAuthorizations.sort()

    projects = token.response.securityInfo.projects
    if projects is not None:
        # sort projects
        od = OrderedDict(sorted(projects.items(), key=lambda t: t[0]))
        token.response.securityInfo.projects = od

    log = logging.getLogger(__name__)
    log.debug("verifying token {0}".format(token))

    if target is not None:
        log.info("Target not None, verifying target security ID")
        if token.response.targetSecurityId == target:
            log.info("Target security ID matches the passed target")
            if expires > current_time_millis():
                log.info("token expiration looks ok ({0} > {1})".format(expires, current_time_millis()))
                data = tser.serialize(token.response)
                sig = base64.b64decode(token.signature)
                log.info("verifying the signature")
                valid = verify_signature(data, sig, pubkey)
            else:
                log.info("expiration is bad ({0} > {1})".format(expires, current_time_millis()))
    elif token.response.securityId == owner:
        log.info("Verifying token for owner: {0}".format(owner))
        if expires > current_time_millis():
            log.info("token expiration looks ok ({0} > {1})".format(expires, current_time_millis()))
            data = tser.serialize(token.response)
            sig = base64.b64decode(token.signature)
            log.info("verifying the signature")
            valid = verify_signature(data, sig, pubkey)
        else:
            log.info("expiration is bad ({0} > {1})".format(expires, current_time_millis()))
    else:
        log.info("Not verifying token because target is none and the security ID doesn't match the owner")
    return valid
开发者ID:ezbake,项目名称:ezbake-security,代码行数:44,代码来源:util.py


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