Skip to content

Commit 79ad584

Browse files
update MapType in _types
1 parent 9efd253 commit 79ad584

File tree

1 file changed

+11
-14
lines changed

1 file changed

+11
-14
lines changed

aiochclient/_types.pyx

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,12 @@ RE_MAP = re.compile(r"^Map\((.*)\)$")
6666
RE_REPLACE_QUOTE = re.compile(r"(?<!\\)'")
6767

6868

69+
cdef str remove_single_quotes(str string):
70+
if string[0] == string[-1] == "'":
71+
return string[1:-1]
72+
return string
73+
74+
6975
cdef str decode(char* val):
7076
"""
7177
Converting bytes from clickhouse with
@@ -168,7 +174,7 @@ cdef class StrType:
168174

169175
cdef str _convert(self, str string):
170176
if self.container:
171-
return string.strip("'")
177+
return remove_single_quotes(string)
172178
return string
173179

174180
cpdef str p_type(self, str string):
@@ -528,7 +534,7 @@ cdef class TupleType:
528534
return self._convert(value.decode())
529535

530536

531-
cdef class MapType:
537+
cdef class MapType:
532538

533539
cdef:
534540
str name
@@ -544,19 +550,10 @@ cdef class MapType:
544550
self.key_type = what_py_type(tps[:comma_index], container=True)
545551
self.value_type = what_py_type(tps[comma_index + 1:], container=True)
546552

547-
cdef dict _convert(self, string):
548-
if isinstance(string, str):
549-
string = RE_REPLACE_QUOTE.sub('"', string)
550-
string = string.replace('\\', '\\\\')
551-
dict_from_string = json.loads(string)
552-
else:
553-
dict_from_string = string
553+
cdef dict _convert(self, str string):
554+
key, value = string[1:-1].split(':', 1)
554555
return {
555-
self.key_type.p_type(
556-
decode(key.encode()) if isinstance(key, str) else key
557-
): self.value_type.p_type(
558-
decode(val.encode()) if isinstance(val, str) else val
559-
) for key, val in dict_from_string.items()
556+
self.key_type.p_type(decode(key.encode())): self.value_type.p_type(decode(value.encode()))
560557
}
561558

562559
cpdef dict p_type(self, string):

0 commit comments

Comments
 (0)