diff options
author | Toshio Kuratomi <a.badger@gmail.com> | 2016-11-07 09:15:18 -0800 |
---|---|---|
committer | Toshio Kuratomi <a.badger@gmail.com> | 2016-11-07 10:24:19 -0800 |
commit | ee14e0cc2a2e9f7b9e1982fd55b4a63ebbc2a77e (patch) | |
tree | 963e0c0aae9f8ac4e473354e75cb2c3268c86520 | |
parent | ecb7f13119f0184d4c47659a567da253bc51905d (diff) | |
download | ansible-ee14e0cc2a2e9f7b9e1982fd55b4a63ebbc2a77e.tar.gz |
Text's .translate() is easier to use than bytes
Text strings and byte strings both have a translate method but the byte
string version is harder to use. It requires a mapping of all 256 bytes
to a translation value. Text strings only require a mapping from the
characters that are changing to the new string. Switching to text
strings on both py2 and py3 allows us to state what we're getting rid of
simply without having to rely on the maketrans() helper function.
-rw-r--r-- | lib/ansible/module_utils/facts.py | 11 |
1 files changed, 2 insertions, 9 deletions
diff --git a/lib/ansible/module_utils/facts.py b/lib/ansible/module_utils/facts.py index c3c4b69f2d..8f8710fac2 100644 --- a/lib/ansible/module_utils/facts.py +++ b/lib/ansible/module_utils/facts.py @@ -38,13 +38,6 @@ from ansible.module_utils.six.moves import configparser, StringIO from ansible.module_utils._text import to_native try: - # python2 - from string import maketrans -except ImportError: - # python3 - maketrans = str.maketrans # TODO: is this really identical? - -try: import selinux HAVE_SELINUX=True except ImportError: @@ -1647,8 +1640,8 @@ class OpenBSDHardware(Hardware): # total: 69268k bytes allocated = 0k used, 69268k available rc, out, err = self.module.run_command("/sbin/swapctl -sk") if rc == 0: - swaptrans = maketrans('kmg', ' ') - data = out.split() + swaptrans = { ord(u'k'): None, ord(u'm'): None, ord(u'g'): None} + data = to_text(out, errors='surrogate_or_strict').split() self.facts['swapfree_mb'] = int(data[-2].translate(swaptrans)) // 1024 self.facts['swaptotal_mb'] = int(data[1].translate(swaptrans)) // 1024 |