Fix and enable no-self-use lint

pull/9866/head
Nathaniel Manista 8 years ago
parent 90798ab199
commit 017365d072
  1. 3
      .pylintrc
  2. 24
      src/python/grpcio/grpc/_auth.py

@ -29,6 +29,5 @@
#TODO: Enable too-many-return-statements #TODO: Enable too-many-return-statements
#TODO: Enable too-many-nested-blocks #TODO: Enable too-many-nested-blocks
#TODO: Enable super-init-not-called #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

@ -39,6 +39,19 @@ def _sign_request(callback, token, error):
callback(metadata, 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): class GoogleCallCredentials(grpc.AuthMetadataPlugin):
"""Metadata wrapper for GoogleCredentials from the oauth2client library.""" """Metadata wrapper for GoogleCredentials from the oauth2client library."""
@ -59,16 +72,7 @@ class GoogleCallCredentials(grpc.AuthMetadataPlugin):
additional_claims={'aud': context.service_url}) additional_claims={'aud': context.service_url})
else: else:
future = self._pool.submit(self._credentials.get_access_token) future = self._pool.submit(self._credentials.get_access_token)
future.add_done_callback( future.add_done_callback(_create_get_token_callback(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)
def __del__(self): def __del__(self):
self._pool.shutdown(wait=False) self._pool.shutdown(wait=False)

Loading…
Cancel
Save