Skip to content

Commit

Permalink
Prevent UnicodeDecodeError on non-ascii hostnames
Browse files Browse the repository at this point in the history
  • Loading branch information
Ferry Boender committed Jul 8, 2017
1 parent bd55cc5 commit a56184d
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/ansiblecmdb/data/tpl/csv.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ writer = csv.writer(sys.stdout, delimiter=',', quotechar='"', quoting=csv.QUOTE_
writer.writerow(fieldnames)
for hostname, host in hosts.items():
if 'ansible_facts' not in host:
sys.stderr.write('{0}: No info collected.\n'.format(hostname))
sys.stderr.write(u'{0}: No info collected.\n'.format(hostname))
else:
out_cols = []
for col in get_cols():
Expand Down
2 changes: 1 addition & 1 deletion src/ansiblecmdb/data/tpl/html_fancy_split.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def render(hosts, vars={}, tpl_dirs=[]):
# Render host details
template = lookup.get_template('html_fancy_split_detail.tpl')
for hostname, host in hosts.items():
out_file = os.path.join('cmdb', '{0}.html'.format(hostname))
out_file = os.path.join('cmdb', u'{0}.html'.format(hostname))
output = template.render(host=host, **vars).lstrip().decode('utf8')
with codecs.open(out_file, 'w', encoding='utf8') as f:
f.write(output)
4 changes: 2 additions & 2 deletions src/ansiblecmdb/data/tpl/txt_table.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@ for col in get_cols():
sys.stdout.write('\n')

for col in get_cols():
sys.stdout.write('-' * col_longest[col['title']] + (' ' * col_space))
sys.stdout.write(u'-' * col_longest[col['title']] + (u' ' * col_space))
sys.stdout.write('\n')

# Print out columns
for hostname, host in hosts.items():
if 'ansible_facts' not in host:
sys.stderr.write('{0}: No info collected.\n'.format(hostname))
sys.stderr.write(u'{0}: No info collected.\n'.format(hostname))
else:
for col in get_cols():
sys.stdout.write(col['field'](host).ljust(col_longest[col['title']]) + (' ' * col_space))
Expand Down

0 comments on commit a56184d

Please sign in to comment.