mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-23 13:20:23 -07: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:
parent
c2f4e7c852
commit
4d3fec908b
1 changed files with 1 additions and 6 deletions
|
@ -278,7 +278,6 @@ except ImportError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import string
|
|
||||||
import time
|
import time
|
||||||
from netaddr import IPNetwork, IPAddress
|
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']:
|
if [x for x in pspec.keys() if x.startswith('size_') or x == 'size']:
|
||||||
# size_tb, size_gb, size_mb, size_kb, size_b ...?
|
# size_tb, size_gb, size_mb, size_kb, size_b ...?
|
||||||
if 'size' in pspec:
|
if 'size' in pspec:
|
||||||
# http://stackoverflow.com/a/1451407
|
expected = ''.join(c for c in pspec['size'] if c.isdigit())
|
||||||
trans = string.maketrans('', '')
|
|
||||||
chars = trans.translate(trans, string.digits)
|
|
||||||
expected = pspec['size'].translate(trans, chars)
|
|
||||||
expected = expected
|
|
||||||
unit = pspec['size'].replace(expected, '').lower()
|
unit = pspec['size'].replace(expected, '').lower()
|
||||||
expected = int(expected)
|
expected = int(expected)
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue