Commit 7830739a authored by Albertas Agejevas's avatar Albertas Agejevas

Trivial Py3 porting changes: binary data, print functions.

parent 114dd15d
...@@ -335,7 +335,7 @@ class ConnectionTests(CommonSetupTearDown): ...@@ -335,7 +335,7 @@ class ConnectionTests(CommonSetupTearDown):
self.shutdownServer() self.shutdownServer()
self._storage = self.openClientStorage('test', 1000, wait=0) self._storage = self.openClientStorage('test', 1000, wait=0)
self.assertRaises(ClientDisconnected, self.assertRaises(ClientDisconnected,
self._storage.load, 'fredwash', '') self._storage.load, b'fredwash', '')
self._storage.close() self._storage.close()
def checkBasicPersistence(self): def checkBasicPersistence(self):
...@@ -579,13 +579,13 @@ class ConnectionTests(CommonSetupTearDown): ...@@ -579,13 +579,13 @@ class ConnectionTests(CommonSetupTearDown):
self._storage = self.openClientStorage() self._storage = self.openClientStorage()
self._dostore() self._dostore()
self.shutdownServer() self.shutdownServer()
self.assertRaises(ClientDisconnected, self._storage.load, '\0'*8, '') self.assertRaises(ClientDisconnected, self._storage.load, b'\0'*8, '')
self.startServer() self.startServer()
# No matter how long we wait, the client won't reconnect: # No matter how long we wait, the client won't reconnect:
time.sleep(2) time.sleep(2)
self.assertRaises(ClientDisconnected, self._storage.load, '\0'*8, '') self.assertRaises(ClientDisconnected, self._storage.load, b'\0'*8, '')
class InvqTests(CommonSetupTearDown): class InvqTests(CommonSetupTearDown):
invq = 3 invq = 3
......
...@@ -127,8 +127,8 @@ class IterationTests: ...@@ -127,8 +127,8 @@ class IterationTests:
txn_info1 = six.advance_iterator(iter1) txn_info1 = six.advance_iterator(iter1)
txn_info2 = six.advance_iterator(iter2) txn_info2 = six.advance_iterator(iter2)
self.assertEquals(txn_info1.tid, txn_info2.tid) self.assertEquals(txn_info1.tid, txn_info2.tid)
self.assertRaises(StopIteration, iter1.next) self.assertRaises(StopIteration, next, iter1)
self.assertRaises(StopIteration, iter2.next) self.assertRaises(StopIteration, next, iter2)
def iterator_sane_after_reconnect(): def iterator_sane_after_reconnect():
......
...@@ -23,6 +23,7 @@ import subprocess ...@@ -23,6 +23,7 @@ import subprocess
import logging import logging
import tempfile import tempfile
import logging import logging
import six
import ZODB.tests.util import ZODB.tests.util
import zope.testing.setupstack import zope.testing.setupstack
from ZEO._compat import BytesIO from ZEO._compat import BytesIO
...@@ -358,7 +359,7 @@ def wait_until(label=None, func=None, timeout=30, onfail=None): ...@@ -358,7 +359,7 @@ def wait_until(label=None, func=None, timeout=30, onfail=None):
if label is None: if label is None:
if func is not None: if func is not None:
label = func.__name__ label = func.__name__
elif not isinstance(label, basestring) and func is None: elif not isinstance(label, six.string_types) and func is None:
func = label func = label
label = func.__name__ label = func.__name__
......
...@@ -13,7 +13,6 @@ ...@@ -13,7 +13,6 @@
############################################################################## ##############################################################################
"""Test suite for ZEO based on ZODB.tests.""" """Test suite for ZEO based on ZODB.tests."""
from __future__ import print_function from __future__ import print_function
from __future__ import print_function
from ZEO.ClientStorage import ClientStorage from ZEO.ClientStorage import ClientStorage
from ZEO.tests.forker import get_port from ZEO.tests.forker import get_port
...@@ -258,7 +257,7 @@ class GenericTests( ...@@ -258,7 +257,7 @@ class GenericTests(
try: try:
t = transaction.get() t = transaction.get()
store.tpc_begin(t) store.tpc_begin(t)
store.store(oid, revid, 'x', '', t) store.store(oid, revid, b'x', '', t)
store.tpc_vote(t) store.tpc_vote(t)
store.tpc_finish(t) store.tpc_finish(t)
except Exception as v: except Exception as v:
...@@ -625,7 +624,7 @@ class CommonBlobTests: ...@@ -625,7 +624,7 @@ class CommonBlobTests:
handle_serials handle_serials
import transaction import transaction
somedata = 'a' * 10 somedata = b'a' * 10
blob = Blob() blob = Blob()
bd_fh = blob.open('w') bd_fh = blob.open('w')
...@@ -649,7 +648,7 @@ class CommonBlobTests: ...@@ -649,7 +648,7 @@ class CommonBlobTests:
self.assert_(not os.path.exists(tfname)) self.assert_(not os.path.exists(tfname))
filename = self._storage.fshelper.getBlobFilename(oid, revid) filename = self._storage.fshelper.getBlobFilename(oid, revid)
self.assert_(os.path.exists(filename)) self.assert_(os.path.exists(filename))
self.assertEqual(somedata, open(filename).read()) self.assertEqual(somedata, open(filename, 'rb').read())
def checkStoreBlob_wrong_partition(self): def checkStoreBlob_wrong_partition(self):
os_rename = os.rename os_rename = os.rename
...@@ -667,7 +666,7 @@ class CommonBlobTests: ...@@ -667,7 +666,7 @@ class CommonBlobTests:
handle_serials handle_serials
import transaction import transaction
somedata = 'a' * 10 somedata = b'a' * 10
blob = Blob() blob = Blob()
bd_fh = blob.open('w') bd_fh = blob.open('w')
...@@ -699,7 +698,8 @@ class CommonBlobTests: ...@@ -699,7 +698,8 @@ class CommonBlobTests:
def checkTransactionBufferCleanup(self): def checkTransactionBufferCleanup(self):
oid = self._storage.new_oid() oid = self._storage.new_oid()
open('blob_file', 'w').write('I am a happy blob.') with open('blob_file', 'wb') as f:
f.write(b'I am a happy blob.')
t = transaction.Transaction() t = transaction.Transaction()
self._storage.tpc_begin(t) self._storage.tpc_begin(t)
self._storage.storeBlob( self._storage.storeBlob(
...@@ -720,7 +720,7 @@ class BlobAdaptedFileStorageTests(FullGenericTests, CommonBlobTests): ...@@ -720,7 +720,7 @@ class BlobAdaptedFileStorageTests(FullGenericTests, CommonBlobTests):
somedata_path = os.path.join(self.blob_cache_dir, 'somedata') somedata_path = os.path.join(self.blob_cache_dir, 'somedata')
somedata = open(somedata_path, 'w+b') somedata = open(somedata_path, 'w+b')
for i in range(1000000): for i in range(1000000):
somedata.write("%s\n" % i) somedata.write(("%s\n" % i).encode('ascii'))
somedata.seek(0) somedata.seek(0)
blob = Blob() blob = Blob()
...@@ -1240,10 +1240,10 @@ def runzeo_without_configfile(): ...@@ -1240,10 +1240,10 @@ def runzeo_without_configfile():
... ''' % sys.path) ... ''' % sys.path)
>>> import subprocess, re >>> import subprocess, re
>>> print re.sub('\d\d+|[:]', '', subprocess.Popen( >>> print(re.sub('\d\d+|[:]', '', subprocess.Popen(
... [sys.executable, 'runzeo', '-a:%s' % get_port(), '-ft', '--test'], ... [sys.executable, 'runzeo', '-a:%s' % get_port(), '-ft', '--test'],
... stdout=subprocess.PIPE, stderr=subprocess.STDOUT, ... stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
... ).stdout.read()), # doctest: +ELLIPSIS +NORMALIZE_WHITESPACE ... ).stdout.read())) # doctest: +ELLIPSIS +NORMALIZE_WHITESPACE
------ ------
--T INFO ZEO.runzeo () opening storage '1' using FileStorage --T INFO ZEO.runzeo () opening storage '1' using FileStorage
------ ------
...@@ -1277,7 +1277,7 @@ Invalidations could cause errors when closing client storages, ...@@ -1277,7 +1277,7 @@ Invalidations could cause errors when closing client storages,
>>> time.sleep(.01) >>> time.sleep(.01)
>>> for i in range(10): >>> for i in range(10):
... conn = ZEO.connection(addr) ... conn = ZEO.connection(addr)
... _ = conn._storage.load('\0'*8) ... _ = conn._storage.load(b'\0'*8)
... conn.close() ... conn.close()
>>> writing.clear() >>> writing.clear()
...@@ -1336,7 +1336,7 @@ constructor. ...@@ -1336,7 +1336,7 @@ constructor.
... def check_for_test_label_1(): ... def check_for_test_label_1():
... for line in open('server-%s.log' % addr[1]): ... for line in open('server-%s.log' % addr[1]):
... if 'test-label-1' in line: ... if 'test-label-1' in line:
... print line.split()[1:4] ... print(line.split()[1:4])
... return True ... return True
['INFO', 'ZEO.StorageServer', '(test-label-1'] ['INFO', 'ZEO.StorageServer', '(test-label-1']
...@@ -1356,7 +1356,7 @@ You can specify the client label via a configuration file as well: ...@@ -1356,7 +1356,7 @@ You can specify the client label via a configuration file as well:
... def check_for_test_label_2(): ... def check_for_test_label_2():
... for line in open('server-%s.log' % addr[1]): ... for line in open('server-%s.log' % addr[1]):
... if 'test-label-2' in line: ... if 'test-label-2' in line:
... print line.split()[1:4] ... print(line.split()[1:4])
... return True ... return True
['INFO', 'ZEO.StorageServer', '(test-label-2'] ['INFO', 'ZEO.StorageServer', '(test-label-2']
......
...@@ -507,7 +507,7 @@ class ConnectThread(threading.Thread): ...@@ -507,7 +507,7 @@ class ConnectThread(threading.Thread):
def _fallback_wrappers(self, wrappers, deadline): def _fallback_wrappers(self, wrappers, deadline):
# If we've got wrappers left at this point, they're fallback # If we've got wrappers left at this point, they're fallback
# connections. Try notifying them until one succeeds. # connections. Try notifying them until one succeeds.
for wrap in wrappers.keys(): for wrap in list(wrappers.keys()):
assert wrap.state == "tested" and wrap.preferred == 0 assert wrap.state == "tested" and wrap.preferred == 0
if self.mgr.is_connected(): if self.mgr.is_connected():
wrap.close() wrap.close()
......
...@@ -196,7 +196,7 @@ class SizedMessageAsyncConnection(asyncore.dispatcher): ...@@ -196,7 +196,7 @@ class SizedMessageAsyncConnection(asyncore.dispatcher):
inp = d inp = d
else: else:
inp.append(d) inp.append(d)
inp = "".join(inp) inp = b"".join(inp)
offset = 0 offset = 0
while (offset + msg_size) <= input_len: while (offset + msg_size) <= input_len:
......
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