Skip to content

Commit

Permalink
cffi: simplified code
Browse files Browse the repository at this point in the history
  • Loading branch information
saghul committed Jan 17, 2019
1 parent a2f25a6 commit ecd55e3
Showing 1 changed file with 10 additions and 14 deletions.
24 changes: 10 additions & 14 deletions pycares/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,13 +260,10 @@ def parse_result(query_type, abuf, alen):
status = parse_status
else:
result = []
srv_reply_ptr = _ffi.new("struct ares_srv_reply **")
srv_reply_ptr[0] = srv_reply[0]
while True:
if srv_reply_ptr[0] == _ffi.NULL:
break
result.append(ares_query_srv_result(srv_reply_ptr[0]))
srv_reply_ptr[0] = srv_reply_ptr[0].next
srv_reply_ptr = srv_reply[0]
while srv_reply_ptr != _ffi.NULL:
result.append(ares_query_srv_result(srv_reply_ptr))
srv_reply_ptr = srv_reply_ptr.next
_lib.ares_free_data(srv_reply[0])
status = None
elif query_type == _lib.T_TXT:
Expand All @@ -277,22 +274,21 @@ def parse_result(query_type, abuf, alen):
status = parse_status
else:
result = []
txt_reply_ptr = _ffi.new("struct ares_txt_ext **")
txt_reply_ptr[0] = txt_reply[0]
txt_reply_ptr = txt_reply[0]
tmp_obj = None
while True:
if txt_reply_ptr[0] == _ffi.NULL:
if txt_reply_ptr == _ffi.NULL:
if tmp_obj is not None:
result.append(tmp_obj)
break
if txt_reply_ptr[0].record_start == 1:
if txt_reply_ptr.record_start == 1:
if tmp_obj is not None:
result.append(tmp_obj)
tmp_obj = ares_query_txt_result(txt_reply_ptr[0])
tmp_obj = ares_query_txt_result(txt_reply_ptr)
else:
new_chunk = ares_query_txt_result(txt_reply_ptr[0])
new_chunk = ares_query_txt_result(txt_reply_ptr)
tmp_obj.text += new_chunk.text
txt_reply_ptr[0] = txt_reply_ptr[0].next
txt_reply_ptr = txt_reply_ptr.next
_lib.ares_free_data(txt_reply[0])
status = None
else:
Expand Down

0 comments on commit ecd55e3

Please sign in to comment.