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


Python TSerialization.serialize函数代码示例

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


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

示例1: encode

def encode(n, proto_factory=TBinaryProtocolFactory()):
    ab = make_addressbook()
    start = time.time()
    for i in range(n):
        serialize(ab, proto_factory)
    end = time.time()
    print("encode\t-> {}".format(end - start))
开发者ID:AllanDaemon,项目名称:thriftpy,代码行数:7,代码来源:benchmark_apache_thrift_struct.py

示例2: testSerializeThenDeserialize

  def testSerializeThenDeserialize(self):
    obj = Xtruct2(i32_thing=1,
                  struct_thing=Xtruct(string_thing="foo"))

    s1 = serialize(obj)
    for i in range(10):
      self.assertEquals(s1, serialize(obj))
      objcopy = Xtruct2()
      deserialize(objcopy, serialize(obj))
      self.assertEquals(obj, objcopy)

    obj = Xtruct(string_thing="bar")
    objcopy = Xtruct()
    deserialize(objcopy, serialize(obj))
    self.assertEquals(obj, objcopy)
开发者ID:Clement-Ng,项目名称:thrift-dev,代码行数:15,代码来源:SerializationTest.py

示例3: render_task_json

 def render_task_json(scheduled_task):
   """Render a single task into json. This is baroque, but it uses thrift to
   give us all of the job status data, while allowing us to compose it with
   other stuff and pretty-print it.
   """
   return json.loads(serialize(scheduled_task,
       protocol_factory=TJSONProtocol.TSimpleJSONProtocolFactory()))
开发者ID:zmanji,项目名称:incubator-aurora,代码行数:7,代码来源:jobs.py

示例4: test_launchTask_deserialization_fail

    def test_launchTask_deserialization_fail(self):  # noqa
        proxy_driver = ProxyDriver()

        role = getpass.getuser()
        task_info = mesos_pb2.TaskInfo()
        task_info.name = task_info.task_id.value = "broken"
        task_info.data = serialize(
            AssignedTask(
                task=TaskConfig(
                    job=JobKey(role=role, environment="env", name="name"),
                    owner=Identity(role=role, user=role),
                    executorConfig=ExecutorConfig(name=AURORA_EXECUTOR_NAME, data="garbage"),
                )
            )
        )

        te = FastThermosExecutor(
            runner_provider=make_provider(safe_mkdtemp()), sandbox_provider=DefaultTestSandboxProvider()
        )
        te.launchTask(proxy_driver, task_info)
        proxy_driver.wait_stopped()

        updates = proxy_driver.method_calls["sendStatusUpdate"]
        assert len(updates) == 2
        assert updates[0][0][0].state == mesos_pb2.TASK_STARTING
        assert updates[1][0][0].state == mesos_pb2.TASK_FAILED
开发者ID:rosmo,项目名称:aurora,代码行数:26,代码来源:test_thermos_executor.py

示例5: render_quota

  def render_quota(self, write_json, quota_resp):
    def get_quota_json(quota):
      result = {}
      result['cpu'] = quota.numCpus
      result['ram'] = float(quota.ramMb) / 1024
      result['disk'] = float(quota.diskMb) / 1024
      return result

    def get_quota_str(quota):
      result = []
      result.append('  CPU: %s' % quota.numCpus)
      result.append('  RAM: %f GB' % (float(quota.ramMb) / 1024))
      result.append('  Disk: %f GB' % (float(quota.diskMb) / 1024))
      return result

    if write_json:
      return serialize(quota_resp.result.getQuotaResult,
          protocol_factory=TJSONProtocol.TSimpleJSONProtocolFactory())
    else:
      quota_result = quota_resp.result.getQuotaResult
      result = ['Allocated:']
      result += get_quota_str(quota_result.quota)
      if quota_result.prodConsumption:
        result.append('Production resources consumed:')
        result += get_quota_str(quota_result.prodConsumption)
      if quota_result.nonProdConsumption:
        result.append('Non-production resources consumed:')
        result += get_quota_str(quota_result.nonProdConsumption)
      return '\n'.join(result)
开发者ID:bhuvan,项目名称:incubator-aurora,代码行数:29,代码来源:quota.py

