Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

fix: Improve transcoding error message#442

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
parthea merged 2 commits intogoogleapis:mainfromvam-google:master
Sep 14, 2022
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 29 additions & 6 deletionsgoogle/api_core/path_template.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -272,23 +272,27 @@ def transcode(http_options, message=None, **request_kwargs):
ValueError: If the request does not match the given template.
"""
transcoded_value = message or request_kwargs
bindings = []
for http_option in http_options:
request = {}

# Assign path
uri_template = http_option["uri"]
path_fields = [
match.group("name") for match in _VARIABLE_RE.finditer(uri_template)
fields = [
(m.group("name"), m.group("template"))
for m in _VARIABLE_RE.finditer(uri_template)
]
path_args = {field: get_field(transcoded_value, field) for field in path_fields}
bindings.append((uri_template, fields))

path_args = {field: get_field(transcoded_value, field) for field, _ in fields}
request["uri"] = expand(uri_template, **path_args)

if not validate(uri_template, request["uri"]) or not all(path_args.values()):
continue

# Remove fields used in uri path from request
leftovers = copy.deepcopy(transcoded_value)
for path_fieldinpath_fields:
for path_field, _infields:
delete_field(leftovers, path_field)

# Assign body and query params
Expand DownExpand Up@@ -316,8 +320,27 @@ def transcode(http_options, message=None, **request_kwargs):
request["method"] = http_option["method"]
return request

bindings_description = [
'\n\tURI: "{}"'
"\n\tRequired request fields:\n\t\t{}".format(
uri,
"\n\t\t".join(
[
'field: "{}", pattern: "{}"'.format(n, p if p else "*")
for n, p in fields
]
),
)
for uri, fields in bindings
]

raise ValueError(
"Request {} does not match any URL path template in available HttpRule's {}".format(
request_kwargs, [opt["uri"] for opt in http_options]
"Invalid request."
"\nSome of the fields of the request message are either not initialized or "
"initialized with an invalid value."
"\nPlease make sure your request matches at least one accepted HTTP binding."
"\nTo match a binding the request message must have all the required fields "
"initialized with values matching their patterns as listed below:{}".format(
"\n".join(bindings_description)
)
)
3 changes: 2 additions & 1 deletiontests/unit/test_path_template.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -629,8 +629,9 @@ def test_transcode_with_additional_bindings(
)
def test_transcode_fails(http_options, message, request_kwargs):
http_options, _ = helper_test_transcode(http_options, range(4))
with pytest.raises(ValueError):
with pytest.raises(ValueError) as exc_info:
path_template.transcode(http_options, message, **request_kwargs)
assert str(exc_info.value).count("URI") == len(http_options)


def helper_test_transcode(http_options_list, expected_result_list):
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp