Skip to content

Commit db943d3

Browse files
committed
python2/python3 updates - print functions part
1 parent 04ef03f commit db943d3

14 files changed

+109
-81
lines changed

examples/example_are_zones_ipv6.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#!/usr/bin/env python
22
"""Cloudflare API code - example"""
33

4+
from __future__ import print_function
5+
46
import os
57
import sys
68

@@ -46,16 +48,16 @@ def main():
4648

4749
ipv6_value = ipv6['value']
4850
if update_ipv6 and ipv6_value == 'off':
49-
print zone_id, ipv6_value, zone_name, '(now updating... off -> on)'
51+
print(zone_id, ipv6_value, zone_name, '(now updating... off -> on)')
5052
try:
5153
ipv6 = cf.zones.settings.ipv6.patch(zone_id, data={'value':'on'})
5254
except CloudFlare.exceptions.CloudFlareAPIError as e:
5355
exit('/zones.settings.ipv6.patch %d %s - api call failed' % (e, e))
5456
ipv6_value = ipv6['value']
5557
if ipv6_value == 'on':
56-
print '\t', '... updated!'
58+
print('\t', '... updated!')
5759
else:
58-
print zone_id, ipv6_value, zone_name
60+
print(zone_id, ipv6_value, zone_name)
5961

6062
exit(0)
6163

examples/example_are_zones_ipv6_simple.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#!/usr/bin/env python
22
"""Cloudflare API code - example"""
33

4+
from __future__ import print_function
5+
46
import os
57
import sys
68

@@ -17,7 +19,7 @@ def main():
1719
zone_id = zone['id']
1820
settings_ipv6 = cf.zones.settings.ipv6.get(zone_id)
1921
ipv6_on = settings_ipv6['value']
20-
print zone_id, ipv6_on, zone_name
22+
print(zone_id, ipv6_on, zone_name)
2123
exit(0)
2224

2325
if __name__ == '__main__':

examples/example_certificates.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#!/usr/bin/env python
22
"""Cloudflare API code - example"""
33

4+
from __future__ import print_function
5+
46
import os
57
import sys
68
import json
@@ -45,35 +47,35 @@ def main():
4547
certificate_sig_count = len(certificate['certificates'])
4648
if certificate_sig_count > 1:
4749
c = certificate['certificates'][0]
48-
print '%-40s %-10s %-32s %-15s [ %s ]' % (
50+
print('%-40s %-10s %-32s %-15s [ %s ]' % (
4951
zone_name,
5052
certificate_type,
5153
primary_certificate,
5254
c['signature'],
5355
','.join(certificate_hosts)
54-
)
56+
))
5557
nn = 0
5658
for c in certificate['certificates']:
5759
nn += 1
5860
if nn == 1:
5961
next
60-
print '%-40s %-10s %-32s %2d:%-15s [ %s ]' % (
62+
print('%-40s %-10s %-32s %2d:%-15s [ %s ]' % (
6163
'',
6264
'',
6365
'',
6466
nn,
6567
c['signature'],
6668
''
67-
)
69+
))
6870
else:
6971
for c in certificate['certificates']:
70-
print '%-40s %-10s %-32s %-15s [ %s ]' % (
72+
print('%-40s %-10s %-32s %-15s [ %s ]' % (
7173
zone_name,
7274
certificate_type,
7375
primary_certificate,
7476
c['signature'],
7577
','.join(certificate_hosts)
76-
)
78+
))
7779

7880
exit(0)
7981

examples/example_create_zone_and_populate.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#!/usr/bin/env python
22
"""Cloudflare API code - example"""
33

4+
from __future__ import print_function
5+
46
import os
57
import sys
68

@@ -20,7 +22,7 @@ def main():
2022
# Create zone - which will only work if ...
2123
# 1) The zone is not on Cloudflare.
2224
# 2) The zone passes a whois test
23-
print 'Create zone %s ...' % (zone_name)
25+
print('Create zone %s ...' % (zone_name))
2426
try:
2527
zone_info = cf.zones.post(data={'jump_start':False, 'name': zone_name})
2628
except CloudFlare.exceptions.CloudFlareAPIError as e:
@@ -35,13 +37,13 @@ def main():
3537
zone_owner = '"' + zone_info['owner']['name'] + '"'
3638
zone_plan = zone_info['plan']['name']
3739
zone_status = zone_info['status']
38-
print '\t%s name=%s owner=%s plan=%s status=%s\n' % (
40+
print('\t%s name=%s owner=%s plan=%s status=%s\n' % (
3941
zone_id,
4042
zone_name,
4143
zone_owner,
4244
zone_plan,
4345
zone_status
44-
)
46+
))
4547

4648
# DNS records to create
4749
dns_records = [
@@ -53,7 +55,7 @@ def main():
5355
{'name':'shakespeare', 'type':'TXT', 'content':"What's in a name? That which we call a rose by any other name would smell as sweet."}
5456
]
5557

56-
print 'Create DNS records ...'
58+
print('Create DNS records ...')
5759
for dns_record in dns_records:
5860
# Create DNS record
5961
try:
@@ -62,15 +64,15 @@ def main():
6264
exit('/zones.dns_records.post %s %s - %d %s' % (zone_name, dns_record['name'], e, e))
6365
# Print respose info - they should be the same
6466
dns_record = r
65-
print '\t%s %30s %6d %-5s %s ; proxied=%s proxiable=%s' % (
67+
print('\t%s %30s %6d %-5s %s ; proxied=%s proxiable=%s' % (
6668
dns_record['id'],
6769
dns_record['name'],
6870
dns_record['ttl'],
6971
dns_record['type'],
7072
dns_record['content'],
7173
dns_record['proxied'],
7274
dns_record['proxiable']
73-
)
75+
))
7476

7577
# set proxied flag to false - for example
7678
dns_record_id = dns_record['id']
@@ -89,27 +91,27 @@ def main():
8991
except CloudFlare.exceptions.CloudFlareAPIError as e:
9092
exit('/zones/dns_records.put %d %s - api call failed' % (e, e))
9193

92-
print ''
94+
print('')
9395

9496
# Now read back all the DNS records
95-
print 'Read back DNS records ...'
97+
print('Read back DNS records ...')
9698
try:
9799
dns_records = cf.zones.dns_records.get(zone_id)
98100
except CloudFlare.exceptions.CloudFlareAPIError as e:
99101
exit('/zones.dns_records.get %s - %d %s' % (zone_name, e, e))
100102

101103
for dns_record in sorted(dns_records, key=lambda v: v['name']):
102-
print '\t%s %30s %6d %-5s %s ; proxied=%s proxiable=%s' % (
104+
print('\t%s %30s %6d %-5s %s ; proxied=%s proxiable=%s' % (
103105
dns_record['id'],
104106
dns_record['name'],
105107
dns_record['ttl'],
106108
dns_record['type'],
107109
dns_record['content'],
108110
dns_record['proxied'],
109111
dns_record['proxiable']
110-
)
112+
))
111113

112-
print ''
114+
print('')
113115

114116
exit(0)
115117

examples/example_delete_zone_entry.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#!/usr/bin/env python
22
"""Cloudflare API code - example"""
33

4+
from __future__ import print_function
5+
46
import os
57
import sys
68
import re
@@ -41,7 +43,7 @@ def main():
4143
zone_id = zone['id']
4244
zone_name = zone['name']
4345

44-
print 'ZONE:', zone_id, zone_name
46+
print('ZONE:', zone_id, zone_name)
4547

4648
try:
4749
params = {'name':dns_name + '.' + zone_name}
@@ -55,17 +57,17 @@ def main():
5557
dns_record_name = dns_record['name']
5658
dns_record_type = dns_record['type']
5759
dns_record_value = dns_record['content']
58-
print 'DNS RECORD:', dns_record_id, dns_record_name, dns_record_type, dns_record_value
60+
print('DNS RECORD:', dns_record_id, dns_record_name, dns_record_type, dns_record_value)
5961

6062
try:
6163
dns_record = cf.zones.dns_records.delete(zone_id, dns_record_id)
62-
print 'DELETED'
64+
print('DELETED')
6365
except CloudFlare.exceptions.CloudFlareAPIError as e:
6466
exit('/zones.dns_records.delete %s - %d %s - api call failed' % (dns_name, e, e))
6567
found = True
6668

6769
if not found:
68-
print 'RECORD NOT FOUND'
70+
print('RECORD NOT FOUND')
6971

7072
exit(0)
7173

examples/example_dns_export.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#!/usr/bin/env python
22
"""Cloudflare API code - example"""
33

4+
from __future__ import print_function
5+
46
import os
57
import sys
68
sys.path.insert(0, os.path.abspath('..'))
@@ -43,7 +45,7 @@ def main():
4345
if len(l) == 0 or l[0] == ';':
4446
# blank line or comment line are skipped - to make example easy to see
4547
continue
46-
print l
48+
print(l)
4749

4850
exit(0)
4951

examples/example_dnssec_settings.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#!/usr/bin/env python
22
"""Cloudflare API code - example"""
33

4+
from __future__ import print_function
5+
46
import os
57
import sys
68

@@ -37,16 +39,16 @@ def main():
3739
except CloudFlare.exceptions.CloudFlareAPIError as e:
3840
exit('/zones.dnssec.get %d %s - api call failed' % (e, e))
3941

40-
print zone_id, zone_name
42+
print(zone_id, zone_name)
4143
# display every setting value
4244
for setting in sorted(settings):
43-
print '\t%-30s %10s = %s' % (
45+
print('\t%-30s %10s = %s' % (
4446
setting,
4547
'(editable)' if setting == 'status' else '',
4648
settings[setting]
47-
)
49+
))
4850

49-
print ''
51+
print('')
5052

5153
exit(0)
5254

examples/example_ips.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#!/usr/bin/env python
22
"""Cloudflare API code - example"""
33

4+
from __future__ import print_function
5+
46
import os
57
import sys
68

@@ -18,12 +20,12 @@ def main():
1820
except Exception as e:
1921
exit('/ips - %s - api call connection failed' % (e))
2022

21-
print 'ipv4_cidrs count = ', len(ips['ipv4_cidrs'])
23+
print('ipv4_cidrs count = ', len(ips['ipv4_cidrs']))
2224
for cidr in sorted(set(ips['ipv4_cidrs'])):
23-
print '\t', cidr
24-
print 'ipv6_cidrs count = ', len(ips['ipv6_cidrs'])
25+
print('\t', cidr)
26+
print('ipv6_cidrs count = ', len(ips['ipv6_cidrs']))
2527
for cidr in sorted(set(ips['ipv6_cidrs'])):
26-
print '\t', cidr
28+
print('\t', cidr)
2729
exit(0)
2830

2931
if __name__ == '__main__':

examples/example_paging_thru_zones.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#!/usr/bin/env python
22
"""Cloudflare API code - example"""
33

4+
from __future__ import print_function
5+
46
import os
57
import sys
68

@@ -31,7 +33,7 @@ def main():
3133
total_count = raw_results['result_info']['total_count']
3234
total_pages = raw_results['result_info']['total_pages']
3335

34-
print "COUNT=%d PAGE=%d PER_PAGE=%d TOTAL_COUNT=%d TOTAL_PAGES=%d -- %s" % (count, page, per_page, total_count, total_pages, domains)
36+
print("COUNT=%d PAGE=%d PER_PAGE=%d TOTAL_COUNT=%d TOTAL_PAGES=%d -- %s" % (count, page, per_page, total_count, total_pages, domains))
3537

3638
if page_number == total_pages:
3739
break

examples/example_proxied.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#!/usr/bin/env python
22
"""Cloudflare API code - example"""
33

4+
from __future__ import print_function
5+
46
import os
57
import sys
68

@@ -44,7 +46,7 @@ def main():
4446
zone_name = zone['name']
4547
zone_id = zone['id']
4648

47-
print "Zone:\t%s %s" % (zone_id, zone_name)
49+
print("Zone:\t%s %s" % (zone_id, zone_name))
4850

4951
try:
5052
params = {'name': dns_name}
@@ -64,9 +66,9 @@ def main():
6466
r_ttl = dns_record['ttl']
6567
r_proxied = dns_record['proxied']
6668
r_proxiable = dns_record['proxiable']
67-
print 'Record:\t%s %s %s %6d %-5s %s ; proxied=%s proxiable=%s' % (
69+
print('Record:\t%s %s %s %6d %-5s %s ; proxied=%s proxiable=%s' % (
6870
r_zone_id, r_id, r_name, r_ttl, r_type, r_content, r_proxied, r_proxiable
69-
)
71+
))
7072

7173
if r_proxied == new_r_proxied_flag:
7274
# Nothing to do
@@ -97,9 +99,9 @@ def main():
9799
r_ttl = dns_record['ttl']
98100
r_proxied = dns_record['proxied']
99101
r_proxiable = dns_record['proxiable']
100-
print 'Record:\t%s %s %s %6d %-5s %s ; proxied=%s proxiable=%s <<-- after' % (
102+
print('Record:\t%s %s %s %6d %-5s %s ; proxied=%s proxiable=%s <<-- after' % (
101103
r_zone_id, r_id, r_name, r_ttl, r_type, r_content, r_proxied, r_proxiable
102-
)
104+
))
103105

104106
exit(0)
105107

0 commit comments

Comments
 (0)