Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix generation for methods with abnormal page token conventions #330

Merged
merged 6 commits into from
Feb 10, 2017

Conversation

tcoffee-google
Copy link
Contributor

@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label Jan 13, 2017
@tcoffee-google
Copy link
Contributor Author

@tcoffee-google
Copy link
Contributor Author

Note this fix should be submitted in concert with googleapis/gapic-generator#880.

"""Creates any _next methods for attaching to a Resource.

The _next methods allow for easy iteration through list() responses.

Args:
methodName: string, name of the method to use.
pageToken: string, name of request page token field.
nextPageToken: string, name of response page token field.

This comment was marked as spam.

This comment was marked as spam.


if isPageTokenParameter:
# Replace pageToken value in URI
parsed = list(urlparse(request.uri))

This comment was marked as spam.

This comment was marked as spam.

# Add _next() methods
# Look for response bodies in schema that contain nextPageToken, and methods
# that take a pageToken parameter.
# Add _next() methods iff one of the names 'pageToken' or 'nextPageToken'

This comment was marked as spam.

This comment was marked as spam.

hasPageToken = 'pageToken' in methodDesc.get('parameters', {})
if hasNextPageToken and hasPageToken:
fixedMethodName, method = createNextMethod(methodName + '_next')
nextPageToken = pageTokenName(

This comment was marked as spam.

This comment was marked as spam.

self._set_dynamic_attr(fixedMethodName,
method.__get__(self, self.__class__))


pageTokenNames = ('pageToken', 'nextPageToken')

This comment was marked as spam.

This comment was marked as spam.


pageTokenNames = ('pageToken', 'nextPageToken')

def pageTokenName(fields):

This comment was marked as spam.

This comment was marked as spam.

method.__get__(self, self.__class__))


def findPageTokenName(fields):

This comment was marked as spam.

This comment was marked as spam.

return next((tokenName for tokenName in _PAGE_TOKEN_NAMES
if tokenName in fields), None)

def methodProperties(methodDesc, schema, name):

This comment was marked as spam.

This comment was marked as spam.

@@ -348,7 +348,7 @@ def no_content_response(self):
def makepatch(original, modified):
"""Create a patch object.

Some methods support PATCH, an efficient way to send updates to a resource.
Some methods support PATCH, an efficient way to send updates to a presource.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

@@ -161,13 +161,13 @@ def prettyPrintSchema(self, schema):
# Return with trailing comma and newline removed.
return self._prettyPrintSchema(schema, dent=1)[:-2]

def get(self, name):
def get(self, name, default=None):

This comment was marked as spam.

This comment was marked as spam.

@theacodes
Copy link
Contributor

@lukesneeringer @landrito I'd love to have one of you take a look.

Large changes like this on this ancient codebase make me uneasy.

raise TypeError('Missing required parameter "%s"' % name)
# temporary workaround for non-paging methods incorrectly requiring
# page token parameter (cf. drive.changes.watch vs. drive.changes.list)
if name not in _PAGE_TOKEN_NAMES or _findPageTokenName(

This comment was marked as spam.

This comment was marked as spam.

@@ -945,24 +957,26 @@ def methodNext(self, previous_request, previous_response):
# Retrieve nextPageToken from previous_response
# Use as pageToken in previous_request to create new request.

if 'nextPageToken' not in previous_response or not previous_response['nextPageToken']:
if (nextPageTokenName not in previous_response or
not previous_response[nextPageTokenName]):

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

First name that is either 'pageToken' or 'nextPageToken' if one exists,
otherwise None.
"""
return next((tokenName for tokenName in _PAGE_TOKEN_NAMES

This comment was marked as spam.

This comment was marked as spam.

@vchudnov-g
Copy link
Contributor

ping

@tcoffee-google
Copy link
Contributor Author

Any further comments on this?

@lukesneeringer
Copy link
Contributor

No further comments. Thanks!

@tcoffee-google
Copy link
Contributor Author

@jonparrott @lukesneeringer can you please approve changes to enable submission? Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes This human has signed the Contributor License Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants