Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions tarantool/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
from tarantool.const import (
SOCKET_TIMEOUT,
RECONNECT_MAX_ATTEMPTS,
RECONNECT_DELAY
RECONNECT_DELAY,
ENCODING_DEFAULT
)

from tarantool.error import (
Expand All @@ -24,7 +25,7 @@
)


def connect(host="localhost", port=33013, user=None, password=None):
def connect(host="localhost", port=33013, user=None, password=None, encoding=ENCODING_DEFAULT):
'''\
Create a connection to the Tarantool server.

Expand All @@ -42,7 +43,9 @@ def connect(host="localhost", port=33013, user=None, password=None):
socket_timeout=SOCKET_TIMEOUT,
reconnect_max_attempts=RECONNECT_MAX_ATTEMPTS,
reconnect_delay=RECONNECT_DELAY,
connect_now=True)
connect_now=True,
encoding=encoding)


__all__ = ['connect', 'Connection', 'Schema', 'Error', 'DatabaseError',
'NetworkError', 'NetworkWarning', 'RetryWarning', 'SchemaError']
9 changes: 7 additions & 2 deletions tarantool/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,16 @@
RETRY_MAX_ATTEMPTS,
REQUEST_TYPE_OK,
REQUEST_TYPE_ERROR,
IPROTO_GREETING_SIZE)
IPROTO_GREETING_SIZE,
ENCODING_DEFAULT)

from tarantool.error import (
NetworkError,
DatabaseError,
warn,
RetryWarning,
NetworkWarning)

from tarantool.schema import Schema
from tarantool.utils import check_key

Expand All @@ -75,7 +78,8 @@ def __init__(self, host, port,
socket_timeout=SOCKET_TIMEOUT,
reconnect_max_attempts=RECONNECT_MAX_ATTEMPTS,
reconnect_delay=RECONNECT_DELAY,
connect_now=True):
connect_now=True,
encoding=ENCODING_DEFAULT):
'''
Initialize a connection to the server.

Expand All @@ -101,6 +105,7 @@ def __init__(self, host, port,
self._socket = None
self.connected = False
self.error = True
self.encoding = encoding
if connect_now:
self.connect()

Expand Down
7 changes: 7 additions & 0 deletions tarantool/const.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# -*- coding: utf-8 -*-
# pylint: disable=C0301,W0105,W0401,W0614

import six

IPROTO_CODE = 0x00
IPROTO_SYNC = 0x01
IPROTO_SPACE_ID = 0x10
Expand Down Expand Up @@ -69,3 +71,8 @@
# Number of reattempts in case of server
# return completion_status == 1 (try again)
RETRY_MAX_ATTEMPTS = 10

if six.PY2:
ENCODING_DEFAULT = None
else:
ENCODING_DEFAULT = "utf-8"
7 changes: 3 additions & 4 deletions tarantool/response.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# -*- coding: utf-8 -*-
# pylint: disable=C0301,W0105,W0401,W0614

import six
import sys
import msgpack
import yaml
Expand Down Expand Up @@ -42,10 +41,10 @@ def __init__(self, conn, response):
# created in the __new__(). But let it be.
super(Response, self).__init__()

if six.PY2:
unpacker = msgpack.Unpacker(use_list=True)
if conn.encoding is not None:
unpacker = msgpack.Unpacker(use_list=True, encoding=conn.encoding)
else:
unpacker = msgpack.Unpacker(use_list=True, encoding="utf-8")
unpacker = msgpack.Unpacker(use_list=True)

unpacker.feed(response)
header = unpacker.unpack()
Expand Down
4 changes: 4 additions & 0 deletions tarantool/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ class SchemaIndex(object):
def __init__(self, array, space):
self.iid = array[1]
self.name = array[2]
if isinstance(self.name, bytes):
self.name = self.name.decode()
self.index = array[3]
self.unique = array[4]
self.parts = []
Expand All @@ -36,6 +38,8 @@ def __init__(self, array, schema):
self.sid = array[0]
self.arity = array[1]
self.name = array[2]
if isinstance(self.name, bytes):
self.name = self.name.decode()
self.indexes = {}
self.schema = schema
self.schema[self.sid] = self
Expand Down