示例6: render_quota

  def render_quota(self, write_json, quota_resp):
    def get_quota_str(quota):
      resource_details = ResourceManager.resource_details_from_quota(quota)
      return ('  %s: %s%s' % (
          r.resource_type.display_name,
          r.value,
          r.resource_type.display_unit) for r in resource_details)

    if write_json:
      return serialize(quota_resp.result.getQuotaResult,
          protocol_factory=TJSONProtocol.TSimpleJSONProtocolFactory())
    else:
      quota_result = quota_resp.result.getQuotaResult
      result = ['Allocated:']
      result += get_quota_str(quota_result.quota)
      if quota_result.prodSharedConsumption:
        result.append('Production shared pool resources consumed:')
        result += get_quota_str(quota_result.prodSharedConsumption)
      if quota_result.prodDedicatedConsumption:
        result.append('Production dedicated pool resources consumed:')
        result += get_quota_str(quota_result.prodDedicatedConsumption)
      if quota_result.nonProdSharedConsumption:
        result.append('Non-production shared pool resources consumed:')
        result += get_quota_str(quota_result.nonProdSharedConsumption)
      if quota_result.nonProdDedicatedConsumption:
        result.append('Non-production dedicated pool resources consumed:')
        result += get_quota_str(quota_result.nonProdDedicatedConsumption)
      return '\n'.join(result)
开发者ID:AltanAlpay,项目名称:aurora,代码行数:28,代码来源:quota.py

示例7: render_quota

    def render_quota(self, write_json, quota_resp):
        def get_quota_json(quota):
            result = {}
            result["cpu"] = quota.numCpus
            result["ram"] = float(quota.ramMb) / 1024
            result["disk"] = float(quota.diskMb) / 1024
            return result

        def get_quota_str(quota):
            result = []
            result.append("  CPU: %s" % quota.numCpus)
            result.append("  RAM: %f GB" % (float(quota.ramMb) / 1024))
            result.append("  Disk: %f GB" % (float(quota.diskMb) / 1024))
            return result

        if write_json:
            return serialize(
                quota_resp.result.getQuotaResult, protocol_factory=TJSONProtocol.TSimpleJSONProtocolFactory()
            )
        else:
            quota_result = quota_resp.result.getQuotaResult
            result = ["Allocated:"]
            result += get_quota_str(quota_result.quota)
            if quota_result.prodConsumption:
                result.append("Production resources consumed:")
                result += get_quota_str(quota_result.prodConsumption)
            if quota_result.nonProdConsumption:
                result.append("Non-production resources consumed:")
                result += get_quota_str(quota_result.nonProdConsumption)
            return "\n".join(result)
开发者ID:kpeterson1,项目名称:aurora,代码行数:30,代码来源:quota.py

示例8: decode

def decode(n, proto_factory=TBinaryProtocolFactory()):
    ab = ttypes.AddressBook()
    ab_encoded = serialize(make_addressbook())
    start = time.time()
    for i in range(n):
        deserialize(ab, ab_encoded, proto_factory)
    end = time.time()
    print("decode\t-> {}".format(end - start))
开发者ID:AllanDaemon,项目名称:thriftpy,代码行数:8,代码来源:benchmark_apache_thrift_struct.py

示例9: create_address

def create_address(host, port):
    """Serialize the given address to thrift ServerAddress.

    :type host: str
    :type port: int
    :rtype: str
    """
    address = ServerAddress(host, port)
    return serialize(address)
开发者ID:aasthabh,项目名称:photon-controller,代码行数:9,代码来源:address.py

示例10: serialize_content

 def serialize_content(content):
     """ Серилизация контента товара для БД Cassandra.
     :param content: контент, который необходимо сериализовать
     :return: строка
     """
     p = WarehouseMethods.build_dict_for_WareContentDto(content)
     content = WarehouseMethods.get_WareContentDto(**p)
     content_obj = serialize(content)
     service_log.put("Serialized content: %s" % str(content_obj))
     return content_obj
开发者ID:Maksim1988,项目名称:test,代码行数:10,代码来源:class_warehouse.py

示例11: next_tuple

 def next_tuple(self):
     try:
         msg_body = next(self.msg_bodies)
         msg = Message(type=MsgType.TYPE_A, body=msg_body, score=98.7654321)
         ser_msg = b2a_base64(serialize(msg))
         self.log('emitting message: {}'.format(msg))
         self.log('serialized message: {}'.format(ser_msg))
         self.emit([ser_msg], tup_id=hash(msg))
     except StopIteration:
         sleep(10)
         pass
开发者ID:Detoo,项目名称:storm-thrift-tuple,代码行数:11,代码来源:msg_sender_spout.py

示例12: testSerializeThenDeserialize

  def testSerializeThenDeserialize(self):
    obj = Xtruct2(i32_thing=1,
                  struct_thing=Xtruct(string_thing="foo"))

    s1 = serialize(obj)
    for i in range(10):
      self.assertEquals(s1, serialize(obj))
      objcopy = Xtruct2()
      deserialize(objcopy, serialize(obj))
      self.assertEquals(obj, objcopy)

    obj = Xtruct(string_thing="bar")
    objcopy = Xtruct()
    deserialize(objcopy, serialize(obj))
    self.assertEquals(obj, objcopy)

    # test booleans
    obj = Bools(im_true=True, im_false=False)
    objcopy = Bools()
    deserialize(objcopy, serialize(obj))
    self.assertEquals(obj, objcopy)

    # test enums
    for num, name in Numberz._VALUES_TO_NAMES.items():
      obj = Bonk(message='enum Numberz value %d is string %s' % (num, name), type=num)
      objcopy = Bonk()
      deserialize(objcopy, serialize(obj))
      self.assertEquals(obj, objcopy)
开发者ID:AltspaceVR,项目名称:thrift,代码行数:28,代码来源:SerializationTest.py

示例13: test_launchTask_deserialization_fail

  def test_launchTask_deserialization_fail(self):
    proxy_driver = ProxyDriver()

    task_info = mesos_pb.TaskInfo()
    task_info.name = task_info.task_id.value = 'broken'
    task_info.data = serialize(AssignedTask(task=TaskConfig(executorConfig=ExecutorConfig(
        name=AURORA_EXECUTOR_NAME,
        data='garbage'))))

    te = ThermosExecutor(
        runner_provider=make_provider(safe_mkdtemp()),
        sandbox_provider=DefaultTestSandboxProvider)
    te.launchTask(proxy_driver, task_info)

    updates = proxy_driver.method_calls['sendStatusUpdate']
    assert len(updates) == 1
    assert updates[0][0][0].state == mesos_pb.TASK_FAILED
开发者ID:Empia,项目名称:incubator-aurora,代码行数:17,代码来源:test_thermos_executor.py

示例14: make_task

def make_task(thermos_config, assigned_ports={}, **kw):
  role = getpass.getuser()
  task_id = thermos_config.task().name().get() + '-001'
  at = AssignedTask(
      taskId=task_id,
      task=TaskConfig(
          executorConfig=ExecutorConfig(
              name=AURORA_EXECUTOR_NAME,
              data=thermos_config.json_dumps()),
          job=JobKey(role=role, environment='env', name='name')),
      assignedPorts=assigned_ports,
      **kw)
  td = mesos_pb2.TaskInfo()
  td.task_id.value = task_id
  td.name = thermos_config.task().name().get()
  td.data = serialize(at)
  return td
开发者ID:bmhatfield,项目名称:aurora,代码行数:17,代码来源:test_thermos_executor.py

示例15: render_task_json

   def render_task_json(scheduled_task):
       """Render a single task into json. This is baroque, but it uses thrift to
 give us all of the job status data, while allowing us to compose it with
 other stuff and pretty-print it.
 """
       task = json.loads(serialize(scheduled_task, protocol_factory=TJSONProtocol.TSimpleJSONProtocolFactory()))
       # Now, clean it up: take all fields that are actually enums, and convert
       # their values to strings.
       task["status"] = ScheduleStatus._VALUES_TO_NAMES[task["status"]]
       events = sorted(task["taskEvents"], key=lambda event: event["timestamp"])
       for event in events:
           event["status"] = ScheduleStatus._VALUES_TO_NAMES[event["status"]]
       # convert boolean fields to boolean value names.
       assigned = task["assignedTask"]
       task_config = assigned["task"]
       task_config["isService"] = task_config["isService"] != 0
       if "production" in task_config:
           task_config["production"] = task_config["production"] != 0
       return task
开发者ID:reneploetz,项目名称:aurora,代码行数:19,代码来源:jobs.py


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