Skip to content

Commit

Permalink
python2/python3 updates - print functions part
Browse files Browse the repository at this point in the history
  • Loading branch information
mahtin committed Feb 15, 2018
1 parent 04ef03f commit db943d3
Show file tree
Hide file tree
Showing 14 changed files with 109 additions and 81 deletions.
8 changes: 5 additions & 3 deletions examples/example_are_zones_ipv6.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#!/usr/bin/env python
"""Cloudflare API code - example"""

from __future__ import print_function

import os
import sys

Expand Down Expand Up @@ -46,16 +48,16 @@ def main():

ipv6_value = ipv6['value']
if update_ipv6 and ipv6_value == 'off':
print zone_id, ipv6_value, zone_name, '(now updating... off -> on)'
print(zone_id, ipv6_value, zone_name, '(now updating... off -> on)')
try:
ipv6 = cf.zones.settings.ipv6.patch(zone_id, data={'value':'on'})
except CloudFlare.exceptions.CloudFlareAPIError as e:
exit('/zones.settings.ipv6.patch %d %s - api call failed' % (e, e))
ipv6_value = ipv6['value']
if ipv6_value == 'on':
print '\t', '... updated!'
print('\t', '... updated!')
else:
print zone_id, ipv6_value, zone_name
print(zone_id, ipv6_value, zone_name)

exit(0)

Expand Down
4 changes: 3 additions & 1 deletion examples/example_are_zones_ipv6_simple.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#!/usr/bin/env python
"""Cloudflare API code - example"""

from __future__ import print_function

import os
import sys

Expand All @@ -17,7 +19,7 @@ def main():
zone_id = zone['id']
settings_ipv6 = cf.zones.settings.ipv6.get(zone_id)
ipv6_on = settings_ipv6['value']
print zone_id, ipv6_on, zone_name
print(zone_id, ipv6_on, zone_name)
exit(0)

if __name__ == '__main__':
Expand Down
14 changes: 8 additions & 6 deletions examples/example_certificates.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#!/usr/bin/env python
"""Cloudflare API code - example"""

from __future__ import print_function

import os
import sys
import json
Expand Down Expand Up @@ -45,35 +47,35 @@ def main():
certificate_sig_count = len(certificate['certificates'])
if certificate_sig_count > 1:
c = certificate['certificates'][0]
print '%-40s %-10s %-32s %-15s [ %s ]' % (
print('%-40s %-10s %-32s %-15s [ %s ]' % (
zone_name,
certificate_type,
primary_certificate,
c['signature'],
','.join(certificate_hosts)
)
))
nn = 0
for c in certificate['certificates']:
nn += 1
if nn == 1:
next
print '%-40s %-10s %-32s %2d:%-15s [ %s ]' % (
print('%-40s %-10s %-32s %2d:%-15s [ %s ]' % (
'',
'',
'',
nn,
c['signature'],
''
)
))
else:
for c in certificate['certificates']:
print '%-40s %-10s %-32s %-15s [ %s ]' % (
print('%-40s %-10s %-32s %-15s [ %s ]' % (
zone_name,
certificate_type,
primary_certificate,
c['signature'],
','.join(certificate_hosts)
)
))

exit(0)

Expand Down
24 changes: 13 additions & 11 deletions examples/example_create_zone_and_populate.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#!/usr/bin/env python
"""Cloudflare API code - example"""

from __future__ import print_function

import os
import sys

Expand All @@ -20,7 +22,7 @@ def main():
# Create zone - which will only work if ...
# 1) The zone is not on Cloudflare.
# 2) The zone passes a whois test
print 'Create zone %s ...' % (zone_name)
print('Create zone %s ...' % (zone_name))
try:
zone_info = cf.zones.post(data={'jump_start':False, 'name': zone_name})
except CloudFlare.exceptions.CloudFlareAPIError as e:
Expand All @@ -35,13 +37,13 @@ def main():
zone_owner = '"' + zone_info['owner']['name'] + '"'
zone_plan = zone_info['plan']['name']
zone_status = zone_info['status']
print '\t%s name=%s owner=%s plan=%s status=%s\n' % (
print('\t%s name=%s owner=%s plan=%s status=%s\n' % (
zone_id,
zone_name,
zone_owner,
zone_plan,
zone_status
)
))

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

print 'Create DNS records ...'
print('Create DNS records ...')
for dns_record in dns_records:
# Create DNS record
try:
Expand All @@ -62,15 +64,15 @@ def main():
exit('/zones.dns_records.post %s %s - %d %s' % (zone_name, dns_record['name'], e, e))
# Print respose info - they should be the same
dns_record = r
print '\t%s %30s %6d %-5s %s ; proxied=%s proxiable=%s' % (
print('\t%s %30s %6d %-5s %s ; proxied=%s proxiable=%s' % (
dns_record['id'],
dns_record['name'],
dns_record['ttl'],
dns_record['type'],
dns_record['content'],
dns_record['proxied'],
dns_record['proxiable']
)
))

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

print ''
print('')

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

for dns_record in sorted(dns_records, key=lambda v: v['name']):
print '\t%s %30s %6d %-5s %s ; proxied=%s proxiable=%s' % (
print('\t%s %30s %6d %-5s %s ; proxied=%s proxiable=%s' % (
dns_record['id'],
dns_record['name'],
dns_record['ttl'],
dns_record['type'],
dns_record['content'],
dns_record['proxied'],
dns_record['proxiable']
)
))

print ''
print('')

exit(0)

Expand Down
10 changes: 6 additions & 4 deletions examples/example_delete_zone_entry.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#!/usr/bin/env python
"""Cloudflare API code - example"""

from __future__ import print_function

import os
import sys
import re
Expand Down Expand Up @@ -41,7 +43,7 @@ def main():
zone_id = zone['id']
zone_name = zone['name']

print 'ZONE:', zone_id, zone_name
print('ZONE:', zone_id, zone_name)

try:
params = {'name':dns_name + '.' + zone_name}
Expand All @@ -55,17 +57,17 @@ def main():
dns_record_name = dns_record['name']
dns_record_type = dns_record['type']
dns_record_value = dns_record['content']
print 'DNS RECORD:', dns_record_id, dns_record_name, dns_record_type, dns_record_value
print('DNS RECORD:', dns_record_id, dns_record_name, dns_record_type, dns_record_value)

try:
dns_record = cf.zones.dns_records.delete(zone_id, dns_record_id)
print 'DELETED'
print('DELETED')
except CloudFlare.exceptions.CloudFlareAPIError as e:
exit('/zones.dns_records.delete %s - %d %s - api call failed' % (dns_name, e, e))
found = True

if not found:
print 'RECORD NOT FOUND'
print('RECORD NOT FOUND')

exit(0)

Expand Down
4 changes: 3 additions & 1 deletion examples/example_dns_export.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#!/usr/bin/env python
"""Cloudflare API code - example"""

from __future__ import print_function

import os
import sys
sys.path.insert(0, os.path.abspath('..'))
Expand Down Expand Up @@ -43,7 +45,7 @@ def main():
if len(l) == 0 or l[0] == ';':
# blank line or comment line are skipped - to make example easy to see
continue
print l
print(l)

exit(0)

Expand Down
10 changes: 6 additions & 4 deletions examples/example_dnssec_settings.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#!/usr/bin/env python
"""Cloudflare API code - example"""

from __future__ import print_function

import os
import sys

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

print zone_id, zone_name
print(zone_id, zone_name)
# display every setting value
for setting in sorted(settings):
print '\t%-30s %10s = %s' % (
print('\t%-30s %10s = %s' % (
setting,
'(editable)' if setting == 'status' else '',
settings[setting]
)
))

print ''
print('')

exit(0)

Expand Down
10 changes: 6 additions & 4 deletions examples/example_ips.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#!/usr/bin/env python
"""Cloudflare API code - example"""

from __future__ import print_function

import os
import sys

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

print 'ipv4_cidrs count = ', len(ips['ipv4_cidrs'])
print('ipv4_cidrs count = ', len(ips['ipv4_cidrs']))
for cidr in sorted(set(ips['ipv4_cidrs'])):
print '\t', cidr
print 'ipv6_cidrs count = ', len(ips['ipv6_cidrs'])
print('\t', cidr)
print('ipv6_cidrs count = ', len(ips['ipv6_cidrs']))
for cidr in sorted(set(ips['ipv6_cidrs'])):
print '\t', cidr
print('\t', cidr)
exit(0)

if __name__ == '__main__':
Expand Down
4 changes: 3 additions & 1 deletion examples/example_paging_thru_zones.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#!/usr/bin/env python
"""Cloudflare API code - example"""

from __future__ import print_function

import os
import sys

Expand Down Expand Up @@ -31,7 +33,7 @@ def main():
total_count = raw_results['result_info']['total_count']
total_pages = raw_results['result_info']['total_pages']

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

if page_number == total_pages:
break
Expand Down
12 changes: 7 additions & 5 deletions examples/example_proxied.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#!/usr/bin/env python
"""Cloudflare API code - example"""

from __future__ import print_function

import os
import sys

Expand Down Expand Up @@ -44,7 +46,7 @@ def main():
zone_name = zone['name']
zone_id = zone['id']

print "Zone:\t%s %s" % (zone_id, zone_name)
print("Zone:\t%s %s" % (zone_id, zone_name))

try:
params = {'name': dns_name}
Expand All @@ -64,9 +66,9 @@ def main():
r_ttl = dns_record['ttl']
r_proxied = dns_record['proxied']
r_proxiable = dns_record['proxiable']
print 'Record:\t%s %s %s %6d %-5s %s ; proxied=%s proxiable=%s' % (
print('Record:\t%s %s %s %6d %-5s %s ; proxied=%s proxiable=%s' % (
r_zone_id, r_id, r_name, r_ttl, r_type, r_content, r_proxied, r_proxiable
)
))

if r_proxied == new_r_proxied_flag:
# Nothing to do
Expand Down Expand Up @@ -97,9 +99,9 @@ def main():
r_ttl = dns_record['ttl']
r_proxied = dns_record['proxied']
r_proxiable = dns_record['proxiable']
print 'Record:\t%s %s %s %6d %-5s %s ; proxied=%s proxiable=%s <<-- after' % (
print('Record:\t%s %s %s %6d %-5s %s ; proxied=%s proxiable=%s <<-- after' % (
r_zone_id, r_id, r_name, r_ttl, r_type, r_content, r_proxied, r_proxiable
)
))

exit(0)

Expand Down
Loading

0 comments on commit db943d3

Please sign in to comment.