diff --git a/confluent_client/bin/confetty b/confluent_client/bin/confetty index d8f88d7a..3844f6b8 100755 --- a/confluent_client/bin/confetty +++ b/confluent_client/bin/confetty @@ -933,6 +933,7 @@ def main(): updatestatus(data) continue if data is not None: + data = client.stringify(data) if clearpowermessage: sys.stdout.write("\x1b[2J\x1b[;H") clearpowermessage = False diff --git a/confluent_server/bin/collective b/confluent_server/bin/collective index 5a658895..297401a0 100644 --- a/confluent_server/bin/collective +++ b/confluent_server/bin/collective @@ -61,7 +61,7 @@ def join_collective(server, invitation): make_certificate() s = client.Command().connection while not invitation: - invitation = raw_input('Paste the invitation here: ') + invitation = input('Paste the invitation here: ') tlvdata.send(s, {'collective': {'operation': 'join', 'invitation': invitation, 'server': server}}) diff --git a/confluent_server/confluent/collective/manager.py b/confluent_server/confluent/collective/manager.py index 8f3b9f15..789858e4 100644 --- a/confluent_server/confluent/collective/manager.py +++ b/confluent_server/confluent/collective/manager.py @@ -75,9 +75,9 @@ def connect_to_leader(cert=None, name=None, leader=None): vers = banner.split()[2] pvers = 0 reqver = 4 - if vers == 'v0': + if vers == b'v0': pvers = 2 - elif vers == 'v1': + elif vers == b'v1': pvers = 4 if sys.version_info[0] < 3: pvers = 2 @@ -131,7 +131,7 @@ def connect_to_leader(cert=None, name=None, leader=None): globaldata = tlvdata.recv(remote) dbi = tlvdata.recv(remote) dbsize = dbi['dbsize'] - dbjson = '' + dbjson = b'' while (len(dbjson) < dbsize): ndata = remote.recv(dbsize - len(dbjson)) if not ndata: @@ -279,7 +279,8 @@ def handle_connection(connection, cert, request, local=False): invitation = request['invitation'] try: invitation = base64.b64decode(invitation) - name, invitation = invitation.split('@', 1) + name, invitation = invitation.split(b'@', 1) + name = util.stringify(name) except Exception: tlvdata.send( connection, diff --git a/confluent_server/confluent/config/configmanager.py b/confluent_server/confluent/config/configmanager.py index f727a68f..3e7628a9 100644 --- a/confluent_server/confluent/config/configmanager.py +++ b/confluent_server/confluent/config/configmanager.py @@ -313,9 +313,9 @@ def check_quorum(): def exec_on_leader(function, *args): if isinstance(cfgleader, bool): raise exc.DegradedCollective() - xid = os.urandom(8) + xid = confluent.util.stringify(base64.b64encode(os.urandom(8))) while xid in _pendingchangesets: - xid = os.urandom(8) + xid = confluent.util.stringify(base64.b64encode(os.urandom(8)) _pendingchangesets[xid] = event.Event() rpcpayload = cPickle.dumps({'function': function, 'args': args, 'xid': xid}, protocol=cfgproto) @@ -742,7 +742,7 @@ def follow_channel(channel, proto=2): while msg: sz = struct.unpack('!Q', msg)[0] if sz != 0: - rpc = '' + rpc = b'' while len(rpc) < sz: nrpc = channel.recv(sz - len(rpc)) if not nrpc: diff --git a/confluent_server/confluent/core.py b/confluent_server/confluent/core.py index d43897ef..ff816422 100644 --- a/confluent_server/confluent/core.py +++ b/confluent_server/confluent/core.py @@ -63,8 +63,10 @@ import itertools import os try: import cPickle as pickle + pargs = {} except ImportError: import pickle + pargs = {'encoding': 'utf-8'} import socket import struct import sys @@ -690,7 +692,7 @@ def handle_dispatch(connection, cert, dispatch, peername): pversion = 0 if bytearray(dispatch)[0] == 0x80: pversion = bytearray(dispatch)[1] - dispatch = pickle.loads(dispatch) + dispatch = pickle.loads(dispatch, **pargs) configmanager = cfm.ConfigManager(dispatch['tenant']) nodes = dispatch['nodes'] inputdata = dispatch['inputdata'] @@ -968,9 +970,9 @@ def dispatch_request(nodes, manager, element, configmanager, inputdata, raise Exception("Invalid certificate on peer") banner = tlvdata.recv(remote) vers = banner.split()[2] - if vers == 'v0': + if vers == b'v0': pvers = 2 - elif vers == 'v1': + elif vers == b'v1': pvers = 4 if sys.version_info[0] < 3: pvers = 2 @@ -979,7 +981,7 @@ def dispatch_request(nodes, manager, element, configmanager, inputdata, dreq = pickle.dumps({'name': myname, 'nodes': list(nodes), 'path': element,'tenant': configmanager.tenant, 'operation': operation, 'inputdata': inputdata}, - version=pvers) + protocol=pvers) tlvdata.send(remote, {'dispatch': {'name': myname, 'length': len(dreq)}}) remote.sendall(dreq) while True: @@ -1026,7 +1028,7 @@ def dispatch_request(nodes, manager, element, configmanager, inputdata, a['name'])) return rsp += nrsp - rsp = pickle.loads(rsp) + rsp = pickle.loads(rsp, **pargs) if isinstance(rsp, Exception): raise rsp yield rsp diff --git a/confluent_server/confluent/noderange.py b/confluent_server/confluent/noderange.py index 9b4b9b46..be35829e 100644 --- a/confluent_server/confluent/noderange.py +++ b/confluent_server/confluent/noderange.py @@ -162,7 +162,7 @@ class NodeRange(object): pieces = seqrange.split(delimiter) if len(pieces) % 2 != 0: return self.failorreturn(seqrange) - halflen = len(pieces) / 2 + halflen = len(pieces) // 2 left = delimiter.join(pieces[:halflen]) right = delimiter.join(pieces[halflen:]) leftbits = _numextractor.parseString(left).asList() diff --git a/confluent_server/confluent/util.py b/confluent_server/confluent/util.py index 9f03cc32..b347c788 100644 --- a/confluent_server/confluent/util.py +++ b/confluent_server/confluent/util.py @@ -109,7 +109,7 @@ def monotonic_time(): def get_certificate_from_file(certfile): - cert = open(certfile, 'rb').read() + cert = open(certfile, 'r').read() inpemcert = False prunedcert = '' for line in cert.split('\n'):