1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

Remove need for translate/maketrans due to py3 differences

* translate() has a different api for text vs byte strings
* maketrans must be imported from a different location on py2 vs py3

Since this is such a small string outside of a loop we don't have to
worry too much about speed so it's better to have a single piece of code
that works on both py2 and py3
This commit is contained in:
Toshio Kuratomi 2016-11-07 09:53:26 -08:00 committed by Matt Clay
parent c2f4e7c852
commit 4d3fec908b

View file

@ -278,7 +278,6 @@ except ImportError:
pass
import os
import string
import time
from netaddr import IPNetwork, IPAddress
@ -757,11 +756,7 @@ class PyVmomiHelper(object):
if [x for x in pspec.keys() if x.startswith('size_') or x == 'size']:
# size_tb, size_gb, size_mb, size_kb, size_b ...?
if 'size' in pspec:
# http://stackoverflow.com/a/1451407
trans = string.maketrans('', '')
chars = trans.translate(trans, string.digits)
expected = pspec['size'].translate(trans, chars)
expected = expected
expected = ''.join(c for c in pspec['size'] if c.isdigit())
unit = pspec['size'].replace(expected, '').lower()
expected = int(expected)
else: