本文整理汇总了Python中google.protobuf.json_format.ParseDict方法的典型用法代码示例。如果您正苦于以下问题:Python json_format.ParseDict方法的具体用法?Python json_format.ParseDict怎么用?Python json_format.ParseDict使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类google.protobuf.json_format
的用法示例。
在下文中一共展示了json_format.ParseDict方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _disable_auto_scheduling
# 需要导入模块: from google.protobuf import json_format [as 别名]
# 或者: from google.protobuf.json_format import ParseDict [as 别名]
def _disable_auto_scheduling(config: Union[dict, TransferConfig]) -> TransferConfig:
"""
In the case of Airflow, the customer needs to create a transfer config
with the automatic scheduling disabled (UI, CLI or an Airflow operator) and
then trigger a transfer run using a specialized Airflow operator that will
call start_manual_transfer_runs.
:param config: Data transfer configuration to create.
:type config: Union[dict, google.cloud.bigquery_datatransfer_v1.types.TransferConfig]
"""
config = MessageToDict(config) if isinstance(config, TransferConfig) else config
new_config = copy(config)
schedule_options = new_config.get("schedule_options")
if schedule_options:
disable_auto_scheduling = schedule_options.get(
"disable_auto_scheduling", None
)
if disable_auto_scheduling is None:
schedule_options["disable_auto_scheduling"] = True
else:
new_config["schedule_options"] = {"disable_auto_scheduling": True}
return ParseDict(new_config, TransferConfig())
示例2: _get_engine_properties
# 需要导入模块: from google.protobuf import json_format [as 别名]
# 或者: from google.protobuf.json_format import ParseDict [as 别名]
def _get_engine_properties(properties):
"""Retrieve and resurrect JSON serialized engine properties from all
properties passed to recipe.
The serialized value is associated with key '$recipe_engine'.
Args:
* properties (dict): All input properties for passed to recipe
Returns a engine_properties_pb2.EngineProperties object
"""
return jsonpb.ParseDict(
properties.get('$recipe_engine', {}),
engine_properties_pb2.EngineProperties(),
ignore_unknown_fields=True)
示例3: return_type
# 需要导入模块: from google.protobuf import json_format [as 别名]
# 或者: from google.protobuf.json_format import ParseDict [as 别名]
def return_type(self):
"""google.cloud.bigquery_v2.types.StandardSqlDataType: Return type of
the routine.
If absent, the return type is inferred from
:attr:`~google.cloud.bigquery.routine.Routine.body` at query time in
each query that references this routine. If present, then the
evaluated result will be cast to the specified returned type at query
time.
See:
https://cloud.google.com/bigquery/docs/reference/rest/v2/routines#Routine.FIELDS.return_type
"""
resource = self._properties.get(self._PROPERTY_TO_API_FIELD["return_type"])
if not resource:
return resource
output = google.cloud.bigquery_v2.types.StandardSqlDataType()
output = json_format.ParseDict(resource, output, ignore_unknown_fields=True)
return output
示例4: from_api_repr
# 需要导入模块: from google.protobuf import json_format [as 别名]
# 或者: from google.protobuf.json_format import ParseDict [as 别名]
def from_api_repr(cls, resource):
"""Factory: construct a model reference given its API representation
Args:
resource (Dict[str, object]):
Model reference representation returned from the API
Returns:
google.cloud.bigquery.model.ModelReference:
Model reference parsed from ``resource``.
"""
ref = cls()
# Keep a reference to the resource as a workaround to find unknown
# field values.
ref._properties = resource
ref._proto = json_format.ParseDict(
resource, types.ModelReference(), ignore_unknown_fields=True
)
return ref
示例5: initialize
# 需要导入模块: from google.protobuf import json_format [as 别名]
# 或者: from google.protobuf.json_format import ParseDict [as 别名]
def initialize(self):
# Add other LUCI_CONTEXT sections in the following dict to support
# modification through this module.
init_sections = {
'luciexe': sections_pb2.LUCIExe,
}
ctx = self._lucictx_client.context
for section_key, section_msg_class in init_sections.iteritems():
if section_key in ctx:
self._state.luci_context[section_key] = (
jsonpb.ParseDict(ctx[section_key],
section_msg_class(),
ignore_unknown_fields=True))
示例6: deserialize
# 需要导入模块: from google.protobuf import json_format [as 别名]
# 或者: from google.protobuf.json_format import ParseDict [as 别名]
def deserialize(data):
"""Deserializes an invocation bundle. Opposite of serialize()."""
ret = {}
def parse_msg(msg, body):
return json_format.ParseDict(
body, msg,
# Do not fail the build because recipe's proto copy is stale.
ignore_unknown_fields=True
)
for line in data.splitlines():
entry = json.loads(line)
assert isinstance(entry, dict), line
inv_id = entry['invocationId']
inv = ret.get(inv_id)
if not inv:
inv = Invocation()
ret[inv_id] = inv
inv_dict = entry.get('invocation')
if inv_dict is not None:
# Invocation is special because there can be only one invocation
# per invocation id.
parse_msg(inv.proto, inv_dict)
continue
found = False
for attr_name, type, key in Invocation._COLLECTIONS:
if key in entry:
found = True
collection = getattr(inv, attr_name)
collection.append(parse_msg(type(), entry[key]))
break
assert found, entry
return ret
示例7: __init__
# 需要导入模块: from google.protobuf import json_format [as 别名]
# 或者: from google.protobuf.json_format import ParseDict [as 别名]
def __init__(self, init_state, **kwargs):
super(SchedulerApi, self).__init__(**kwargs)
self._host = init_state.get('hostname') or 'luci-scheduler.appspot.com'
self._fake_uuid_count = 0
self._triggers = []
for t_dict in init_state.get('triggers') or []:
self._triggers.append(
json_format.ParseDict(t_dict, triggers_pb2.Trigger()))
示例8: dict2msg
# 需要导入模块: from google.protobuf import json_format [as 别名]
# 或者: from google.protobuf.json_format import ParseDict [as 别名]
def dict2msg(d, message, ignore_unknown_fields=False):
return ParseDict(d, message, ignore_unknown_fields=ignore_unknown_fields)
示例9: testExtensionToDictAndBack
# 需要导入模块: from google.protobuf import json_format [as 别名]
# 或者: from google.protobuf.json_format import ParseDict [as 别名]
def testExtensionToDictAndBack(self):
message = unittest_mset_pb2.TestMessageSetContainer()
ext1 = unittest_mset_pb2.TestMessageSetExtension1.message_set_extension
ext2 = unittest_mset_pb2.TestMessageSetExtension2.message_set_extension
message.message_set.Extensions[ext1].i = 23
message.message_set.Extensions[ext2].str = 'foo'
message_dict = json_format.MessageToDict(
message
)
parsed_message = unittest_mset_pb2.TestMessageSetContainer()
json_format.ParseDict(message_dict, parsed_message)
self.assertEqual(message, parsed_message)
示例10: testParseDict
# 需要导入模块: from google.protobuf import json_format [as 别名]
# 或者: from google.protobuf.json_format import ParseDict [as 别名]
def testParseDict(self):
expected = 12345
js_dict = {'int32Value': expected}
message = json_format_proto3_pb2.TestMessage()
json_format.ParseDict(js_dict, message)
self.assertEqual(expected, message.int32_value)
示例11: _load_test_json
# 需要导入模块: from google.protobuf import json_format [as 别名]
# 或者: from google.protobuf.json_format import ParseDict [as 别名]
def _load_test_json(filename):
with open(filename, "r") as tp_file:
tp_json = json.load(tp_file)
test_file = tests_pb2.TestFile()
json_format.ParseDict(tp_json, test_file)
shortname = os.path.split(filename)[-1]
for test_proto in test_file.tests:
test_proto.description = test_proto.description + " (%s)" % shortname
yield test_proto
示例12: test_stackdriver_enable_alert_policy
# 需要导入模块: from google.protobuf import json_format [as 别名]
# 或者: from google.protobuf.json_format import ParseDict [as 别名]
def test_stackdriver_enable_alert_policy(self, mock_policy_client, mock_get_creds_and_project_id):
hook = stackdriver.StackdriverHook()
alert_policy_enabled = ParseDict(TEST_ALERT_POLICY_1, monitoring_v3.types.alert_pb2.AlertPolicy())
alert_policy_disabled = ParseDict(TEST_ALERT_POLICY_2, monitoring_v3.types.alert_pb2.AlertPolicy())
alert_policies = [alert_policy_enabled, alert_policy_disabled]
mock_policy_client.return_value.list_alert_policies.return_value = alert_policies
hook.enable_alert_policies(
filter_=TEST_FILTER,
project_id=PROJECT_ID,
)
mock_policy_client.return_value.list_alert_policies.assert_called_once_with(
name='projects/{project}'.format(project=PROJECT_ID),
filter_=TEST_FILTER,
retry=DEFAULT,
timeout=DEFAULT,
order_by=None,
page_size=None,
metadata=None,
)
mask = monitoring_v3.types.field_mask_pb2.FieldMask()
alert_policy_disabled.enabled.value = True # pylint: disable=no-member
mask.paths.append('enabled') # pylint: disable=no-member
mock_policy_client.return_value.update_alert_policy.assert_called_once_with(
alert_policy=alert_policy_disabled,
update_mask=mask,
retry=DEFAULT,
timeout=DEFAULT,
metadata=None,
)
示例13: test_stackdriver_disable_alert_policy
# 需要导入模块: from google.protobuf import json_format [as 别名]
# 或者: from google.protobuf.json_format import ParseDict [as 别名]
def test_stackdriver_disable_alert_policy(self, mock_policy_client, mock_get_creds_and_project_id):
hook = stackdriver.StackdriverHook()
alert_policy_enabled = ParseDict(TEST_ALERT_POLICY_1, monitoring_v3.types.alert_pb2.AlertPolicy())
alert_policy_disabled = ParseDict(TEST_ALERT_POLICY_2, monitoring_v3.types.alert_pb2.AlertPolicy())
mock_policy_client.return_value.list_alert_policies.return_value = [
alert_policy_enabled,
alert_policy_disabled
]
hook.disable_alert_policies(
filter_=TEST_FILTER,
project_id=PROJECT_ID,
)
mock_policy_client.return_value.list_alert_policies.assert_called_once_with(
name='projects/{project}'.format(project=PROJECT_ID),
filter_=TEST_FILTER,
retry=DEFAULT,
timeout=DEFAULT,
order_by=None,
page_size=None,
metadata=None,
)
mask = monitoring_v3.types.field_mask_pb2.FieldMask()
alert_policy_enabled.enabled.value = False # pylint: disable=no-member
mask.paths.append('enabled') # pylint: disable=no-member
mock_policy_client.return_value.update_alert_policy.assert_called_once_with(
alert_policy=alert_policy_enabled,
update_mask=mask,
retry=DEFAULT,
timeout=DEFAULT,
metadata=None,
)
示例14: test_stackdriver_enable_notification_channel
# 需要导入模块: from google.protobuf import json_format [as 别名]
# 或者: from google.protobuf.json_format import ParseDict [as 别名]
def test_stackdriver_enable_notification_channel(self, mock_channel_client,
mock_get_creds_and_project_id):
hook = stackdriver.StackdriverHook()
notification_channel_enabled = ParseDict(TEST_NOTIFICATION_CHANNEL_1,
monitoring_v3.types.notification_pb2.NotificationChannel())
notification_channel_disabled = ParseDict(TEST_NOTIFICATION_CHANNEL_2,
monitoring_v3.types.notification_pb2.NotificationChannel())
mock_channel_client.return_value.list_notification_channels.return_value = [
notification_channel_enabled,
notification_channel_disabled
]
hook.enable_notification_channels(
filter_=TEST_FILTER,
project_id=PROJECT_ID,
)
notification_channel_disabled.enabled.value = True # pylint: disable=no-member
mask = monitoring_v3.types.field_mask_pb2.FieldMask()
mask.paths.append('enabled') # pylint: disable=no-member
mock_channel_client.return_value.update_notification_channel.assert_called_once_with(
notification_channel=notification_channel_disabled,
update_mask=mask,
retry=DEFAULT,
timeout=DEFAULT,
metadata=None,
)
示例15: test_stackdriver_disable_notification_channel
# 需要导入模块: from google.protobuf import json_format [as 别名]
# 或者: from google.protobuf.json_format import ParseDict [as 别名]
def test_stackdriver_disable_notification_channel(self, mock_channel_client,
mock_get_creds_and_project_id):
hook = stackdriver.StackdriverHook()
notification_channel_enabled = ParseDict(TEST_NOTIFICATION_CHANNEL_1,
monitoring_v3.types.notification_pb2.NotificationChannel())
notification_channel_disabled = ParseDict(TEST_NOTIFICATION_CHANNEL_2,
monitoring_v3.types.notification_pb2.NotificationChannel())
mock_channel_client.return_value.list_notification_channels.return_value = [
notification_channel_enabled,
notification_channel_disabled
]
hook.disable_notification_channels(
filter_=TEST_FILTER,
project_id=PROJECT_ID,
)
notification_channel_enabled.enabled.value = False # pylint: disable=no-member
mask = monitoring_v3.types.field_mask_pb2.FieldMask()
mask.paths.append('enabled') # pylint: disable=no-member
mock_channel_client.return_value.update_notification_channel.assert_called_once_with(
notification_channel=notification_channel_enabled,
update_mask=mask,
retry=DEFAULT,
timeout=DEFAULT,
metadata=None,
)