Skip to content

Commit

Permalink
Fix and enable no-self-use lint
Browse files Browse the repository at this point in the history
  • Loading branch information
nathanielmanistaatgoogle committed Mar 2, 2017
1 parent 90798ab commit 017365d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
3 changes: 1 addition & 2 deletions .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,5 @@
#TODO: Enable too-many-return-statements
#TODO: Enable too-many-nested-blocks
#TODO: Enable super-init-not-called
#TODO: Enable no-self-use

disable=missing-docstring,too-few-public-methods,too-many-arguments,no-init,duplicate-code,invalid-name,suppressed-message,locally-disabled,protected-access,no-name-in-module,unused-argument,fixme,wrong-import-order,no-value-for-parameter,cyclic-import,unused-variable,redefined-outer-name,unused-import,too-many-instance-attributes,broad-except,too-many-locals,too-many-lines,redefined-variable-type,next-method-called,import-error,useless-else-on-loop,too-many-return-statements,too-many-nested-blocks,super-init-not-called,no-self-use
disable=missing-docstring,too-few-public-methods,too-many-arguments,no-init,duplicate-code,invalid-name,suppressed-message,locally-disabled,protected-access,no-name-in-module,unused-argument,fixme,wrong-import-order,no-value-for-parameter,cyclic-import,unused-variable,redefined-outer-name,unused-import,too-many-instance-attributes,broad-except,too-many-locals,too-many-lines,redefined-variable-type,next-method-called,import-error,useless-else-on-loop,too-many-return-statements,too-many-nested-blocks,super-init-not-called
24 changes: 14 additions & 10 deletions src/python/grpcio/grpc/_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,19 @@ def _sign_request(callback, token, error):
callback(metadata, error)


def _create_get_token_callback(callback):

def get_token_callback(future):
try:
access_token = future.result().access_token
except Exception as exception:
_sign_request(callback, None, exception)
else:
_sign_request(callback, access_token, None)

return get_token_callback


class GoogleCallCredentials(grpc.AuthMetadataPlugin):
"""Metadata wrapper for GoogleCredentials from the oauth2client library."""

Expand All @@ -59,16 +72,7 @@ def __call__(self, context, callback):
additional_claims={'aud': context.service_url})
else:
future = self._pool.submit(self._credentials.get_access_token)
future.add_done_callback(
lambda x: self._get_token_callback(callback, x))

def _get_token_callback(self, callback, future):
try:
access_token = future.result().access_token
except Exception as e:
_sign_request(callback, None, e)
else:
_sign_request(callback, access_token, None)
future.add_done_callback(_create_get_token_callback(callback))

def __del__(self):
self._pool.shutdown(wait=False)
Expand Down

0 comments on commit 017365d

Please sign in to comment.