diff options
author | Toshio Kuratomi <toshio@fedoraproject.org> | 2016-04-04 12:57:32 -0700 |
---|---|---|
committer | Toshio Kuratomi <toshio@fedoraproject.org> | 2016-04-04 12:57:32 -0700 |
commit | c75b5ba85f5c690c72b1c238d1c90d39b5909dbb (patch) | |
tree | 0eda45e94df1c06d0cdbde7f4344b63b079c8cba | |
parent | 83367dc52f909036424f15b5375aab0633b6e1cf (diff) | |
download | ansible-c75b5ba85f5c690c72b1c238d1c90d39b5909dbb.tar.gz |
Use to_bytes and to_str instead of str as str is unsafe.
-rw-r--r-- | lib/ansible/plugins/lookup/csvfile.py | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/lib/ansible/plugins/lookup/csvfile.py b/lib/ansible/plugins/lookup/csvfile.py index d0db412c71..42f0d44fbe 100644 --- a/lib/ansible/plugins/lookup/csvfile.py +++ b/lib/ansible/plugins/lookup/csvfile.py @@ -22,6 +22,7 @@ import csv from ansible.errors import AnsibleError from ansible.plugins.lookup import LookupBase +from ansible.utils.unicode import to_bytes, to_str, to_unicode class CSVRecoder: """ @@ -48,7 +49,7 @@ class CSVReader: def next(self): row = self.reader.next() - return [unicode(s, 'utf-8') for s in row] + return [to_unicode(s) for s in row] def __iter__(self): return self @@ -59,13 +60,13 @@ class LookupModule(LookupBase): try: f = open(filename, 'r') - creader = CSVReader(f, delimiter=str(delimiter), encoding=encoding) + creader = CSVReader(f, delimiter=to_bytes(delimiter), encoding=encoding) for row in creader: if row[0] == key: return row[int(col)] except Exception as e: - raise AnsibleError("csvfile: %s" % str(e)) + raise AnsibleError("csvfile: %s" % to_str(e)) return dflt @@ -100,7 +101,7 @@ class LookupModule(LookupBase): paramvals['delimiter'] = "\t" lookupfile = self._loader.path_dwim_relative(basedir, 'files', paramvals['file']) - var = self.read_csv(lookupfile, key, str(paramvals['delimiter']), paramvals['encoding'], paramvals['default'], paramvals['col']) + var = self.read_csv(lookupfile, key, paramvals['delimiter'], paramvals['encoding'], paramvals['default'], paramvals['col']) if var is not None: if type(var) is list: for v in var: |