Skip to content

Commit 21af37b

Browse files
authored
feat: allow to use 'six.moves.collections_abc.Mapping' in 'client_options.from_dict()' (googleapis#943)
1 parent cc83ec2 commit 21af37b

File tree

2 files changed

+22
-9
lines changed

2 files changed

+22
-9
lines changed

googleapiclient/discovery.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -213,10 +213,10 @@ def build(
213213
cache_discovery: Boolean, whether or not to cache the discovery doc.
214214
cache: googleapiclient.discovery_cache.base.CacheBase, an optional
215215
cache object for the discovery documents.
216-
client_options: Dictionary or google.api_core.client_options, Client options to set user
217-
options on the client. API endpoint should be set through client_options.
218-
client_cert_source is not supported, client cert should be provided using
219-
client_encrypted_cert_source instead.
216+
client_options: Mapping object or google.api_core.client_options, client
217+
options to set user options on the client. The API endpoint should be set
218+
through client_options. client_cert_source is not supported, client cert
219+
should be provided using client_encrypted_cert_source instead.
220220
adc_cert_path: str, client certificate file path to save the application
221221
default client certificate for mTLS. This field is required if you want to
222222
use the default client certificate.
@@ -359,10 +359,10 @@ def build_from_document(
359359
credentials: oauth2client.Credentials or
360360
google.auth.credentials.Credentials, credentials to be used for
361361
authentication.
362-
client_options: Dictionary or google.api_core.client_options, Client options to set user
363-
options on the client. API endpoint should be set through client_options.
364-
client_cert_source is not supported, client cert should be provided using
365-
client_encrypted_cert_source instead.
362+
client_options: Mapping object or google.api_core.client_options, client
363+
options to set user options on the client. The API endpoint should be set
364+
through client_options. client_cert_source is not supported, client cert
365+
should be provided using client_encrypted_cert_source instead.
366366
adc_cert_path: str, client certificate file path to save the application
367367
default client certificate for mTLS. This field is required if you want to
368368
use the default client certificate.
@@ -398,7 +398,7 @@ def build_from_document(
398398
# If an API Endpoint is provided on client options, use that as the base URL
399399
base = urljoin(service["rootUrl"], service["servicePath"])
400400
if client_options:
401-
if type(client_options) == dict:
401+
if isinstance(client_options, six.moves.collections_abc.Mapping):
402402
client_options = google.api_core.client_options.from_dict(client_options)
403403
if client_options.api_endpoint:
404404
base = client_options.api_endpoint

tests/test_discovery.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import re
3939
import sys
4040
import unittest2 as unittest
41+
from collections import defaultdict
4142

4243
from parameterized import parameterized
4344
import mock
@@ -534,6 +535,18 @@ def test_api_endpoint_override_from_client_options(self):
534535

535536
self.assertEqual(plus._baseUrl, api_endpoint)
536537

538+
def test_api_endpoint_override_from_client_options_mapping_object(self):
539+
540+
discovery = open(datafile("plus.json")).read()
541+
api_endpoint = "https://foo.googleapis.com/"
542+
mapping_object = defaultdict(str)
543+
mapping_object['api_endpoint'] = api_endpoint
544+
plus = build_from_document(
545+
discovery, client_options=mapping_object
546+
)
547+
548+
self.assertEqual(plus._baseUrl, api_endpoint)
549+
537550
def test_api_endpoint_override_from_client_options_dict(self):
538551
discovery = open(datafile("plus.json")).read()
539552
api_endpoint = "https://foo.googleapis.com/"

0 commit comments

Comments
 (0)