mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-06 21:32:49 +00:00
Fix undefined variables, basestring usage, and some associated python3 issues
This commit is contained in:
@@ -75,17 +75,10 @@ except ImportError:
|
||||
HAS_FLATDICT = False
|
||||
|
||||
from ansible.module_utils.six.moves import configparser
|
||||
from ansible.module_utils._text import to_bytes, to_text
|
||||
from ansible.plugins.callback import CallbackBase
|
||||
|
||||
|
||||
def is_unicode(ch):
|
||||
return isinstance(ch, unicode)
|
||||
|
||||
|
||||
def create_unicode(ch):
|
||||
return unicode(ch, 'utf-8')
|
||||
|
||||
|
||||
class PlainTextSocketAppender(object):
|
||||
def __init__(self,
|
||||
verbose=True,
|
||||
@@ -141,15 +134,13 @@ class PlainTextSocketAppender(object):
|
||||
def put(self, data):
|
||||
# Replace newlines with Unicode line separator
|
||||
# for multi-line events
|
||||
if not is_unicode(data):
|
||||
multiline = create_unicode(data).replace('\n', self.LINE_SEP)
|
||||
else:
|
||||
multiline = data.replace('\n', self.LINE_SEP)
|
||||
multiline += "\n"
|
||||
data = to_text(data, errors='surrogate_or_strict')
|
||||
multiline = data.replace(u'\n', self.LINE_SEP)
|
||||
multiline += u"\n"
|
||||
# Send data, reconnect if needed
|
||||
while True:
|
||||
try:
|
||||
self._conn.send(multiline.encode('utf-8'))
|
||||
self._conn.send(to_bytes(multiline, errors='surrogate_or_strict'))
|
||||
except socket.error:
|
||||
self.reopen_connection()
|
||||
continue
|
||||
|
||||
@@ -227,7 +227,7 @@ class Connection(ConnectionBase):
|
||||
if not os.path.exists(in_path):
|
||||
raise AnsibleFileNotFound("file or module does not exist: %s" % in_path)
|
||||
|
||||
fd = file(in_path, 'rb')
|
||||
fd = open(in_path, 'rb')
|
||||
fstat = os.stat(in_path)
|
||||
try:
|
||||
display.vvv("PUT file is %d bytes" % fstat.st_size, host=self._play_context.remote_addr)
|
||||
|
||||
@@ -64,11 +64,11 @@ class LookupModule(LookupBase):
|
||||
if shelvefile:
|
||||
res = self.read_shelve(shelvefile, key)
|
||||
if res is None:
|
||||
raise AnsibleError("Key %s not found in shelve file %s" % (key, file))
|
||||
raise AnsibleError("Key %s not found in shelve file %s" % (key, shelvefile))
|
||||
# Convert the value read to string
|
||||
ret.append(to_text(res))
|
||||
break
|
||||
else:
|
||||
raise AnsibleError("Could not locate shelve file in lookup: %s" % file)
|
||||
raise AnsibleError("Could not locate shelve file in lookup: %s" % paramvals['file'])
|
||||
|
||||
return ret
|
||||
|
||||
@@ -177,6 +177,5 @@ class Debugger(cmd.Cmd):
|
||||
def default(self, line):
|
||||
try:
|
||||
self.execute(line)
|
||||
display.display(pprint.pformat(result))
|
||||
except:
|
||||
pass
|
||||
|
||||
Reference in New Issue
Block a user