Skip to content

Commit 11d0335

Browse files
committed
doc: Code examples in README are now python 3 compatible #66
Signed-off-by: Romain Beuque <romain.beuque@corp.ovh.com>
1 parent 8eb617a commit 11d0335

File tree

5 files changed

+49
-34
lines changed

5 files changed

+49
-34
lines changed

README.rst

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ credential creation and requests signing.
4040
)
4141
4242
# Print nice welcome message
43-
print "Welcome", client.get('/me')['firstname']
43+
print("Welcome", client.get('/me')['firstname'])
4444
4545
Installation
4646
============
@@ -133,6 +133,11 @@ customer's information:
133133
134134
# -*- encoding: utf-8 -*-
135135
136+
try:
137+
input = raw_input
138+
except NameError:
139+
pass
140+
136141
import ovh
137142
138143
# create a client using configuration
@@ -145,12 +150,12 @@ customer's information:
145150
# Request token
146151
validation = ck.request()
147152
148-
print "Please visit %s to authenticate" % validation['validationUrl']
149-
raw_input("and press Enter to continue...")
153+
print("Please visit %s to authenticate" % validation['validationUrl'])
154+
input("and press Enter to continue...")
150155
151156
# Print nice welcome message
152-
print "Welcome", client.get('/me')['firstname']
153-
print "Btw, your 'consumerKey' is '%s'" % validation['consumerKey']
157+
print("Welcome", client.get('/me')['firstname'])
158+
print("Btw, your 'consumerKey' is '%s'" % validation['consumerKey'])
154159
155160
156161
Returned ``consumerKey`` should then be kept to avoid re-authenticating your
@@ -195,7 +200,7 @@ is only supported with reserved keywords.
195200
to=DESTINATION,
196201
localCopy=False
197202
)
198-
print "Installed new mail redirection from %s to %s" % (SOURCE, DESTINATION)
203+
print("Installed new mail redirection from %s to %s" % (SOURCE, DESTINATION))
199204
200205
Grab bill list
201206
--------------
@@ -220,12 +225,12 @@ This example assumes an existing Configuration_ with valid ``application_key``,
220225
bills = client.get('/me/bill')
221226
for bill in bills:
222227
details = client.get('/me/bill/%s' % bill)
223-
print "%12s (%s): %10s --> %s" % (
228+
print("%12s (%s): %10s --> %s" % (
224229
bill,
225230
details['date'],
226231
details['priceWithTax']['text'],
227232
details['pdfUrl'],
228-
)
233+
))
229234
230235
Enable network burst in SBG1
231236
----------------------------
@@ -255,7 +260,7 @@ This example assumes an existing Configuration_ with valid ``application_key``,
255260
if details['datacenter'] == 'sbg1':
256261
# enable burst on server
257262
client.put('/dedicated/server/%s/burst' % server, status='active')
258-
print "Enabled burst for %s server located in SBG-1" % server
263+
print("Enabled burst for %s server located in SBG-1" % server)
259264
260265
List application authorized to access your account
261266
--------------------------------------------------
@@ -295,8 +300,8 @@ This example assumes an existing Configuration_ with valid ``application_key``,
295300
credential['expiration'],
296301
credential['lastUse'],
297302
])
298-
print tabulate(table, headers=['ID', 'App Name', 'Description',
299-
'Token Creation', 'Token Expiration', 'Token Last Use'])
303+
print(tabulate(table, headers=['ID', 'App Name', 'Description',
304+
'Token Creation', 'Token Expiration', 'Token Last Use']))
300305
301306
Before running this example, make sure you have the
302307
`tabulate <https://pypi.python.org/pypi/tabulate>`_ library installed. It's a
@@ -326,7 +331,7 @@ fully installed on the machine and a consumer key allowed on the server exists.
326331
327332
# check arguments
328333
if len(sys.argv) != 3:
329-
print "Usage: %s SERVER_NAME ALLOWED_IP_V4" % sys.argv[0]
334+
print("Usage: %s SERVER_NAME ALLOWED_IP_V4" % sys.argv[0])
330335
sys.exit(1)
331336
332337
server_name = sys.argv[1]
@@ -343,7 +348,7 @@ fully installed on the machine and a consumer key allowed on the server exists.
343348
try:
344349
# use a named temfile and feed it to java web start
345350
with tempfile.NamedTemporaryFile() as f:
346-
f.write(client.get('/dedicated/server/ns6457228.ip-178-33-61.eu/features/ipmi/access?type=kvmipJnlp')['value'])
351+
f.write(client.get('/dedicated/server/'+server_name+'/features/ipmi/access?type=kvmipJnlp')['value'])
347352
f.flush()
348353
subprocess.call(["javaws", f.name])
349354
break
@@ -355,10 +360,10 @@ Running is only a simple command line:
355360
.. code:: bash
356361
357362
# Basic
358-
python open_kvm.py ns1234567.ip-178-42-42.eu $(curl ifconfig.ovh)
363+
python open_kvm.py ns1234567.ip-42-42-42.eu $(curl ifconfig.ovh)
359364
360365
# Use a specific consumer key
361-
OVH_CONSUMER_KEY=AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA python open_kvm.py ns6457228.ip-178-33-61.eu $(curl -s ifconfig.ovh)
366+
OVH_CONSUMER_KEY=AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA python open_kvm.py ns1234567.ip-42-42-42.eu $(curl -s ifconfig.ovh)
362367
363368
Configuration
364369
=============

docs/index.rst

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ creation and requests signing.
2525
)
2626
2727
# Print nice welcome message
28-
print "Welcome", client.get('/me')['firstname']
28+
print("Welcome", client.get('/me')['firstname'])
2929
3030
Installation
3131
============
@@ -112,6 +112,11 @@ behalf, you need a **consumer key (CK)**.
112112
113113
# -*- encoding: utf-8 -*-
114114
115+
try:
116+
input = raw_input
117+
except NameError:
118+
pass
119+
115120
import ovh
116121
117122
# create a client using configuration
@@ -125,12 +130,12 @@ behalf, you need a **consumer key (CK)**.
125130
# Request token
126131
validation = client.request_consumerkey(access_rules)
127132
128-
print "Please visit %s to authenticate" % validation['validationUrl']
129-
raw_input("and press Enter to continue...")
133+
print("Please visit %s to authenticate" % validation['validationUrl'])
134+
input("and press Enter to continue...")
130135
131136
# Print nice welcome message
132-
print "Welcome", client.get('/me')['firstname']
133-
print "Btw, your 'consumerKey' is '%s'" % validation['consumerKey']
137+
print("Welcome", client.get('/me')['firstname'])
138+
print("Btw, your 'consumerKey' is '%s'" % validation['consumerKey'])
134139
135140
136141
Returned ``consumerKey`` should then be kept to avoid re-authenticating your
@@ -179,7 +184,7 @@ is only supported with reserved keywords.
179184
to=DESTINATION
180185
localCopy=False
181186
)
182-
print "Installed new mail redirection from %s to %s" % (SOURCE, DESTINATION)
187+
print("Installed new mail redirection from %s to %s" % (SOURCE, DESTINATION))
183188
184189
Grab bill list
185190
--------------
@@ -204,12 +209,12 @@ This example assumes an existing Configuration_ with valid ``application_key``,
204209
bills = client.get('/me/bill')
205210
for bill in bills:
206211
details = client.get('/me/bill/%s' % bill)
207-
print "%12s (%s): %10s --> %s" % (
212+
print("%12s (%s): %10s --> %s" % (
208213
bill,
209214
details['date'],
210215
details['priceWithTax']['text'],
211216
details['pdfUrl'],
212-
)
217+
))
213218
214219
Enable network burst in SBG1
215220
----------------------------
@@ -239,7 +244,7 @@ This example assumes an existing Configuration_ with valid ``application_key``,
239244
if details['datacenter'] == 'sbg1':
240245
# enable burst on server
241246
client.put('/dedicated/server/%s/burst' % server, status='active')
242-
print "Enabled burst for %s server located in SBG-1" % server
247+
print("Enabled burst for %s server located in SBG-1" % server)
243248
244249
List application authorized to access your account
245250
--------------------------------------------------
@@ -279,8 +284,8 @@ This example assumes an existing Configuration_ with valid ``application_key``,
279284
credential['expiration'],
280285
credential['lastUse'],
281286
])
282-
print tabulate(table, headers=['ID', 'App Name', 'Description',
283-
'Token Creation', 'Token Expiration', 'Token Last Use'])
287+
print(tabulate(table, headers=['ID', 'App Name', 'Description',
288+
'Token Creation', 'Token Expiration', 'Token Last Use']))
284289
285290
Before running this example, make sure you have the
286291
`tabulate <https://pypi.python.org/pypi/tabulate>`_ library installed. It's a
@@ -445,6 +450,6 @@ OVH North America
445450
Related links
446451
=============
447452

448-
- **contribute**: https://github.com/ovh/python-ovh
453+
- **Contribute**: https://github.com/ovh/python-ovh
449454
- **Report bugs**: https://github.com/ovh/python-ovh/issues
450455
- **Download**: http://pypi.python.org/pypi/ovh

examples/serviceExpiration/serviceThatWillExpired.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,4 +71,4 @@
7171
services_will_expired.append( [ service_type, service, service_infos['status'], service_infos['expiration'] ] )
7272

7373
# At the end, we show service expirated or that will expirated (in a table with tabulate)
74-
print tabulate(services_will_expired, headers=['Type', 'ID', 'status', 'expiration date'])
74+
print(tabulate(services_will_expired, headers=['Type', 'ID', 'status', 'expiration date']))

examples/serviceList/serviceList.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,4 @@
6363
services_will_expired.append( [ service_type, service, service_infos['status'], service_infos['expiration'] ] )
6464

6565
# At the end, we show service expirated or that will expirated (in a table with tabulate)
66-
print tabulate(services_will_expired, headers=['Type', 'ID', 'status', 'expiration date'])
66+
print(tabulate(services_will_expired, headers=['Type', 'ID', 'status', 'expiration date']))

ovh/client.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,9 @@ class Client(object):
112112
client = Client(REGION, APP_KEY, APP_SECRET, CONSUMER_KEY)
113113
114114
try:
115-
print client.get('/me')
115+
print(client.get('/me'))
116116
except APIError as e:
117-
print "Ooops, failed to get my info:", e.msg
117+
print("Ooops, failed to get my info:", e.msg)
118118
119119
"""
120120

@@ -261,6 +261,11 @@ def request_consumerkey(self, access_rules, redirect_url=None):
261261
262262
.. code:: python
263263
264+
try:
265+
input = raw_input
266+
except NameError:
267+
pass
268+
264269
# Request RO, /me API access
265270
access_rules = [
266271
{'method': 'GET', 'path': '/me'},
@@ -269,11 +274,11 @@ def request_consumerkey(self, access_rules, redirect_url=None):
269274
# Request token
270275
validation = client.request_consumerkey(access_rules)
271276
272-
print "Please visit", validation['validationUrl'], "to authenticate"
273-
raw_input("and press Enter to continue...")
277+
print("Please visit", validation['validationUrl'], "to authenticate")
278+
input("and press Enter to continue...")
274279
275280
# Print nice welcome message
276-
print "Welcome", client.get('/me')['firstname']
281+
print("Welcome", client.get('/me')['firstname'])
277282
278283
279284
:param list access_rules: Mapping specifying requested privileges.

0 commit comments

Comments
 (0)