mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Python 3: there's no xrange
Use six.moves.range instead (aliased to xrange on Python 2, aliased to range on Python 3). Also I couldn't resist replacing the elaborate chr/ord/randrange dance with the simpler random.choice(string.ascii_lowercase) that was already used elsewhere in the Ansible codebase.
This commit is contained in:
parent
cc6627cdd6
commit
baf9320369
1 changed files with 3 additions and 1 deletions
|
@ -24,8 +24,10 @@ __metaclass__ = type
|
||||||
import pipes
|
import pipes
|
||||||
import random
|
import random
|
||||||
import re
|
import re
|
||||||
|
import string
|
||||||
|
|
||||||
from six import iteritems, string_types
|
from six import iteritems, string_types
|
||||||
|
from six.moves import range
|
||||||
|
|
||||||
from ansible import constants as C
|
from ansible import constants as C
|
||||||
from ansible.errors import AnsibleError
|
from ansible.errors import AnsibleError
|
||||||
|
@ -317,7 +319,7 @@ class PlayContext(Base):
|
||||||
if self.become:
|
if self.become:
|
||||||
|
|
||||||
becomecmd = None
|
becomecmd = None
|
||||||
randbits = ''.join(chr(random.randint(ord('a'), ord('z'))) for x in xrange(32))
|
randbits = ''.join(random.choice(string.ascii_lowercase) for x in range(32))
|
||||||
success_key = 'BECOME-SUCCESS-%s' % randbits
|
success_key = 'BECOME-SUCCESS-%s' % randbits
|
||||||
success_cmd = pipes.quote('echo %s; %s' % (success_key, cmd))
|
success_cmd = pipes.quote('echo %s; %s' % (success_key, cmd))
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue