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


Python struct_pb2.Struct方法代码示例

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


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

示例1: _to_bq_value

# 需要导入模块: from google.protobuf import struct_pb2 [as 别名]
# 或者: from google.protobuf.struct_pb2 import Struct [as 别名]
def _to_bq_value(value, field_desc):
  if field_desc.enum_type:
    # Enums are stored as strings.
    enum_val = field_desc.enum_type.values_by_number.get(value)
    if not enum_val:
      raise ValueError('Invalid value %r for enum type %s' % (
          value, field_desc.enum_type.full_name))
    return enum_val.name
  elif isinstance(value, duration_pb2.Duration):
    return value.ToTimedelta().total_seconds()
  elif isinstance(value, struct_pb2.Struct):
    # Structs are stored as JSONPB strings,
    # see https://bit.ly/chromium-bq-struct
    return json_format.MessageToJson(value)
  elif isinstance(value, timestamp_pb2.Timestamp):
    return value.ToDatetime().isoformat()
  elif isinstance(value, message_pb.Message):
    return message_to_dict(value)
  else:
    return value 
开发者ID:luci,项目名称:luci-py,代码行数:22,代码来源:bqh.py

示例2: __init__

# 需要导入模块: from google.protobuf import struct_pb2 [as 别名]
# 或者: from google.protobuf.struct_pb2 import Struct [as 别名]
def __init__(self, id, type, metadata, interface, custom, container=None):
        """
        A task template represents the full set of information necessary to perform a unit of work in the Flyte system.
        It contains the metadata about what inputs and outputs are consumed or produced.  It also contains the metadata
        necessary for Flyte Propeller to do the appropriate work.

        :param flytekit.models.core.identifier.Identifier id: This is generated by the system and uniquely identifies
            the task.
        :param Text type: This is used to define additional extensions for use by Propeller or SDK.
        :param TaskMetadata metadata: This contains information needed at runtime to determine behavior such as
            whether or not outputs are discoverable, timeouts, and retries.
        :param flytekit.models.interface.TypedInterface interface: The interface definition for this task.
        :param dict[Text, T] custom: Dictionary that must be serializable to a protobuf Struct for custom task plugins.
        :param Container container: Provides the necessary entrypoint information for execution.  For instance,
            a Container might be specified with the necessary command line arguments.
        """
        self._id = id
        self._type = type
        self._metadata = metadata
        self._interface = interface
        self._custom = custom
        self._container = container 
开发者ID:lyft,项目名称:flytekit,代码行数:24,代码来源:task.py

示例3: to_flyte_idl

# 需要导入模块: from google.protobuf import struct_pb2 [as 别名]
# 或者: from google.protobuf.struct_pb2 import Struct [as 别名]
def to_flyte_idl(self):
        """
        :rtype: flyteidl.core.types_pb2.LiteralType
        """
        if self.metadata is not None:
            metadata = _json_format.Parse(_json.dumps(self.metadata), _struct.Struct())
        else:
            metadata = None
        t = _types_pb2.LiteralType(
            simple=self.simple if self.simple is not None else None,
            schema=self.schema.to_flyte_idl() if self.schema is not None else None,
            collection_type=self.collection_type.to_flyte_idl() if self.collection_type is not None else None,
            map_value_type=self.map_value_type.to_flyte_idl() if self.map_value_type is not None else None,
            blob=self.blob.to_flyte_idl() if self.blob is not None else None,
            metadata=metadata
        )
        return t 
开发者ID:lyft,项目名称:flytekit,代码行数:19,代码来源:types.py

示例4: from_python_std

# 需要导入模块: from google.protobuf import struct_pb2 [as 别名]
# 或者: from google.protobuf.struct_pb2 import Struct [as 别名]
def from_python_std(cls, t_value):
        """
        :param T t_value: It is up to each individual object as to whether or not this value can be cast.
        :rtype: FlyteSdkValue
        :raises: flytekit.common.exceptions.user.FlyteTypeException
        """
        if t_value is None:
            return _base_sdk_types.Void()
        elif not isinstance(t_value, dict):
            raise _user_exceptions.FlyteTypeException(type(t_value), dict, t_value)

        try:
            t = _json.dumps(t_value)
        except:
            raise _user_exceptions.FlyteValueException(
                t_value,
                "Is not JSON serializable."
            )

        return cls(_json_format.Parse(t, _struct.Struct())) 
开发者ID:lyft,项目名称:flytekit,代码行数:22,代码来源:primitives.py

示例5: testInvalidStruct

# 需要导入模块: from google.protobuf import struct_pb2 [as 别名]
# 或者: from google.protobuf.struct_pb2 import Struct [as 别名]
def testInvalidStruct(self):
    message = json_format_proto3_pb2.TestStruct()
    text = '{"value": 1234}'
    self.assertRaisesRegex(
        json_format.ParseError,
        'Failed to parse value field: Struct must be in a dict which is 1234',
        json_format.Parse, text, message) 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:9,代码来源:json_format_test.py

示例6: testInvalidStruct

# 需要导入模块: from google.protobuf import struct_pb2 [as 别名]
# 或者: from google.protobuf.struct_pb2 import Struct [as 别名]
def testInvalidStruct(self):
    message = json_format_proto3_pb2.TestStruct()
    text = '{"value": 1234}'
    self.assertRaisesRegexp(
        json_format.ParseError,
        'Failed to parse value field: Struct must be in a dict which is 1234',
        json_format.Parse, text, message) 
开发者ID:abhisuri97,项目名称:auto-alt-text-lambda-api,代码行数:9,代码来源:json_format_test.py

示例7: parameters_struct_to_msg

# 需要导入模块: from google.protobuf import struct_pb2 [as 别名]
# 或者: from google.protobuf.struct_pb2 import Struct [as 别名]
def parameters_struct_to_msg(parameters):
    """Convert Dialogflow parameter (Google Struct) into ros msg
    :param parameters:
    :type parameters: struct_pb2.Struct
    :return: List of DF Param msgs or empty list
    :rtype: (list of DialogflowParameter) or None
    """
    if parameters.items():
        param_list = []
        for name, value in parameters.items():
            param = DialogflowParameter(param_name=str(name), value=[str(value)])
            param_list.append(param)
        return param_list
    else:
        return [] 
开发者ID:piraka9011,项目名称:dialogflow_ros,代码行数:17,代码来源:converters.py

示例8: params_msg_to_struct

# 需要导入模块: from google.protobuf import struct_pb2 [as 别名]
# 或者: from google.protobuf.struct_pb2 import Struct [as 别名]
def params_msg_to_struct(parameters):
    """Create a DF compatible parameter dictionary
    :param parameters: DialogflowParameter message
    :type parameters: list(DialogflowParameter)
    :return: Parameters as a dictionary (Technically)
    :rtype: struct_pb2.Struct
    """
    google_struct = struct_pb2.Struct()
    for param in parameters:
        google_struct[param.param_name] = param.value
    return google_struct 
开发者ID:piraka9011,项目名称:dialogflow_ros,代码行数:13,代码来源:converters.py

示例9: _test_bot_events_simple

# 需要导入模块: from google.protobuf import struct_pb2 [as 别名]
# 或者: from google.protobuf.struct_pb2 import Struct [as 别名]
def _test_bot_events_simple(self, request):
    self.set_as_bot()
    self.do_handshake()
    self.set_as_user()
    raw_resp = self.app.post(
        '/prpc/swarming.v1.BotAPI/Events', _encode(request), self._headers)
    expected = swarming_pb2.BotEventsResponse(
      events=[
        swarming_pb2.BotEvent(
          event_time=timestamp_pb2.Timestamp(seconds=1262401445),
          bot=swarming_pb2.Bot(
            bot_id='bot1',
            pools=['default'],
            info=swarming_pb2.BotInfo(
              supplemental=struct_pb2.Struct(
                fields={
                  'running_time': struct_pb2.Value(number_value=1234.0),
                  'sleep_streak': struct_pb2.Value(number_value=0),
                  'started_ts': struct_pb2.Value(number_value=1410990411.11),
                }),
              external_ip='192.168.2.2',
              authenticated_as='bot:whitelisted-ip',
              version='123',
              ),
            dimensions=[
              swarming_pb2.StringListPair(key='id', values=['bot1']),
              swarming_pb2.StringListPair(key='os', values=['Amiga']),
              swarming_pb2.StringListPair(key='pool', values=['default']),
            ]),
          event=swarming_pb2.BOT_NEW_SESSION,
        ),
      ])
    resp = swarming_pb2.BotEventsResponse()
    _decode(raw_resp.body, resp)
    self.assertEqual(unicode(expected), unicode(resp)) 
开发者ID:luci,项目名称:luci-py,代码行数:37,代码来源:handlers_prpc_test.py

示例10: test_send_to_bq

# 需要导入模块: from google.protobuf import struct_pb2 [as 别名]
# 或者: from google.protobuf.struct_pb2 import Struct [as 别名]
def test_send_to_bq(self):
    payloads = []
    def json_request(url, method, payload, scopes, deadline):
      self.assertEqual(
          'https://www.googleapis.com/bigquery/v2/projects/sample-app/datasets/'
          'swarming/tables/foo/insertAll', url)
      payloads.append(payload)
      self.assertEqual('POST', method)
      self.assertEqual(bq_state.bqh.INSERT_ROWS_SCOPE, scopes)
      self.assertEqual(600, deadline)
      return {'insertErrors': []}
    self.mock(bq_state.net, 'json_request', json_request)

    rows = [
        ('key1', struct_pb2.Struct()),
        ('key2', struct_pb2.Struct()),
    ]
    self.assertEqual(0, bq_state.send_to_bq('foo', rows))
    expected = [
        {
            'ignoreUnknownValues': False,
            'kind': 'bigquery#tableDataInsertAllRequest',
            'skipInvalidRows': True,
        },
    ]
    actual_rows = payloads[0].pop('rows')
    self.assertEqual(expected, payloads)
    self.assertEqual(2, len(actual_rows)) 
开发者ID:luci,项目名称:luci-py,代码行数:30,代码来源:bq_state_test.py

示例11: test_BotEvent_proto_maintenance

# 需要导入模块: from google.protobuf import struct_pb2 [as 别名]
# 或者: from google.protobuf.struct_pb2 import Struct [as 别名]
def test_BotEvent_proto_maintenance(self):
    # Also test a misconfigured bot not in a pool.
    event_key = _bot_event(
        event_type=u'bot_connected',
        bot_id=u'id1',
        dimensions={u'id': [u'id1']},
        maintenance_msg=u'Too hot')
    actual = swarming_pb2.BotEvent()
    event_key.get().to_proto(actual)
    expected = swarming_pb2.BotEvent(
        event=swarming_pb2.BOT_NEW_SESSION,
        bot=swarming_pb2.Bot(
            bot_id=u'id1',
            dimensions=[
                swarming_pb2.StringListPair(key=u'id', values=[u'id1']),
            ],
            status=swarming_pb2.OVERHEAD_MAINTENANCE_EXTERNAL,
            status_msg=u'Too hot',
            info=swarming_pb2.BotInfo(
                supplemental=struct_pb2.Struct(fields={
                    u'ram': struct_pb2.Value(number_value=65),
                }),
                version=_VERSION,
                external_ip=u'8.8.4.4',
                authenticated_as=u'bot:id1.domain',
            ),
        ),
    )
    expected.event_time.FromDatetime(self.now)
    self.assertEqual(unicode(expected), unicode(actual)) 
开发者ID:luci,项目名称:luci-py,代码行数:32,代码来源:bot_management_test.py

示例12: encode

# 需要导入模块: from google.protobuf import struct_pb2 [as 别名]
# 或者: from google.protobuf.struct_pb2 import Struct [as 别名]
def encode(msg: Message) -> bytes:
        """Encode a message into bytes using Protobuf."""
        body_json = Struct()
        body_json.update(msg.body)  # pylint: disable=no-member
        body_bytes = body_json.SerializeToString()
        return body_bytes 
开发者ID:fetchai,项目名称:agents-aea,代码行数:8,代码来源:base.py

示例13: decode

# 需要导入模块: from google.protobuf import struct_pb2 [as 别名]
# 或者: from google.protobuf.struct_pb2 import Struct [as 别名]
def decode(obj: bytes) -> Message:
        """Decode bytes into a message using Protobuf."""
        body_json = Struct()
        body_json.ParseFromString(obj)

        body = dict(body_json)
        msg = Message(body=body)
        return msg 
开发者ID:fetchai,项目名称:agents-aea,代码行数:10,代码来源:base.py

示例14: to_flyte_idl

# 需要导入模块: from google.protobuf import struct_pb2 [as 别名]
# 或者: from google.protobuf.struct_pb2 import Struct [as 别名]
def to_flyte_idl(self):
        """
        :rtype: flyteidl.core.tasks_pb2.TaskTemplate
        """
        return _core_task.TaskTemplate(
            id=self.id.to_flyte_idl(),
            type=self.type,
            metadata=self.metadata.to_flyte_idl(),
            interface=self.interface.to_flyte_idl(),
            custom=_json_format.Parse(_json.dumps(self.custom), _struct.Struct()) if self.custom else None,
            container=self.container.to_flyte_idl() if self.container else None
        ) 
开发者ID:lyft,项目名称:flytekit,代码行数:14,代码来源:task.py

示例15: from_flyte_idl

# 需要导入模块: from google.protobuf import struct_pb2 [as 别名]
# 或者: from google.protobuf.struct_pb2 import Struct [as 别名]
def from_flyte_idl(cls, idl_object):
        """

        :param _struct.Struct idl_object:
        :return: FlyteCustomIdlEntity
        """
        return cls.from_dict(idl_dict=_json_format.MessageToDict(idl_object)) 
开发者ID:lyft,项目名称:flytekit,代码行数:9,代码来源:common.py


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