Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
5 changes: 4 additions & 1 deletion gapic/samplegen/samplegen.py
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ def _normal_request_setup(self, base_param_to_attrs, val, request, field):
)
del request["field"]

if isinstance(request["value"], str):
if isinstance(request["value"], str) or isinstance(request["value"], list):
# Passing value through json is a safe and simple way of
# making sure strings are properly wrapped and quotes escaped.
# This statement both wraps enums in quotes and escapes quotes
Expand All @@ -426,6 +426,9 @@ def _normal_request_setup(self, base_param_to_attrs, val, request, field):
# This is preferable to adding the necessary import statement
# and requires less munging of the assigned value
request["value"] = json.dumps(request["value"])
elif isinstance(request["value"], bytes):
# Use double quotes for bytes literals for consistency.
request["value"] = f'b"{request["value"].decode("utf-8")}"'

# Mypy isn't smart enough to handle dictionary unpacking,
# so disable it for the AttributeRequestSetup ctor call.
Expand Down
6 changes: 5 additions & 1 deletion gapic/templates/examples/feature_fragments.j2
Original file line number Diff line number Diff line change
Expand Up @@ -174,11 +174,15 @@ client = {{ module_name }}.{{ client_name }}()
{% endif %}
{% endfor %}
{% if not full_request.flattenable %}
{% if full_request.request_list|length > 0 %}
request = {{ module_name }}.{{ request_type.ident.name }}(
{% for parameter in full_request.request_list %}
{{ parameter.base }}={{ parameter.base if parameter.body else parameter.single.value }},
{% endfor %}
)
{% else %}
request = {{ module_name }}.{{ request_type.ident.name }}()
{% endif %}
{# Note: This template assumes only one request needs to be sent. When samples accept
configs the client streaming logic should be modified to allow 2+ request objects. #}
{# If client streaming, wrap the single request in a generator that produces 'requests' #}
Expand Down Expand Up @@ -256,8 +260,8 @@ operation
# Make the request
{% if calling_form in [calling_form_enum.Request, calling_form_enum.RequestStreamingClient] %}
{% if response_statements %}response = {% endif %}{{ method_invocation_text|trim }}

{% if response_statements %}

# Handle the response
{% for statement in response_statements %}
{{ dispatch_statement(statement)|trim }}
Expand Down
1 change: 1 addition & 0 deletions gapic/templates/examples/sample.py.j2
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
{{ frags.render_calling_form(method_call, calling_form, calling_form_enum, sample.transport, sample.response)|indent -}}
{% endwith %}


# [END {{ sample.id }}]
{# TODO: Enable main block (or decide to remove main block from python sample) #}
{# {{ frags.render_main_block(sample, sample.request) }} #}
Expand Down
3 changes: 1 addition & 2 deletions gapic/templates/noxfile.py.j2
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,9 @@ LINT_PATHS = ["docs", "{{ api.naming.versioned_module_name }}", "tests", "noxfil
# and less concerned about the line length.
LINT_LINE_LENGTH = 150

# Add samples to the list of directories to format if the directory exists.
# Add samples to the list of directories to lint if the directory exists.
if os.path.isdir("samples"):
LINT_PATHS.append("samples")
FORMAT_PATHS.append("samples")

ALL_PYTHON = [
"3.7",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2439,8 +2439,7 @@ async def sample_update_saved_query():
client = asset_v1.AssetServiceAsyncClient()

# Initialize request argument(s)
request = asset_v1.UpdateSavedQueryRequest(
)
request = asset_v1.UpdateSavedQueryRequest()

# Make the request
response = await client.update_saved_query(request=request)
Expand Down Expand Up @@ -2660,7 +2659,7 @@ async def sample_batch_get_effective_iam_policies():
# Initialize request argument(s)
request = asset_v1.BatchGetEffectiveIamPoliciesRequest(
scope="scope_value",
names=['names_value1', 'names_value2'],
names=["names_value1", "names_value2"],
)

# Make the request
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2939,8 +2939,7 @@ def sample_update_saved_query():
client = asset_v1.AssetServiceClient()

# Initialize request argument(s)
request = asset_v1.UpdateSavedQueryRequest(
)
request = asset_v1.UpdateSavedQueryRequest()

# Make the request
response = client.update_saved_query(request=request)
Expand Down Expand Up @@ -3158,7 +3157,7 @@ def sample_batch_get_effective_iam_policies():
# Initialize request argument(s)
request = asset_v1.BatchGetEffectiveIamPoliciesRequest(
scope="scope_value",
names=['names_value1', 'names_value2'],
names=["names_value1", "names_value2"],
)

# Make the request
Expand Down
3 changes: 1 addition & 2 deletions tests/integration/goldens/asset/noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,9 @@
# and less concerned about the line length.
LINT_LINE_LENGTH = 150

# Add samples to the list of directories to format if the directory exists.
# Add samples to the list of directories to lint if the directory exists.
if os.path.isdir("samples"):
LINT_PATHS.append("samples")
FORMAT_PATHS.append("samples")

ALL_PYTHON = [
"3.7",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,5 @@ async def sample_analyze_iam_policy():
# Handle the response
print(response)


# [END cloudasset_v1_generated_AssetService_AnalyzeIamPolicy_async]
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,5 @@ async def sample_analyze_iam_policy_longrunning():
# Handle the response
print(response)


# [END cloudasset_v1_generated_AssetService_AnalyzeIamPolicyLongrunning_async]
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,5 @@ def sample_analyze_iam_policy_longrunning():
# Handle the response
print(response)


# [END cloudasset_v1_generated_AssetService_AnalyzeIamPolicyLongrunning_sync]
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,5 @@ def sample_analyze_iam_policy():
# Handle the response
print(response)


# [END cloudasset_v1_generated_AssetService_AnalyzeIamPolicy_sync]
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,5 @@ async def sample_analyze_move():
# Handle the response
print(response)


# [END cloudasset_v1_generated_AssetService_AnalyzeMove_async]
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,5 @@ def sample_analyze_move():
# Handle the response
print(response)


# [END cloudasset_v1_generated_AssetService_AnalyzeMove_sync]
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,5 @@ async def sample_analyze_org_policies():
async for response in page_result:
print(response)


# [END cloudasset_v1_generated_AssetService_AnalyzeOrgPolicies_async]
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,5 @@ def sample_analyze_org_policies():
for response in page_result:
print(response)


# [END cloudasset_v1_generated_AssetService_AnalyzeOrgPolicies_sync]
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,5 @@ async def sample_analyze_org_policy_governed_assets():
async for response in page_result:
print(response)


# [END cloudasset_v1_generated_AssetService_AnalyzeOrgPolicyGovernedAssets_async]
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,5 @@ def sample_analyze_org_policy_governed_assets():
for response in page_result:
print(response)


# [END cloudasset_v1_generated_AssetService_AnalyzeOrgPolicyGovernedAssets_sync]
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,5 @@ async def sample_analyze_org_policy_governed_containers():
async for response in page_result:
print(response)


# [END cloudasset_v1_generated_AssetService_AnalyzeOrgPolicyGovernedContainers_async]
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,5 @@ def sample_analyze_org_policy_governed_containers():
for response in page_result:
print(response)


# [END cloudasset_v1_generated_AssetService_AnalyzeOrgPolicyGovernedContainers_sync]
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,5 @@ async def sample_batch_get_assets_history():
# Handle the response
print(response)


# [END cloudasset_v1_generated_AssetService_BatchGetAssetsHistory_async]
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,5 @@ def sample_batch_get_assets_history():
# Handle the response
print(response)


# [END cloudasset_v1_generated_AssetService_BatchGetAssetsHistory_sync]
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ async def sample_batch_get_effective_iam_policies():
# Initialize request argument(s)
request = asset_v1.BatchGetEffectiveIamPoliciesRequest(
scope="scope_value",
names=['names_value1', 'names_value2'],
names=["names_value1", "names_value2"],
)

# Make the request
Expand All @@ -50,4 +50,5 @@ async def sample_batch_get_effective_iam_policies():
# Handle the response
print(response)


# [END cloudasset_v1_generated_AssetService_BatchGetEffectiveIamPolicies_async]
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def sample_batch_get_effective_iam_policies():
# Initialize request argument(s)
request = asset_v1.BatchGetEffectiveIamPoliciesRequest(
scope="scope_value",
names=['names_value1', 'names_value2'],
names=["names_value1", "names_value2"],
)

# Make the request
Expand All @@ -50,4 +50,5 @@ def sample_batch_get_effective_iam_policies():
# Handle the response
print(response)


# [END cloudasset_v1_generated_AssetService_BatchGetEffectiveIamPolicies_sync]
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,5 @@ async def sample_create_feed():
# Handle the response
print(response)


# [END cloudasset_v1_generated_AssetService_CreateFeed_async]
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,5 @@ def sample_create_feed():
# Handle the response
print(response)


# [END cloudasset_v1_generated_AssetService_CreateFeed_sync]
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,5 @@ async def sample_create_saved_query():
# Handle the response
print(response)


# [END cloudasset_v1_generated_AssetService_CreateSavedQuery_async]
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,5 @@ def sample_create_saved_query():
# Handle the response
print(response)


# [END cloudasset_v1_generated_AssetService_CreateSavedQuery_sync]
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,5 @@ async def sample_export_assets():
# Handle the response
print(response)


# [END cloudasset_v1_generated_AssetService_ExportAssets_async]
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,5 @@ def sample_export_assets():
# Handle the response
print(response)


# [END cloudasset_v1_generated_AssetService_ExportAssets_sync]
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,5 @@ async def sample_get_feed():
# Handle the response
print(response)


# [END cloudasset_v1_generated_AssetService_GetFeed_async]
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,5 @@ def sample_get_feed():
# Handle the response
print(response)


# [END cloudasset_v1_generated_AssetService_GetFeed_sync]
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,5 @@ async def sample_get_saved_query():
# Handle the response
print(response)


# [END cloudasset_v1_generated_AssetService_GetSavedQuery_async]
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,5 @@ def sample_get_saved_query():
# Handle the response
print(response)


# [END cloudasset_v1_generated_AssetService_GetSavedQuery_sync]
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,5 @@ async def sample_list_assets():
async for response in page_result:
print(response)


# [END cloudasset_v1_generated_AssetService_ListAssets_async]
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,5 @@ def sample_list_assets():
for response in page_result:
print(response)


# [END cloudasset_v1_generated_AssetService_ListAssets_sync]
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,5 @@ async def sample_list_feeds():
# Handle the response
print(response)


# [END cloudasset_v1_generated_AssetService_ListFeeds_async]
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,5 @@ def sample_list_feeds():
# Handle the response
print(response)


# [END cloudasset_v1_generated_AssetService_ListFeeds_sync]
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,5 @@ async def sample_list_saved_queries():
async for response in page_result:
print(response)


# [END cloudasset_v1_generated_AssetService_ListSavedQueries_async]
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,5 @@ def sample_list_saved_queries():
for response in page_result:
print(response)


# [END cloudasset_v1_generated_AssetService_ListSavedQueries_sync]
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,5 @@ async def sample_query_assets():
# Handle the response
print(response)


# [END cloudasset_v1_generated_AssetService_QueryAssets_async]
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,5 @@ def sample_query_assets():
# Handle the response
print(response)


# [END cloudasset_v1_generated_AssetService_QueryAssets_sync]
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,5 @@ async def sample_search_all_iam_policies():
async for response in page_result:
print(response)


# [END cloudasset_v1_generated_AssetService_SearchAllIamPolicies_async]
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,5 @@ def sample_search_all_iam_policies():
for response in page_result:
print(response)


# [END cloudasset_v1_generated_AssetService_SearchAllIamPolicies_sync]
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,5 @@ async def sample_search_all_resources():
async for response in page_result:
print(response)


# [END cloudasset_v1_generated_AssetService_SearchAllResources_async]
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,5 @@ def sample_search_all_resources():
for response in page_result:
print(response)


# [END cloudasset_v1_generated_AssetService_SearchAllResources_sync]
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,5 @@ async def sample_update_feed():
# Handle the response
print(response)


# [END cloudasset_v1_generated_AssetService_UpdateFeed_async]
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,5 @@ def sample_update_feed():
# Handle the response
print(response)


# [END cloudasset_v1_generated_AssetService_UpdateFeed_sync]
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ async def sample_update_saved_query():
client = asset_v1.AssetServiceAsyncClient()

# Initialize request argument(s)
request = asset_v1.UpdateSavedQueryRequest(
)
request = asset_v1.UpdateSavedQueryRequest()

# Make the request
response = await client.update_saved_query(request=request)

# Handle the response
print(response)


# [END cloudasset_v1_generated_AssetService_UpdateSavedQuery_async]
Loading