Skip to content

Commit d4685f5

Browse files
authored
Unicode fix2 (#324)
* Handle both ASCII and Unicode content when writing inventory and config files. Fixes #323. * Increment version.
1 parent 0e9b54f commit d4685f5

File tree

3 files changed

+7
-11
lines changed

3 files changed

+7
-11
lines changed

library/juniper_junos_facts.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,6 @@
166166
'''
167167

168168
# Standard library imports
169-
# Python 2.x and 3.x portable open
170-
from io import open
171169
import json
172170
import os.path
173171

@@ -311,8 +309,8 @@ def save_inventory(junos_module, inventory):
311309
file_path = os.path.normpath(os.path.join(save_dir, file_name))
312310
junos_module.logger.debug("Saving inventory to: %s.", file_path)
313311
try:
314-
with open(file_path, 'wt', encoding='utf-8') as fact_file:
315-
fact_file.write(inventory)
312+
with open(file_path, 'wb') as fact_file:
313+
fact_file.write(inventory.encode(encoding='utf-8'))
316314
junos_module.logger.debug("Inventory saved to: %s.", file_path)
317315
except IOError:
318316
junos_module.fail_json(msg="Unable to save inventory. Failed to "

module_utils/juniper_junos_common.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,6 @@
4141
# Standard library imports
4242
from argparse import ArgumentParser
4343
from distutils.version import LooseVersion
44-
# Python 2.x and 3.x portable open
45-
from io import open
4644
import json
4745
import logging
4846
import os
@@ -1806,7 +1804,7 @@ def save_text_output(self, name, format, text):
18061804
- If the destination file is not writable.
18071805
"""
18081806
file_path = None
1809-
mode = 'wt'
1807+
mode = 'wb'
18101808
if name == 'diff':
18111809
if self.params.get('diffs_file') is not None:
18121810
file_path = os.path.normpath(self.params.get('diffs_file'))
@@ -1832,8 +1830,8 @@ def save_text_output(self, name, format, text):
18321830
file_path = os.path.normpath(os.path.join(dest_dir, file_name))
18331831
if file_path is not None:
18341832
try:
1835-
with open(file_path, mode, encoding='utf-8') as save_file:
1836-
save_file.write(text)
1833+
with open(file_path, mode) as save_file:
1834+
save_file.write(text.encode(encoding='utf-8'))
18371835
self.logger.debug("Output saved to: %s.", file_path)
18381836
except IOError:
18391837
self.fail_json(msg="Unable to save output. Failed to "

version.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
VERSION = "2.0.1.dev0"
2-
DATE = "2018-Jan-11"
1+
VERSION = "2.0.1"
2+
DATE = "2018-Jan-15"

0 commit comments

Comments
 (0)