Skip to content

Commit dc773ca

Browse files
committed
fix for tests ok
1 parent f8d9157 commit dc773ca

File tree

4 files changed

+29
-11
lines changed

4 files changed

+29
-11
lines changed

tarantool/request.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
Request types definitions
55
'''
66

7+
import six
78
import msgpack
89
import hashlib
910

@@ -105,14 +106,17 @@ def __init__(self, conn, salt, user, password):
105106
super(RequestAuthenticate, self).__init__(conn)
106107

107108
def sha1(values):
108-
sha1 = hashlib.sha1()
109+
sha = hashlib.sha1()
109110
for i in values:
110-
sha1.update(i)
111-
return sha1.digest()
111+
sha.update(i if isinstance(i, six.binary_type) else i.encode())
112+
return sha.digest()
112113

113114
def strxor(rhs, lhs):
115+
if six.PY2:
114116
return "".join(chr(ord(x) ^ ord(y)) for x, y in zip(rhs, lhs))
115117

118+
return bytes([x ^ y for x, y in zip(rhs, lhs)])
119+
116120
hash1 = sha1((password,))
117121
hash2 = sha1((hash1,))
118122
scramble = sha1((salt, hash2))

tarantool/response.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# -*- coding: utf-8 -*-
22
# pylint: disable=C0301,W0105,W0401,W0614
33

4+
import six
45
import sys
56
import msgpack
67
import yaml
@@ -41,7 +42,11 @@ def __init__(self, conn, response):
4142
# created in the __new__(). But let it be.
4243
super(Response, self).__init__()
4344

44-
unpacker = msgpack.Unpacker(use_list=True)
45+
if six.PY2:
46+
unpacker = msgpack.Unpacker(use_list=True)
47+
else:
48+
unpacker = msgpack.Unpacker(use_list=True, encoding="utf-8")
49+
4550
unpacker.feed(response)
4651
header = unpacker.unpack()
4752

tarantool/schema.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
class SchemaIndex(object):
1515
def __init__(self, array, space):
1616
self.iid = array[1]
17-
self.name = array[2].decode()
17+
self.name = array[2]
1818
self.index = array[3]
1919
self.unique = array[4]
2020
self.parts = []
@@ -35,7 +35,7 @@ class SchemaSpace(object):
3535
def __init__(self, array, schema):
3636
self.sid = array[0]
3737
self.arity = array[1]
38-
self.name = array[2].decode()
38+
self.name = array[2]
3939
self.indexes = {}
4040
self.schema = schema
4141
self.schema[self.sid] = self

tests/suites/lib/tarantool_server.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1+
# -*- coding: utf-8 -*-
2+
13
import os
4+
import os.path
25
import errno
36
import shlex
47
import random
@@ -39,6 +42,7 @@ def __init__(self, host, port):
3942
self.port = port
4043
self.is_connected = False
4144
self.socket = None
45+
4246
def connect(self):
4347
self.socket = socket.create_connection((self.host, self.port))
4448
self.socket.setsockopt(socket.SOL_TCP, socket.TCP_NODELAY, 1)
@@ -87,7 +91,7 @@ def execute_no_reconnect(self, command):
8791
if not command:
8892
return
8993
cmd = command.replace('\n', ' ') + '\n'
90-
self.socket.sendall(cmd)
94+
self.socket.sendall(cmd.encode())
9195

9296
bufsiz = 4096
9397
res = ""
@@ -96,7 +100,7 @@ def execute_no_reconnect(self, command):
96100
buf = self.socket.recv(bufsiz)
97101
if not buf:
98102
break
99-
res = res + buf
103+
res = res + buf.decode()
100104
if (res.rfind("\n...\n") >= 0 or res.rfind("\r\n...\r\n") >= 0):
101105
break
102106

@@ -134,6 +138,7 @@ def script_dst(self):
134138
def script(self):
135139
if not hasattr(self, '_script'): self._script = None
136140
return self._script
141+
137142
@script.setter
138143
def script(self, val):
139144
if val is None:
@@ -153,6 +158,7 @@ def _admin(self):
153158
if not hasattr(self, 'admin'):
154159
self.admin = None
155160
return self.admin
161+
156162
@_admin.setter
157163
def _admin(self, port):
158164
try:
@@ -168,6 +174,7 @@ def log_des(self):
168174
if not hasattr(self, '_log_des'):
169175
self._log_des = open(self.logfile_path, 'a')
170176
return self._log_des
177+
171178
@log_des.deleter
172179
def log_des(self):
173180
if not hasattr(self, '_log_des'):
@@ -249,15 +256,17 @@ def start(self):
249256
self.wait_until_started()
250257

251258
def stop(self):
252-
self.process.terminate()
253-
self.process.wait()
259+
if self.process.poll() is None:
260+
self.process.terminate()
261+
self.process.wait()
254262

255263
def restart(self):
256264
self.stop()
257265
self.start()
258266

259267
def clean(self):
260-
shutil.rmtree(self.vardir)
268+
if os.path.isdir(self.vardir):
269+
shutil.rmtree(self.vardir)
261270

262271
def __del__(self):
263272
self.stop()

0 commit comments

Comments
 (0)