1+ <!DOCTYPE html>
2+
3+
4+ < html xmlns ="http://www.w3.org/1999/xhtml ">
5+ < head >
6+ < meta http-equiv ="Content-Type " content ="text/html; charset=utf-8 " />
7+
8+ < title > gcloud.connection — gcloud 0.4.1 documentation</ title >
9+
10+ < link rel ="stylesheet " href ="../../_static/css/main.css " type ="text/css " />
11+ < link rel ="stylesheet " href ="../../_static/pygments.css " type ="text/css " />
12+ < link rel ="stylesheet " href ="../../_static/css/normalize.css " type ="text/css " />
13+ < link rel ="stylesheet " href ="../../_static/css/github.min.css " type ="text/css " />
14+
15+ < script type ="text/javascript ">
16+ var DOCUMENTATION_OPTIONS = {
17+ URL_ROOT : '../../' ,
18+ VERSION : '0.4.1' ,
19+ COLLAPSE_INDEX : false ,
20+ FILE_SUFFIX : '.html' ,
21+ HAS_SOURCE : true
22+ } ;
23+ </ script >
24+ < script type ="text/javascript " src ="../../_static/js/vendor/modernizr-2.6.2.min.js "> </ script >
25+ < link rel ="shortcut icon " href ="../../_static/favicon.ico "/>
26+ < link rel ="top " title ="gcloud 0.4.1 documentation " href ="../../index.html " />
27+ < link rel ="up " title ="Module code " href ="../index.html " />
28+ </ head >
29+ < body >
30+ < header class ="page-header fixed " role ="banner ">
31+ < h1 class ="logo ">
32+ < a href ="index.html " title ="back to home ">
33+ < img src ="../../_static/images/logo.svg " alt ="Google Cloud Platform " />
34+ < span class ="gcloud "> gcloud</ span >
35+ </ a >
36+ </ h1 >
37+ < nav class ="main-nav ">
38+ < div class ="nav-current "> Python</ div >
39+ < ul class ="menu ">
40+ < li >
41+ < a href ="
42+ https://googlecloudplatform.github.io/gcloud-node " title ="Node.js docs page ">
43+ < img src ="../../_static/images/icon-lang-nodejs.svg " alt ="Node.js icon " class ="menu-icon " />
44+ Node.js
45+ </ a >
46+ </ li >
47+ < li >
48+ < a href ="# " title ="Python docs page ">
49+ < img src ="../../_static/images/icon-lang-python.svg " alt ="Python icon " class ="menu-icon " />
50+ Python
51+ </ a >
52+ </ li >
53+ </ ul >
54+ </ nav > <!-- end of .main-nav -->
55+ </ header > <!-- end of .page-header -->
56+
57+ < article class ="main lang-page " role ="main ">
58+
59+ < header class ="docs-header ">
60+ < h1 class ="page-title "> Python</ h1 >
61+
62+ < div class ="versions ">
63+ < span class ="v-current "> 0.4.1</ span >
64+ <!--
65+ <a href="versions.html" class="v-btn">
66+ <img src="_static/images/icon-arrow-bullet.svg" />
67+ See version History
68+ </a>-->
69+ </ div > <!-- end of .versions -->
70+ </ header >
71+
72+ < section class ="content ">
73+
74+ < h1 > Source code for gcloud.connection</ h1 > < div class ="highlight "> < pre >
75+ < span class ="c "> # Copyright 2014 Google Inc. All rights reserved.</ span >
76+ < span class ="c "> #</ span >
77+ < span class ="c "> # Licensed under the Apache License, Version 2.0 (the "License");</ span >
78+ < span class ="c "> # you may not use this file except in compliance with the License.</ span >
79+ < span class ="c "> # You may obtain a copy of the License at</ span >
80+ < span class ="c "> #</ span >
81+ < span class ="c "> # http://www.apache.org/licenses/LICENSE-2.0</ span >
82+ < span class ="c "> #</ span >
83+ < span class ="c "> # Unless required by applicable law or agreed to in writing, software</ span >
84+ < span class ="c "> # distributed under the License is distributed on an "AS IS" BASIS,</ span >
85+ < span class ="c "> # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.</ span >
86+ < span class ="c "> # See the License for the specific language governing permissions and</ span >
87+ < span class ="c "> # limitations under the License.</ span >
88+
89+ < span class ="sd "> """ Shared implementation of connections to API servers."""</ span >
90+
91+ < span class ="kn "> from</ span > < span class ="nn "> pkg_resources</ span > < span class ="kn "> import</ span > < span class ="n "> get_distribution</ span >
92+
93+ < span class ="kn "> import</ span > < span class ="nn "> httplib2</ span >
94+
95+
96+ < div class ="viewcode-block " id ="Connection "> < a class ="viewcode-back " href ="../../gcloud-api.html#gcloud.connection.Connection "> [docs]</ a > < span class ="k "> class</ span > < span class ="nc "> Connection</ span > < span class ="p "> (</ span > < span class ="nb "> object</ span > < span class ="p "> ):</ span >
97+ < span class ="sd "> """A generic connection to Google Cloud Platform.</ span >
98+
99+ < span class ="sd "> Subclasses should understand only the basic types in method arguments,</ span >
100+ < span class ="sd "> however they should be capable of returning advanced types.</ span >
101+
102+ < span class ="sd "> If no value is passed in for ``http``, a :class:`httplib2.Http` object</ span >
103+ < span class ="sd "> will be created and authorized with the ``credentials``. If not, the</ span >
104+ < span class ="sd "> ``credentials`` and ``http`` need not be related.</ span >
105+
106+ < span class ="sd "> Subclasses may seek to use the private key from ``credentials`` to sign</ span >
107+ < span class ="sd "> data.</ span >
108+
109+ < span class ="sd "> A custom (non-``httplib2``) HTTP object must have a ``request`` method</ span >
110+ < span class ="sd "> which accepts the following arguments:</ span >
111+
112+ < span class ="sd "> * ``uri``</ span >
113+ < span class ="sd "> * ``method``</ span >
114+ < span class ="sd "> * ``body``</ span >
115+ < span class ="sd "> * ``headers``</ span >
116+
117+ < span class ="sd "> In addition, ``redirections`` and ``connection_type`` may be used.</ span >
118+
119+ < span class ="sd "> Without the use of ``credentials.authorize(http)``, a custom ``http``</ span >
120+ < span class ="sd "> object will also need to be able to add a bearer token to API</ span >
121+ < span class ="sd "> requests and handle token refresh on 401 errors.</ span >
122+
123+ < span class ="sd "> :type credentials: :class:`oauth2client.client.OAuth2Credentials` or</ span >
124+ < span class ="sd "> :class:`NoneType`</ span >
125+ < span class ="sd "> :param credentials: The OAuth2 Credentials to use for this connection.</ span >
126+
127+ < span class ="sd "> :type http: :class:`httplib2.Http` or class that defines ``request()``.</ span >
128+ < span class ="sd "> :param http: An optional HTTP object to make requests.</ span >
129+ < span class ="sd "> """</ span >
130+
131+ < span class ="n "> API_BASE_URL</ span > < span class ="o "> =</ span > < span class ="s "> 'https://www.googleapis.com'</ span >
132+ < span class ="sd "> """The base of the API call URL."""</ span >
133+
134+ < span class ="n "> USER_AGENT</ span > < span class ="o "> =</ span > < span class ="s "> "gcloud-python/{0}"</ span > < span class ="o "> .</ span > < span class ="n "> format</ span > < span class ="p "> (</ span > < span class ="n "> get_distribution</ span > < span class ="p "> (</ span > < span class ="s "> 'gcloud'</ span > < span class ="p "> )</ span > < span class ="o "> .</ span > < span class ="n "> version</ span > < span class ="p "> )</ span >
135+ < span class ="sd "> """The user agent for gcloud-python requests."""</ span >
136+
137+ < span class ="k "> def</ span > < span class ="nf "> __init__</ span > < span class ="p "> (</ span > < span class ="bp "> self</ span > < span class ="p "> ,</ span > < span class ="n "> credentials</ span > < span class ="o "> =</ span > < span class ="bp "> None</ span > < span class ="p "> ,</ span > < span class ="n "> http</ span > < span class ="o "> =</ span > < span class ="bp "> None</ span > < span class ="p "> ):</ span >
138+ < span class ="bp "> self</ span > < span class ="o "> .</ span > < span class ="n "> _http</ span > < span class ="o "> =</ span > < span class ="n "> http</ span >
139+ < span class ="bp "> self</ span > < span class ="o "> .</ span > < span class ="n "> _credentials</ span > < span class ="o "> =</ span > < span class ="n "> credentials</ span >
140+
141+ < span class ="nd "> @property</ span >
142+ < div class ="viewcode-block " id ="Connection.credentials "> < a class ="viewcode-back " href ="../../gcloud-api.html#gcloud.connection.Connection.credentials "> [docs]</ a > < span class ="k "> def</ span > < span class ="nf "> credentials</ span > < span class ="p "> (</ span > < span class ="bp "> self</ span > < span class ="p "> ):</ span >
143+ < span class ="sd "> """Getter for current credentials.</ span >
144+
145+ < span class ="sd "> :rtype: :class:`oauth2client.client.OAuth2Credentials` or</ span >
146+ < span class ="sd "> :class:`NoneType`</ span >
147+ < span class ="sd "> :returns: The credentials object associated with this connection.</ span >
148+ < span class ="sd "> """</ span >
149+ < span class ="k "> return</ span > < span class ="bp "> self</ span > < span class ="o "> .</ span > < span class ="n "> _credentials</ span >
150+ </ div >
151+ < span class ="nd "> @property</ span >
152+ < div class ="viewcode-block " id ="Connection.http "> < a class ="viewcode-back " href ="../../gcloud-api.html#gcloud.connection.Connection.http "> [docs]</ a > < span class ="k "> def</ span > < span class ="nf "> http</ span > < span class ="p "> (</ span > < span class ="bp "> self</ span > < span class ="p "> ):</ span >
153+ < span class ="sd "> """A getter for the HTTP transport used in talking to the API.</ span >
154+
155+ < span class ="sd "> :rtype: :class:`httplib2.Http`</ span >
156+ < span class ="sd "> :returns: A Http object used to transport data.</ span >
157+ < span class ="sd "> """</ span >
158+ < span class ="k "> if</ span > < span class ="bp "> self</ span > < span class ="o "> .</ span > < span class ="n "> _http</ span > < span class ="ow "> is</ span > < span class ="bp "> None</ span > < span class ="p "> :</ span >
159+ < span class ="bp "> self</ span > < span class ="o "> .</ span > < span class ="n "> _http</ span > < span class ="o "> =</ span > < span class ="n "> httplib2</ span > < span class ="o "> .</ span > < span class ="n "> Http</ span > < span class ="p "> ()</ span >
160+ < span class ="k "> if</ span > < span class ="bp "> self</ span > < span class ="o "> .</ span > < span class ="n "> _credentials</ span > < span class ="p "> :</ span >
161+ < span class ="bp "> self</ span > < span class ="o "> .</ span > < span class ="n "> _http</ span > < span class ="o "> =</ span > < span class ="bp "> self</ span > < span class ="o "> .</ span > < span class ="n "> _credentials</ span > < span class ="o "> .</ span > < span class ="n "> authorize</ span > < span class ="p "> (</ span > < span class ="bp "> self</ span > < span class ="o "> .</ span > < span class ="n "> _http</ span > < span class ="p "> )</ span >
162+ < span class ="k "> return</ span > < span class ="bp "> self</ span > < span class ="o "> .</ span > < span class ="n "> _http</ span > </ div > </ div >
163+ </ pre > </ div >
164+
165+ </ section > <!-- end of .content -->
166+ < nav class ="side-nav ">
167+ < ul > < li > < a href ="../../index.html "> gcloud</ a > </ li > </ ul >
168+ < ul >
169+ < li class ="toctree-l1 "> < a class ="reference internal " href ="../../gcloud-api.html "> GCloud Package</ a > </ li >
170+ < li class ="toctree-l1 "> < a class ="reference internal " href ="../../datastore-api.html "> Datastore</ a > </ li >
171+ < li class ="toctree-l1 "> < a class ="reference internal " href ="../../datastore-entities.html "> Entities</ a > </ li >
172+ < li class ="toctree-l1 "> < a class ="reference internal " href ="../../datastore-keys.html "> Keys</ a > </ li >
173+ < li class ="toctree-l1 "> < a class ="reference internal " href ="../../datastore-queries.html "> Queries</ a > </ li >
174+ < li class ="toctree-l1 "> < a class ="reference internal " href ="../../datastore-transactions.html "> Transactions</ a > </ li >
175+ < li class ="toctree-l1 "> < a class ="reference internal " href ="../../datastore-batches.html "> Batches</ a > </ li >
176+ < li class ="toctree-l1 "> < a class ="reference internal " href ="../../storage-api.html "> Storage</ a > </ li >
177+ < li class ="toctree-l1 "> < a class ="reference internal " href ="../../storage-blobs.html "> Blobs / Objects</ a > </ li >
178+ < li class ="toctree-l1 "> < a class ="reference internal " href ="../../storage-buckets.html "> Buckets</ a > </ li >
179+ < li class ="toctree-l1 "> < a class ="reference internal " href ="../../storage-acl.html "> ACL</ a > </ li >
180+ </ ul >
181+
182+ < ul class ="external-links ">
183+ < li >
184+ < a href ="https://github.com/GoogleCloudPlatform/gcloud-python/ " title ="Python on Github ">
185+ < img src ="../../_static/images/icon-link-github.svg " alt ="Github icon " />
186+ Github
187+ </ a >
188+ </ li >
189+ < li >
190+ < a href ="https://github.com/GoogleCloudPlatform/gcloud-python/issues " title ="Python issues on Github ">
191+ < img src ="../../_static/images/icon-link-github.svg " alt ="Github icon " />
192+ Issues
193+ </ a >
194+ </ li >
195+ < li >
196+ < a href ="http://stackoverflow.com/questions/tagged/gcloud-python " title ="gcloud on StackOverflow ">
197+ < img src ="../../_static/images/icon-link-stackoverflow.svg " alt ="StackOverflow icon " />
198+ gcloud
199+ </ a >
200+ </ li >
201+ < li >
202+ < a href ="https://pypi.python.org/pypi/gcloud " title ="Python package manager ">
203+ < img src ="../../_static/images/icon-link-package-manager.svg " alt ="Package Manager icon " />
204+ Package Manager
205+ </ a >
206+ </ li >
207+ </ ul >
208+ </ nav > <!-- end of .side-nav -->
209+ </ article > <!-- end of .main -->
210+
211+ < script src ="../../_static/js/vendor/jquery-1.10.2.min.js "> </ script >
212+ < script src ="../../_static/js/plugins.js "> </ script >
213+ < script src ="../../_static/js/main.js "> </ script >
214+
215+ </ body >
216+ </ html >
0 commit comments