Commit b05992e1 authored by Albertas Agejevas's avatar Albertas Agejevas

More trivial Py3 fixes.

parent c19bae1d
...@@ -409,7 +409,7 @@ class ClientStorage(object): ...@@ -409,7 +409,7 @@ class ClientStorage(object):
if blob_cache_size is not None: if blob_cache_size is not None:
assert blob_cache_size_check < 100 assert blob_cache_size_check < 100
self._blob_cache_size_check = ( self._blob_cache_size_check = (
blob_cache_size * blob_cache_size_check / 100) blob_cache_size * blob_cache_size_check // 100)
self._check_blob_size() self._check_blob_size()
self._rpc_mgr = self.ConnectionManagerClass(addr, self, self._rpc_mgr = self.ConnectionManagerClass(addr, self,
......
...@@ -1560,7 +1560,9 @@ class ZEOStorage308Adapter: ...@@ -1560,7 +1560,9 @@ class ZEOStorage308Adapter:
return getattr(self.storage, name) return getattr(self.storage, name)
def _addr_label(addr): def _addr_label(addr):
if isinstance(addr, type("")): if isinstance(addr, six.binary_type):
return addr.decode('ascii')
if isinstance(addr, six.string_types):
return addr return addr
else: else:
host, port = addr host, port = addr
......
...@@ -1166,7 +1166,7 @@ class MSTThread(threading.Thread): ...@@ -1166,7 +1166,7 @@ class MSTThread(threading.Thread):
# Begin a transaction # Begin a transaction
t = Transaction() t = Transaction()
for c in clients: for c in clients:
#print "%s.%s.%s begin\n" % (tname, c.__name, i), #print("%s.%s.%s begin" % (tname, c.__name, i))
c.tpc_begin(t) c.tpc_begin(t)
for j in range(testcase.nobj): for j in range(testcase.nobj):
...@@ -1175,20 +1175,20 @@ class MSTThread(threading.Thread): ...@@ -1175,20 +1175,20 @@ class MSTThread(threading.Thread):
oid = c.new_oid() oid = c.new_oid()
c.__oids.append(oid) c.__oids.append(oid)
data = MinPO("%s.%s.t%d.o%d" % (tname, c.__name, i, j)) data = MinPO("%s.%s.t%d.o%d" % (tname, c.__name, i, j))
#print data.value #print(data.value)
data = zodb_pickle(data) data = zodb_pickle(data)
s = c.store(oid, ZERO, data, '', t) s = c.store(oid, ZERO, data, '', t)
c.__serials.update(handle_all_serials(oid, s)) c.__serials.update(handle_all_serials(oid, s))
# Vote on all servers and handle serials # Vote on all servers and handle serials
for c in clients: for c in clients:
#print "%s.%s.%s vote\n" % (tname, c.__name, i), #print("%s.%s.%s vote" % (tname, c.__name, i))
s = c.tpc_vote(t) s = c.tpc_vote(t)
c.__serials.update(handle_all_serials(None, s)) c.__serials.update(handle_all_serials(None, s))
# Finish on all servers # Finish on all servers
for c in clients: for c in clients:
#print "%s.%s.%s finish\n" % (tname, c.__name, i), #print("%s.%s.%s finish\n" % (tname, c.__name, i))
c.tpc_finish(t) c.tpc_finish(t)
for c in clients: for c in clients:
......
...@@ -194,7 +194,7 @@ class LargeUpdatesThread(FailableThread): ...@@ -194,7 +194,7 @@ class LargeUpdatesThread(FailableThread):
tree = cn.root()["tree"] tree = cn.root()["tree"]
break break
except (ConflictError, KeyError): except (ConflictError, KeyError):
# print "%d getting tree abort" % self.threadnum # print("%d getting tree abort" % self.threadnum)
transaction.abort() transaction.abort()
keys_added = {} # set of keys we commit keys_added = {} # set of keys we commit
...@@ -215,11 +215,11 @@ class LargeUpdatesThread(FailableThread): ...@@ -215,11 +215,11 @@ class LargeUpdatesThread(FailableThread):
try: try:
tree[key] = self.threadnum tree[key] = self.threadnum
except (ReadConflictError, ConflictError) as msg: except (ReadConflictError, ConflictError) as msg:
# print "%d setting key %s" % (self.threadnum, msg) # print("%d setting key %s" % (self.threadnum, msg))
transaction.abort() transaction.abort()
break break
else: else:
# print "%d set #%d" % (self.threadnum, len(keys)) # print("%d set #%d" % (self.threadnum, len(keys)))
transaction.get().note("keys %s" % ", ".join(map(str, keys))) transaction.get().note("keys %s" % ", ".join(map(str, keys)))
try: try:
transaction.commit() transaction.commit()
...@@ -227,7 +227,7 @@ class LargeUpdatesThread(FailableThread): ...@@ -227,7 +227,7 @@ class LargeUpdatesThread(FailableThread):
if self.sleep: if self.sleep:
time.sleep(self.sleep) time.sleep(self.sleep)
except ConflictError as msg: except ConflictError as msg:
# print "%d commit %s" % (self.threadnum, msg) # print("%d commit %s" % (self.threadnum, msg))
transaction.abort() transaction.abort()
continue continue
for k in keys: for k in keys:
......
...@@ -85,7 +85,7 @@ The simplest client configuration specified a server address: ...@@ -85,7 +85,7 @@ The simplest client configuration specified a server address:
>>> storage._blob_cache_size >>> storage._blob_cache_size
1048576000 1048576000
>>> print storage._blob_cache_size_check >>> print(storage._blob_cache_size_check)
104857600 104857600
>>> storage.close() >>> storage.close()
...@@ -82,7 +82,7 @@ Now, let's verify our assertions above: ...@@ -82,7 +82,7 @@ Now, let's verify our assertions above:
- Publishes a stale-cache event. - Publishes a stale-cache event.
>>> for e in events: >>> for e in events:
... print e ... print(e)
(3, '', 'StaleCache') (3, '', 'StaleCache')
Note that the length of the cache when the event handler was Note that the length of the cache when the event handler was
...@@ -105,7 +105,7 @@ Now, let's verify our assertions above: ...@@ -105,7 +105,7 @@ Now, let's verify our assertions above:
- Logs a CRITICAL message. - Logs a CRITICAL message.
>>> print handler >>> print(handler)
ZEO.ClientStorage CRITICAL ZEO.ClientStorage CRITICAL
test dropping stale cache test dropping stale cache
...@@ -149,14 +149,14 @@ in the database, which is why we get 1, rather than 0 objects in the cache.) ...@@ -149,14 +149,14 @@ in the database, which is why we get 1, rather than 0 objects in the cache.)
- Publishes a stake-cache event. - Publishes a stake-cache event.
>>> for e in events: >>> for e in events:
... print e ... print(e)
(2, '', 'StaleCache') (2, '', 'StaleCache')
>>> del events[:] >>> del events[:]
- Logs a CRITICAL message. - Logs a CRITICAL message.
>>> print handler >>> print(handler)
ZEO.ClientStorage CRITICAL ZEO.ClientStorage CRITICAL
test dropping stale cache test dropping stale cache
...@@ -199,10 +199,10 @@ drop_cache_rather_verify option: ...@@ -199,10 +199,10 @@ drop_cache_rather_verify option:
>>> wait_connected(db.storage) >>> wait_connected(db.storage)
>>> for e in events: >>> for e in events:
... print e ... print(e)
(4, '', 'StaleCache') (4, '', 'StaleCache')
>>> print handler >>> print(handler)
<BLANKLINE> <BLANKLINE>
>>> len(db.storage._cache) >>> len(db.storage._cache)
......
...@@ -52,15 +52,15 @@ stub that implements the client invalidation calls: ...@@ -52,15 +52,15 @@ stub that implements the client invalidation calls:
... def __init__(self, name): ... def __init__(self, name):
... self.name = name ... self.name = name
... def invalidateTransaction(self, tid, invalidated): ... def invalidateTransaction(self, tid, invalidated):
... print 'invalidateTransaction', tid, self.name ... print('invalidateTransaction', tid, self.name)
... print invalidated ... print(invalidated)
>>> class Connection: >>> class Connection:
... def __init__(self, mgr, obj): ... def __init__(self, mgr, obj):
... self.mgr = mgr ... self.mgr = mgr
... self.obj = obj ... self.obj = obj
... def should_close(self): ... def should_close(self):
... print 'closed', self.obj.name ... print('closed', self.obj.name)
... self.mgr.close_conn(self) ... self.mgr.close_conn(self)
... def poll(self): ... def poll(self):
... pass ... pass
...@@ -101,7 +101,7 @@ Now, if we call invalidate, we'll see it propigate to the client: ...@@ -101,7 +101,7 @@ Now, if we call invalidate, we'll see it propigate to the client:
The storage servers queue will reflect the invalidations: The storage servers queue will reflect the invalidations:
>>> for tid, invalidated in server.invq['t']: >>> for tid, invalidated in server.invq['t']:
... print repr(tid), invalidated ... print(repr(tid), invalidated)
'trans3' ['ob1', 'ob2'] 'trans3' ['ob1', 'ob2']
'trans2' ['ob1', 'ob2'] 'trans2' ['ob1', 'ob2']
'trans1' ['ob0', 'ob1'] 'trans1' ['ob0', 'ob1']
...@@ -119,6 +119,6 @@ The connections will then reopen and revalidate their caches. ...@@ -119,6 +119,6 @@ The connections will then reopen and revalidate their caches.
The servers's invalidation queue will get reset The servers's invalidation queue will get reset
>>> for tid, invalidated in server.invq['t']: >>> for tid, invalidated in server.invq['t']:
... print repr(tid), invalidated ... print(repr(tid), invalidated)
'trans1' ['ob0', 'ob1'] 'trans1' ['ob0', 'ob1']
'trans0' ['ob0'] 'trans0' ['ob0']
...@@ -17,7 +17,7 @@ The actual tests are in ConnectionTests.py; this file provides the ...@@ -17,7 +17,7 @@ The actual tests are in ConnectionTests.py; this file provides the
platform-dependent scaffolding. platform-dependent scaffolding.
""" """
from __future__ import with_statement from __future__ import with_statement, print_function
from ZEO.tests import ConnectionTests, InvalidationTests from ZEO.tests import ConnectionTests, InvalidationTests
from zope.testing import setupstack from zope.testing import setupstack
...@@ -222,16 +222,16 @@ This tests tries to provoke this bug by: ...@@ -222,16 +222,16 @@ This tests tries to provoke this bug by:
... conn = db.open() ... conn = db.open()
... for i in range(1000): ... for i in range(1000):
... if conn.root()[i].value != conn2.root()[i].value: ... if conn.root()[i].value != conn2.root()[i].value:
... print 'bad', c, i, conn.root()[i].value, ... print('bad', c, i, conn.root()[i].value, end=" ")
... print conn2.root()[i].value ... print(conn2.root()[i].value)
... bad = True ... bad = True
... print 'client debug log with lock held' ... print('client debug log with lock held')
... while handler.records: ... while handler.records:
... record = handler.records.pop(0) ... record = handler.records.pop(0)
... print record.name, record.levelname, ... print(record.name, record.levelname, end=' ')
... print handler.format(record) ... print(handler.format(record))
... if bad: ... if bad:
... print open('server-%s.log' % addr[1]).read() ... print(open('server-%s.log' % addr[1]).read())
... #else: ... #else:
... # logging.getLogger('ZEO').debug('GOOD %s' % c) ... # logging.getLogger('ZEO').debug('GOOD %s' % c)
... db.close() ... db.close()
...@@ -245,8 +245,8 @@ This tests tries to provoke this bug by: ...@@ -245,8 +245,8 @@ This tests tries to provoke this bug by:
>>> for record in handler.records: >>> for record in handler.records:
... if record.levelno < logging.ERROR: ... if record.levelno < logging.ERROR:
... continue ... continue
... print record.name, record.levelname ... print(record.name, record.levelname)
... print handler.format(record) ... print(handler.format(record))
>>> handler.uninstall() >>> handler.uninstall()
......
...@@ -64,7 +64,7 @@ underlying storage. ...@@ -64,7 +64,7 @@ underlying storage.
>>> next = None >>> next = None
>>> while 1: >>> while 1:
... oid, serial, data, next = zeo.record_iternext(next) ... oid, serial, data, next = zeo.record_iternext(next)
... print oid ... print(oid)
... if next is None: ... if next is None:
... break ... break
1 1
...@@ -114,7 +114,7 @@ Now we'll have our way with it's private _server attr: ...@@ -114,7 +114,7 @@ Now we'll have our way with it's private _server attr:
>>> next = None >>> next = None
>>> while 1: >>> while 1:
... oid, serial, data, next = client.record_iternext(next) ... oid, serial, data, next = client.record_iternext(next)
... print oid ... print(oid)
... if next is None: ... if next is None:
... break ... break
1 1
...@@ -143,7 +143,7 @@ stuff. I'd rather do a lame test than a really lame test, so here goes. ...@@ -143,7 +143,7 @@ stuff. I'd rather do a lame test than a really lame test, so here goes.
>>> next = None >>> next = None
>>> while 1: >>> while 1:
... oid, serial, data, next = stub.record_iternext(next) ... oid, serial, data, next = stub.record_iternext(next)
... print oid ... print(oid)
... if next is None: ... if next is None:
... break ... break
1 1
......
...@@ -9,23 +9,27 @@ Storage Names ...@@ -9,23 +9,27 @@ Storage Names
It is an error not to specify any storages: It is an error not to specify any storages:
>>> import StringIO, sys, ZEO.runzeo >>> import sys, ZEO.runzeo
>>> try:
... from StringIO import StringIO
... except ImportError:
... from io import StringIO
>>> stderr = sys.stderr >>> stderr = sys.stderr
>>> open('config', 'w').write(""" >>> r = open('config', 'w').write("""
... <zeo> ... <zeo>
... address 8100 ... address 8100
... </zeo> ... </zeo>
... """) ... """)
>>> sys.stderr = StringIO.StringIO() >>> sys.stderr = StringIO()
>>> options = ZEO.runzeo.ZEOOptions() >>> options = ZEO.runzeo.ZEOOptions()
>>> options.realize('-C config'.split()) >>> options.realize('-C config'.split())
Traceback (most recent call last): Traceback (most recent call last):
... ...
SystemExit: 2 SystemExit: 2
>>> print sys.stderr.getvalue() # doctest: +ELLIPSIS +NORMALIZE_WHITESPACE >>> print(sys.stderr.getvalue()) # doctest: +ELLIPSIS +NORMALIZE_WHITESPACE
Error: not enough values for section type 'zodb.storage'; Error: not enough values for section type 'zodb.storage';
0 found, 1 required 0 found, 1 required
... ...
...@@ -33,7 +37,7 @@ It is an error not to specify any storages: ...@@ -33,7 +37,7 @@ It is an error not to specify any storages:
But we can specify a storage without a name: But we can specify a storage without a name:
>>> open('config', 'w').write(""" >>> r = open('config', 'w').write("""
... <zeo> ... <zeo>
... address 8100 ... address 8100
... </zeo> ... </zeo>
...@@ -47,8 +51,8 @@ But we can specify a storage without a name: ...@@ -47,8 +51,8 @@ But we can specify a storage without a name:
We can't have multiple unnamed storages: We can't have multiple unnamed storages:
>>> sys.stderr = StringIO.StringIO() >>> sys.stderr = StringIO()
>>> open('config', 'w').write(""" >>> r = open('config', 'w').write("""
... <zeo> ... <zeo>
... address 8100 ... address 8100
... </zeo> ... </zeo>
...@@ -63,14 +67,14 @@ We can't have multiple unnamed storages: ...@@ -63,14 +67,14 @@ We can't have multiple unnamed storages:
... ...
SystemExit: 2 SystemExit: 2
>>> print sys.stderr.getvalue() # doctest: +ELLIPSIS +NORMALIZE_WHITESPACE >>> print(sys.stderr.getvalue()) # doctest: +ELLIPSIS +NORMALIZE_WHITESPACE
Error: No more than one storage may be unnamed. Error: No more than one storage may be unnamed.
... ...
Or an unnamed storage and one named '1': Or an unnamed storage and one named '1':
>>> sys.stderr = StringIO.StringIO() >>> sys.stderr = StringIO()
>>> open('config', 'w').write(""" >>> r = open('config', 'w').write("""
... <zeo> ... <zeo>
... address 8100 ... address 8100
... </zeo> ... </zeo>
...@@ -85,13 +89,13 @@ Or an unnamed storage and one named '1': ...@@ -85,13 +89,13 @@ Or an unnamed storage and one named '1':
... ...
SystemExit: 2 SystemExit: 2
>>> print sys.stderr.getvalue() # doctest: +ELLIPSIS +NORMALIZE_WHITESPACE >>> print(sys.stderr.getvalue()) # doctest: +ELLIPSIS +NORMALIZE_WHITESPACE
Error: Can't have an unnamed storage and a storage named 1. Error: Can't have an unnamed storage and a storage named 1.
... ...
But we can have multiple storages: But we can have multiple storages:
>>> open('config', 'w').write(""" >>> r = open('config', 'w').write("""
... <zeo> ... <zeo>
... address 8100 ... address 8100
... </zeo> ... </zeo>
...@@ -107,8 +111,8 @@ But we can have multiple storages: ...@@ -107,8 +111,8 @@ But we can have multiple storages:
As long as the names are unique: As long as the names are unique:
>>> sys.stderr = StringIO.StringIO() >>> sys.stderr = StringIO()
>>> open('config', 'w').write(""" >>> r = open('config', 'w').write("""
... <zeo> ... <zeo>
... address 8100 ... address 8100
... </zeo> ... </zeo>
...@@ -123,7 +127,7 @@ As long as the names are unique: ...@@ -123,7 +127,7 @@ As long as the names are unique:
... ...
SystemExit: 2 SystemExit: 2
>>> print sys.stderr.getvalue() # doctest: +ELLIPSIS +NORMALIZE_WHITESPACE >>> print(sys.stderr.getvalue()) # doctest: +ELLIPSIS +NORMALIZE_WHITESPACE
Error: section names must not be re-used within the same container:'1' Error: section names must not be re-used within the same container:'1'
... ...
......
...@@ -47,7 +47,7 @@ If we update c1, we'll eventually see the change in c2: ...@@ -47,7 +47,7 @@ If we update c1, we'll eventually see the change in c2:
>>> r1[1].v = 1000 >>> r1[1].v = 1000
>>> r1[2] = persistent.mapping.PersistentMapping() >>> r1[2] = persistent.mapping.PersistentMapping()
>>> r1[2].v = -1000 >>> r1[2].v = -1000
>>> r1[3] = ZODB.blob.Blob('x'*4111222) >>> r1[3] = ZODB.blob.Blob(b'x'*4111222)
>>> for i in range(1000, 2000): >>> for i in range(1000, 2000):
... r1[i] = persistent.mapping.PersistentMapping() ... r1[i] = persistent.mapping.PersistentMapping()
... r1[i].v = 0 ... r1[i].v = 0
...@@ -97,14 +97,14 @@ Now, let's see if we can break it. :) ...@@ -97,14 +97,14 @@ Now, let's see if we can break it. :)
>>> while time.time() - start_time < 999: >>> while time.time() - start_time < 999:
... t = tm2.begin() ... t = tm2.begin()
... if r2[1].v + r2[2].v: ... if r2[1].v + r2[2].v:
... print 'oops', r2[1], r2[2] ... print('oops', r2[1], r2[2])
... if r2[1].v == 800: ... if r2[1].v == 800:
... break # we caught up ... break # we caught up
... path = s2.fshelper.getBlobFilename(*blob_id) ... path = s2.fshelper.getBlobFilename(*blob_id)
... if os.path.exists(path): ... if os.path.exists(path):
... ZODB.blob.remove_committed(path) ... ZODB.blob.remove_committed(path)
... s2._server.sendBlob(*blob_id) ... s2._server.sendBlob(*blob_id)
... else: print 'Dang' ... else: print('Dang')
>>> threadf.join() >>> threadf.join()
...@@ -129,11 +129,11 @@ invalidated: ...@@ -129,11 +129,11 @@ invalidated:
... and ... and
... (r2[2]._p_changed is None) ... (r2[2]._p_changed is None)
... ): ... ):
... print 'Cool' ... print('Cool')
... break ... break
... time.sleep(0.01) ... time.sleep(0.01)
... else: ... else:
... print 'Dang' ... print('Dang')
Cool Cool
Cleanup: Cleanup:
......
...@@ -87,19 +87,19 @@ target: ...@@ -87,19 +87,19 @@ target:
>>> for i in range(1, 101): >>> for i in range(1, 101):
... data = conn.root()[i].open().read() ... data = conn.root()[i].open().read()
... if data != chr(i)*100: ... if data != chr(i)*100:
... print 'bad data', `chr(i)`, `data` ... print('bad data', repr(chr(i)), repr(data))
>>> wait_until("size is reduced", check, 99, onfail) >>> wait_until("size is reduced", check, 99, onfail)
>>> for i in range(1, 101): >>> for i in range(1, 101):
... data = conn.root()[i].open().read() ... data = conn.root()[i].open().read()
... if data != chr(i)*100: ... if data != chr(i)*100:
... print 'bad data', `chr(i)`, `data` ... print('bad data', repr(chr(i)), repr(data))
>>> for i in range(1, 101): >>> for i in range(1, 101):
... data = conn.root()[i].open('c').read() ... data = conn.root()[i].open('c').read()
... if data != chr(i)*100: ... if data != chr(i)*100:
... print 'bad data', `chr(i)`, `data` ... print('bad data', repr(chr(i)), repr(data))
>>> wait_until("size is reduced", check, 99, onfail) >>> wait_until("size is reduced", check, 99, onfail)
...@@ -116,11 +116,11 @@ provoke problems: ...@@ -116,11 +116,11 @@ provoke problems:
... i = random.randint(1, 100) ... i = random.randint(1, 100)
... data = conn.root()[i].open().read() ... data = conn.root()[i].open().read()
... if data != chr(i)*100: ... if data != chr(i)*100:
... print 'bad data', `chr(i)`, `data` ... print('bad data', repr(chr(i)), repr(data))
... i = random.randint(1, 100) ... i = random.randint(1, 100)
... data = conn.root()[i].open('c').read() ... data = conn.root()[i].open('c').read()
... if data != chr(i)*100: ... if data != chr(i)*100:
... print 'bad data', `chr(i)`, `data` ... print('bad data', repr(chr(i)), repr(data))
... db.close() ... db.close()
>>> threads = [threading.Thread(target=run) for i in range(10)] >>> threads = [threading.Thread(target=run) for i in range(10)]
...@@ -131,7 +131,7 @@ provoke problems: ...@@ -131,7 +131,7 @@ provoke problems:
>>> for thread in threads: >>> for thread in threads:
... thread.join(99) ... thread.join(99)
... if thread.isAlive(): ... if thread.isAlive():
... print "Can't join thread." ... print("Can't join thread.")
>>> wait_until("size is reduced", check, 99, onfail) >>> wait_until("size is reduced", check, 99, onfail)
......
...@@ -831,4 +831,4 @@ class ManagedClientConnection(Connection): ...@@ -831,4 +831,4 @@ class ManagedClientConnection(Connection):
def send_reply(self, msgid, ret): def send_reply(self, msgid, ret):
# Whimper. Used to send heartbeat # Whimper. Used to send heartbeat
assert msgid == -1 and ret is None assert msgid == -1 and ret is None
self.message_output('(J\xff\xff\xff\xffK\x00U\x06.replyNt.') self.message_output(b'(J\xff\xff\xff\xffK\x00U\x06.replyNt.')
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment