diff --git a/confluent_client/bin/nodeattrib b/confluent_client/bin/nodeattrib index 1195f07e..61e1a25e 100755 --- a/confluent_client/bin/nodeattrib +++ b/confluent_client/bin/nodeattrib @@ -126,6 +126,6 @@ else: sys.stderr.write(res['error'] + '\n') exitcode = 1 else: - print res['item']['href'].replace('/', '') + print(res['item']['href'].replace('/', '')) sys.exit(exitcode) \ No newline at end of file diff --git a/confluent_client/bin/nodeeventlog b/confluent_client/bin/nodeeventlog index e0f90d20..03f870c5 100755 --- a/confluent_client/bin/nodeeventlog +++ b/confluent_client/bin/nodeeventlog @@ -33,7 +33,8 @@ if path.startswith('/opt'): import confluent.client as client -sys.stdout = codecs.getwriter('utf8')(sys.stdout) +if sys.version_info[0] < 3: + sys.stdout = codecs.getwriter('utf8')(sys.stdout) argparser = optparse.OptionParser( usage="Usage: %prog [options] noderange [clear]") diff --git a/confluent_client/bin/nodelist b/confluent_client/bin/nodelist index 61cf4a69..39c07c93 100755 --- a/confluent_client/bin/nodelist +++ b/confluent_client/bin/nodelist @@ -61,7 +61,7 @@ def main(): sys.stderr.write(res['error'] + '\n') exitcode = 1 else: - print res['item']['href'].replace('/', '') + print(res['item']['href'].replace('/', '')) sys.exit(exitcode) diff --git a/confluent_client/bin/nodesensors b/confluent_client/bin/nodesensors index 05a433a8..c86e1256 100755 --- a/confluent_client/bin/nodesensors +++ b/confluent_client/bin/nodesensors @@ -150,7 +150,7 @@ def sensorpass(showout=True, appendtime=False): showval += ' @' + time.strftime( '%Y-%m-%dT%H:%M:%S') print(u'{0}: {1}:{2}'.format( - node, sensedata['name'], showval).encode('utf-8')) + node, sensedata['name'], showval)) sys.stdout.flush() return resultdata @@ -199,7 +199,7 @@ def main(): orderedsensors.append(name) orderedsensors.sort() for name in orderedsensors: - headernames.append(sensorheaders[name].encode('utf-8')) + headernames.append(sensorheaders[name]) if options.csv: linebyline = False csvwriter = csv.writer(sys.stdout) diff --git a/confluent_client/confluent/client.py b/confluent_client/confluent/client.py index 2c703421..bf8f15b3 100644 --- a/confluent_client/confluent/client.py +++ b/confluent_client/confluent/client.py @@ -15,7 +15,10 @@ # See the License for the specific language governing permissions and # limitations under the License. -import anydbm as dbm +try: + import anydbm as dbm +except ImportError: + import dbm import csv import errno import fnmatch @@ -322,14 +325,19 @@ class Command(object): if knownhosts: certdata = self.connection.getpeercert(binary_form=True) fingerprint = 'sha512$' + hashlib.sha512(certdata).hexdigest() + fingerprint = fingerprint.encode('utf-8') hostid = '@'.join((port, server)) khf = dbm.open(os.path.join(clientcfgdir, "knownhosts"), 'c', 384) if hostid in khf: if fingerprint == khf[hostid]: return else: - replace = raw_input( - "MISMATCHED CERTIFICATE DATA, ACCEPT NEW? (y/n):") + try: + replace = raw_input( + "MISMATCHED CERTIFICATE DATA, ACCEPT NEW? (y/n):") + except NameError: + replace = input( + "MISMATCHED CERTIFICATE DATA, ACCEPT NEW? (y/n):") if replace not in ('y', 'Y'): raise Exception("BAD CERTIFICATE") cprint('Adding new key for %s:%s' % (server, port)) @@ -393,7 +401,7 @@ def print_attrib_path(path, session, requestargs, options, rename=None): for node in sorted(res['databynode']): for attr, val in sorted( res['databynode'][node].items(), - key=lambda (k, v): v.get('sortid', k) if isinstance(v, dict) else k): + key=lambda k: k[1].get('sortid', k[0]) if isinstance(k[1], dict) else k[0]): if attr == 'error': sys.stderr.write('{0}: Error: {1}\n'.format(node, val)) continue @@ -655,4 +663,4 @@ def check_globbing(noderange): 'bash or change directories such that there is no filename ' 'that would conflict.' '\n'.format(noderange)) - sys.exit(1) \ No newline at end of file + sys.exit(1) diff --git a/confluent_client/confluent/tlvdata.py b/confluent_client/confluent/tlvdata.py index 709801ed..18a3328b 100644 --- a/confluent_client/confluent/tlvdata.py +++ b/confluent_client/confluent/tlvdata.py @@ -34,6 +34,8 @@ def decodestr(value): ret = value.decode('cp437') except UnicodeDecodeError: ret = value + except AttributeError: + return value return ret def unicode_dictvalues(dictdata):