Skip to content

Commit e053eb8

Browse files
author
Jon Wayne Parrott
authored
Remove gapic_v1.method.wrap_with_paging (#4257)
1 parent bba7f68 commit e053eb8

File tree

3 files changed

+17
-82
lines changed

3 files changed

+17
-82
lines changed

google/api_core/gapic_v1/method.py

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,8 @@
1818
pagination, and long-running operations to gRPC methods.
1919
"""
2020

21-
import functools
22-
23-
import six
24-
2521
from google.api_core import general_helpers
2622
from google.api_core import grpc_helpers
27-
from google.api_core import page_iterator
2823
from google.api_core import timeout
2924
from google.api_core.gapic_v1 import client_info
3025

@@ -232,38 +227,3 @@ def get_topic(name, timeout=None):
232227
_GapicCallable(
233228
func, default_retry, default_timeout,
234229
user_agent_metadata=user_agent_metadata))
235-
236-
237-
def wrap_with_paging(
238-
func, items_field, request_token_field, response_token_field):
239-
"""Wrap an RPC method to return a page iterator.
240-
241-
Args:
242-
func (Callable): The RPC method. This should already have been
243-
wrapped with common functionality using :func:`wrap_method`.
244-
request (protobuf.Message): The request message.
245-
items_field (str): The field in the response message that has the
246-
items for the page.
247-
request_token_field (str): The field in the request message used to
248-
specify the page token.
249-
response_token_field (str): The field in the response message that has
250-
the token for the next page.
251-
252-
Returns:
253-
Callable: Returns a callable that when invoked will call the RPC
254-
method and return a
255-
:class:`google.api_core.page_iterator.Iterator`.
256-
"""
257-
@six.wraps(func)
258-
def paged_method(request, **kwargs):
259-
"""Wrapper that invokes a method and returns a page iterator."""
260-
iterator = page_iterator.GRPCIterator(
261-
client=None,
262-
method=functools.partial(func, **kwargs),
263-
request=request,
264-
items_field=items_field,
265-
request_token_field=request_token_field,
266-
response_token_field=response_token_field)
267-
return iterator
268-
269-
return paged_method

google/api_core/operations_v1/operations_client.py

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,10 @@
3535
/operations.proto
3636
"""
3737

38+
import functools
39+
3840
from google.api_core import gapic_v1
41+
from google.api_core import page_iterator
3942
from google.api_core.operations_v1 import operations_client_config
4043
from google.longrunning import operations_pb2
4144

@@ -72,12 +75,6 @@ def __init__(self, channel, client_config=operations_client_config.config):
7275
default_retry=method_configs['ListOperations'].retry,
7376
default_timeout=method_configs['ListOperations'].timeout)
7477

75-
self._list_operations = gapic_v1.method.wrap_with_paging(
76-
self._list_operations,
77-
'operations',
78-
'page_token',
79-
'next_page_token')
80-
8178
self._cancel_operation = gapic_v1.method.wrap_method(
8279
self.operations_stub.CancelOperation,
8380
default_retry=method_configs['CancelOperation'].retry,
@@ -182,7 +179,20 @@ def list_operations(
182179
# Create the request object.
183180
request = operations_pb2.ListOperationsRequest(
184181
name=name, filter=filter_)
185-
return self._list_operations(request, retry=retry, timeout=timeout)
182+
183+
# Create the method used to fetch pages
184+
method = functools.partial(
185+
self._list_operations, retry=retry, timeout=timeout)
186+
187+
iterator = page_iterator.GRPCIterator(
188+
client=None,
189+
method=method,
190+
request=request,
191+
items_field='operations',
192+
request_token_field='page_token',
193+
response_token_field='next_page_token')
194+
195+
return iterator
186196

187197
def cancel_operation(
188198
self, name,

tests/unit/gapic/test_method.py

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -179,38 +179,3 @@ def test_wrap_method_with_overriding_timeout_as_a_number():
179179

180180
assert result == 42
181181
method.assert_called_once_with(timeout=22, metadata=mock.ANY)
182-
183-
184-
def test_wrap_with_paging():
185-
page_one = mock.Mock(
186-
spec=['items', 'page_token', 'next_page_token'],
187-
items=[1, 2],
188-
next_page_token='icanhasnextpls')
189-
page_two = mock.Mock(
190-
spec=['items', 'page_token', 'next_page_token'],
191-
items=[3, 4],
192-
next_page_token=None)
193-
method = mock.Mock(
194-
spec=['__call__', '__name__'], side_effect=(page_one, page_two))
195-
method.__name__ = 'mockmethod'
196-
197-
wrapped_method = google.api_core.gapic_v1.method.wrap_with_paging(
198-
method, 'items', 'page_token', 'next_page_token')
199-
200-
request = mock.Mock(spec=['page_token'], page_token=None)
201-
result = wrapped_method(request, extra='param')
202-
203-
# Should return an iterator and should not have actually called the
204-
# method yet.
205-
assert isinstance(result, google.api_core.page_iterator.Iterator)
206-
method.assert_not_called()
207-
assert request.page_token is None
208-
209-
# Draining the iterator should call the method until no more pages are
210-
# returned.
211-
results = list(result)
212-
213-
assert results == [1, 2, 3, 4]
214-
assert method.call_count == 2
215-
method.assert_called_with(request, extra='param')
216-
assert request.page_token == 'icanhasnextpls'

0 commit comments

Comments
 (0)