@@ -21,14 +21,16 @@ def __init__(self, index_row, space):
21
21
self .iid = index_row [1 ]
22
22
self .name = index_row [2 ]
23
23
if isinstance (self .name , bytes ):
24
- self .name = self .name .decode ()
24
+ self .name = self .name .decode (encoding = 'utf-8' )
25
25
self .index = index_row [3 ]
26
26
self .unique = index_row [4 ]
27
27
self .parts = []
28
28
if isinstance (index_row [5 ], (list , tuple )):
29
29
for val in index_row [5 ]:
30
30
if isinstance (val , dict ):
31
- self .parts .append ((val ['field' ], val ['type' ]))
31
+ val_field = val .get ('field' , val .get (b'field' ))
32
+ val_type = val .get ('type' , val .get (b'type' ))
33
+ self .parts .append ((val_field , val_type ))
32
34
else :
33
35
self .parts .append ((val [0 ], val [1 ]))
34
36
else :
@@ -54,14 +56,24 @@ def __init__(self, space_row, schema):
54
56
self .arity = space_row [1 ]
55
57
self .name = space_row [2 ]
56
58
if isinstance (self .name , bytes ):
57
- self .name = self .name .decode ()
59
+ self .name = self .name .decode (encoding = 'utf-8' )
58
60
self .indexes = {}
59
61
self .schema = schema
60
62
self .schema [self .sid ] = self
61
63
if self .name :
62
64
self .schema [self .name ] = self
63
65
self .format = dict ()
64
- for part_id , part in enumerate (space_row [6 ]):
66
+ for part_id , raw_part in enumerate (space_row [6 ]):
67
+ # Convert keys and values from bytes to str.
68
+ # It is necessary for an encoding=None connection.
69
+ part = dict ()
70
+ for key , val in raw_part .items ():
71
+ if isinstance (key , bytes ):
72
+ key = key .decode (encoding = 'utf-8' )
73
+ if isinstance (val , bytes ):
74
+ val = val .decode (encoding = 'utf-8' )
75
+ part [key ] = val
76
+
65
77
part ['id' ] = part_id
66
78
self .format [part ['name' ]] = part
67
79
self .format [part_id ] = part
@@ -78,6 +90,9 @@ def __init__(self, con):
78
90
self .con = con
79
91
80
92
def get_space (self , space ):
93
+ if isinstance (space , bytes ):
94
+ space = space .decode (encoding = 'utf-8' )
95
+
81
96
try :
82
97
return self .schema [space ]
83
98
except KeyError :
@@ -135,6 +150,11 @@ def fetch_space_all(self):
135
150
SchemaSpace (row , self .schema )
136
151
137
152
def get_index (self , space , index ):
153
+ if isinstance (space , bytes ):
154
+ space = space .decode (encoding = 'utf-8' )
155
+ if isinstance (index , bytes ):
156
+ index = index .decode (encoding = 'utf-8' )
157
+
138
158
_space = self .get_space (space )
139
159
try :
140
160
return _space .indexes [index ]
@@ -203,6 +223,11 @@ def fetch_index_from(self, space, index):
203
223
return index_row
204
224
205
225
def get_field (self , space , field ):
226
+ if isinstance (space , bytes ):
227
+ space = space .decode (encoding = 'utf-8' )
228
+ if isinstance (field , bytes ):
229
+ field = field .decode (encoding = 'utf-8' )
230
+
206
231
_space = self .get_space (space )
207
232
try :
208
233
return _space .format [field ]
0 commit comments