2020from six .moves .urllib .parse import urlencode
2121
2222import google .auth .credentials
23- import google_auth_httplib2
24- import httplib2
2523
2624from google .cloud .exceptions import make_exception
2725
3735class Connection (object ):
3836 """A generic connection to Google Cloud Platform.
3937
40- Subclasses should understand only the basic types in method arguments,
41- however they should be capable of returning advanced types.
42-
43- If no value is passed in for ``http``, a :class:`httplib2.Http` object
44- will be created and authorized with the ``credentials``. If not, the
45- ``credentials`` and ``http`` need not be related.
46-
47- Subclasses may seek to use the private key from ``credentials`` to sign
48- data.
49-
50- A custom (non-``httplib2``) HTTP object must have a ``request`` method
51- which accepts the following arguments:
52-
53- * ``uri``
54- * ``method``
55- * ``body``
56- * ``headers``
57-
58- In addition, ``redirections`` and ``connection_type`` may be used.
59-
60- Without the use of ``credentials.authorize(http)``, a custom ``http``
61- object will also need to be able to add a bearer token to API
62- requests and handle token refresh on 401 errors.
63-
64- :type credentials: :class:`google.auth.credentials.Credentials` or
65- :class:`NoneType`
66- :param credentials: The credentials to use for this connection.
67-
68- :type http: :class:`httplib2.Http` or class that defines ``request()``.
69- :param http: An optional HTTP object to make requests.
38+ :type client: :class:`~google.cloud.client.Client`
39+ :param client: The client that owns the credentials.
7040 """
7141
7242 USER_AGENT = DEFAULT_USER_AGENT
7343
74- SCOPE = None
75- """The scopes required for authenticating with a service.
76-
77- Needs to be set by subclasses.
78- """
79-
80- def __init__ (self , credentials = None , http = None ):
81- self ._http = http
82- self ._credentials = google .auth .credentials .with_scopes_if_required (
83- credentials , self .SCOPE )
44+ def __init__ (self , client ):
45+ self ._client = client
8446
8547 @property
8648 def credentials (self ):
@@ -90,7 +52,7 @@ def credentials(self):
9052 :class:`NoneType`
9153 :returns: The credentials object associated with this connection.
9254 """
93- return self ._credentials
55+ return self ._client . _credentials
9456
9557 @property
9658 def http (self ):
@@ -99,13 +61,7 @@ def http(self):
9961 :rtype: :class:`httplib2.Http`
10062 :returns: A Http object used to transport data.
10163 """
102- if self ._http is None :
103- if self ._credentials :
104- self ._http = google_auth_httplib2 .AuthorizedHttp (
105- self ._credentials )
106- else :
107- self ._http = httplib2 .Http ()
108- return self ._http
64+ return self ._client ._http
10965
11066
11167class JSONConnection (Connection ):
0 commit comments