Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 1.8k
Removing usage of the gRPC beta subpackage.#2149
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
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -30,9 +30,13 @@ | ||
| except ImportError: | ||
| app_identity = None | ||
| try: | ||
| from grpc.beta import implementations | ||
| from google.gax.grpc import exc_to_code as beta_exc_to_code | ||
| import grpc | ||
| from grpc._channel import _Rendezvous | ||
| except ImportError: # pragma: NO COVER | ||
| implementations = None | ||
| beta_exc_to_code = None | ||
| grpc = None | ||
| _Rendezvous = Exception | ||
| import six | ||
| from six.moves.http_client import HTTPConnection | ||
| from six.moves import configparser | ||
| @@ -572,10 +576,10 @@ def __call__(self, unused_context, callback): | ||
| callback(headers, None) | ||
| def make_stub(credentials, user_agent, stub_factory, host, port): | ||
| def make_stub(credentials, user_agent, stub_class, host, port): | ||
| """Makes a stub for an RPC service. | ||
| Uses / depends on the beta implementation of gRPC. | ||
| Uses / depends on gRPC. | ||
| :type credentials: :class:`oauth2client.client.OAuth2Credentials` | ||
| :param credentials: The OAuth2 Credentials to use for creating | ||
| @@ -584,29 +588,44 @@ def make_stub(credentials, user_agent, stub_factory, host, port): | ||
| :type user_agent: str | ||
| :param user_agent: (Optional) The user agent to be used with API requests. | ||
| :type stub_factory: callable | ||
| :param stub_factory: A factory which will create a gRPC stub for | ||
| a given service. | ||
| :type stub_class: type | ||
| :param stub_class: A gRPC stub type for a given service. | ||
| :type host: str | ||
| :param host: The host for the service. | ||
| :type port: int | ||
| :param port: The port for the service. | ||
| :rtype: :class:`grpc.beta._stub._AutoIntermediary` | ||
| :rtype: object, instance of ``stub_class`` | ||
| :returns: The stub object used to make gRPC requests to a given API. | ||
| """ | ||
| # Leaving the first argument to ssl_channel_credentials() as None | ||
| # loads root certificates from `grpc/_adapter/credentials/roots.pem`. | ||
| transport_creds = implementations.ssl_channel_credentials(None, None, None) | ||
| transport_creds = grpc.ssl_channel_credentials() | ||
| custom_metadata_plugin = MetadataPlugin(credentials, user_agent) | ||
| auth_creds = implementations.metadata_call_credentials( | ||
| auth_creds = grpc.metadata_call_credentials( | ||
| custom_metadata_plugin, name='google_creds') | ||
| channel_creds = implementations.composite_channel_credentials( | ||
| channel_creds = grpc.composite_channel_credentials( | ||
| transport_creds, auth_creds) | ||
| channel = implementations.secure_channel(host, port, channel_creds) | ||
| return stub_factory(channel) | ||
| target = '%s:%d' % (host, port) | ||
| channel = grpc.secure_channel(target, channel_creds) | ||
| return stub_class(channel) | ||
| def exc_to_code(exc): | ||
This comment was marked as spam.Sorry, something went wrong. Uh oh!There was an error while loading. Please reload this page.
This comment was marked as spam.Sorry, something went wrong. Uh oh!There was an error while loading. Please reload this page.
This comment was marked as spam.Sorry, something went wrong. Uh oh!There was an error while loading. Please reload this page.
This comment was marked as spam.Sorry, something went wrong. Uh oh!There was an error while loading. Please reload this page. | ||
| """Retrieves the status code from a gRPC exception. | ||
| :type exc: :class:`Exception` | ||
| :param exc: An exception from gRPC beta or stable. | ||
| :rtype: :class:`grpc.StatusCode` | ||
| :returns: The status code attached to the exception. | ||
| """ | ||
| if isinstance(exc, _Rendezvous): | ||
| return exc.code() | ||
| else: | ||
| return beta_exc_to_code(exc) | ||
| try: | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -21,16 +21,6 @@ class _FakeStub(object): | ||
| def __init__(self, *results): | ||
| self.results = results | ||
| self.method_calls = [] | ||
| self._entered = 0 | ||
| self._exited = [] | ||
| def __enter__(self): | ||
| self._entered += 1 | ||
| return self | ||
| def __exit__(self, exc_type, exc_val, exc_tb): | ||
| self._exited.append((exc_type, exc_val, exc_tb)) | ||
| return True | ||
| def __getattr__(self, name): | ||
| # We need not worry about attributes set in constructor | ||
| @@ -41,17 +31,16 @@ def __getattr__(self, name): | ||
| class _MethodMock(object): | ||
| """Mock for API method attached to a gRPC stub. | ||
| In the beta implementation, these are of type. | ||
| :class:`grpc.framework.crust.implementations._UnaryUnaryMultiCallable` | ||
| These are of type :class:`grpc._channel._UnaryUnaryMultiCallable`. | ||
This comment was marked as spam.Sorry, something went wrong. Uh oh!There was an error while loading. Please reload this page.
This comment was marked as spam.Sorry, something went wrong. Uh oh!There was an error while loading. Please reload this page. | ||
| """ | ||
| def __init__(self, name, factory): | ||
| def __init__(self, name, stub): | ||
| self._name = name | ||
| self._factory = factory | ||
| self._stub = stub | ||
| def __call__(self, *args, **kwargs): | ||
| """Sync method meant to mock a gRPC stub request.""" | ||
| self._factory.method_calls.append((self._name, args, kwargs)) | ||
| curr_result, self._factory.results = (self._factory.results[0], | ||
| self._factory.results[1:]) | ||
| self._stub.method_calls.append((self._name, args, kwargs)) | ||
| curr_result, self._stub.results = (self._stub.results[0], | ||
| self._stub.results[1:]) | ||
| return curr_result | ||
Uh oh!
There was an error while loading. Please reload this page.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.