fix unicode errors in iosxr
This commit is contained in:
parent
045f0ff520
commit
0b5b5ec50a
2 changed files with 6 additions and 5 deletions
|
@ -29,7 +29,7 @@ import re
|
|||
import hashlib
|
||||
|
||||
from ansible.module_utils.six.moves import zip
|
||||
from ansible.module_utils._text import to_bytes
|
||||
from ansible.module_utils._text import to_bytes, to_native
|
||||
from ansible.module_utils.network_common import to_list
|
||||
|
||||
DEFAULT_COMMENT_TOKENS = ['#', '!', '/*', '*/', 'echo']
|
||||
|
@ -205,6 +205,7 @@ class NetworkConfig(object):
|
|||
def parse(self, lines, comment_tokens=None):
|
||||
toplevel = re.compile(r'\S')
|
||||
childline = re.compile(r'^\s*(.+)$')
|
||||
entry_reg = re.compile(r'([{};])')
|
||||
|
||||
ancestors = list()
|
||||
config = list()
|
||||
|
@ -212,8 +213,8 @@ class NetworkConfig(object):
|
|||
curlevel = 0
|
||||
prevlevel = 0
|
||||
|
||||
for linenum, line in enumerate(str(lines).split('\n')):
|
||||
text = str(re.sub(r'([{};])', '', line)).strip()
|
||||
for linenum, line in enumerate(to_native(lines, errors='surrogate_or_strict').split('\n')):
|
||||
text = entry_reg.sub('', line).strip()
|
||||
|
||||
cfg = ConfigLine(line)
|
||||
|
||||
|
|
|
@ -25,7 +25,7 @@ import time
|
|||
import glob
|
||||
|
||||
from ansible.plugins.action.iosxr import ActionModule as _ActionModule
|
||||
from ansible.module_utils._text import to_text
|
||||
from ansible.module_utils._text import to_text, to_bytes
|
||||
from ansible.module_utils.six.moves.urllib.parse import urlsplit
|
||||
from ansible.utils.vars import merge_hash
|
||||
|
||||
|
@ -74,7 +74,7 @@ class ActionModule(_ActionModule):
|
|||
os.remove(fn)
|
||||
tstamp = time.strftime("%Y-%m-%d@%H:%M:%S", time.localtime(time.time()))
|
||||
filename = '%s/%s_config.%s' % (backup_path, host, tstamp)
|
||||
open(filename, 'w').write(contents)
|
||||
open(filename, 'w').write(to_bytes(contents))
|
||||
return filename
|
||||
|
||||
def _handle_template(self):
|
||||
|
|
Loading…
Reference in a new issue