def _request(self, url, method='<STR_LIT:GET>', params=None):
self.connected = True<EOL>retry_counter = <NUM_LIT:0><EOL>method = method.lower()<EOL>func = getattr(self.client, method)<EOL>params, _ = _transparent_params(params)<EOL>def _send(retry_counter):<EOL><INDENT>requests_args = {}<EOL>for k, v in self.client_args.items():<EOL><INDENT>if k in ('<STR_LIT>', '<STR_LIT>', '<STR_LIT>'):<EOL><INDENT>requests_args[k] = v<EOL><DEDENT><DEDENT>while self.connected:<EOL><INDENT>try:<EOL><INDENT>if method == '<STR_LIT>':<EOL><INDENT>requests_args['<STR_LIT>'] = params<EOL><DEDENT>else:<EOL><INDENT>requests_args['<STR_LIT:data>'] = params<EOL><DEDENT>response = func(url, **requests_args)<EOL><DEDENT>except requests.exceptions.Timeout:<EOL><INDENT>self.on_timeout()<EOL><DEDENT>else:<EOL><INDENT>if response.status_code != <NUM_LIT:200>:<EOL><INDENT>self.on_error(response.status_code, response.content)<EOL><DEDENT>if self.retry_count and(self.retry_count - retry_counter) > <NUM_LIT:0>:<EOL><INDENT>time.sleep(self.retry_in)<EOL>retry_counter += <NUM_LIT:1><EOL>_send(retry_counter)<EOL><DEDENT>return response<EOL><DEDENT><DEDENT><DEDENT>while self.connected:<EOL><INDENT>response = _send(retry_counter)<EOL>for line in response.iter_lines(self.chunk_size):<EOL><INDENT>if not self.connected:<EOL><INDENT>break<EOL><DEDENT>if line:<EOL><INDENT>try:<EOL><INDENT>if is_py3:<EOL><INDENT>line = line.decode('<STR_LIT:utf-8>')<EOL><DEDENT>data = json.loads(line)<EOL><DEDENT>except ValueError:  <EOL><INDENT>self.on_error(response.status_code,<EOL>'<STR_LIT>')<EOL><DEDENT>else:<EOL><INDENT>if self.on_success(data):  <EOL><INDENT>for message_type in self.handlers:<EOL><INDENT>if message_type in data:<EOL><INDENT>handler = getattr(self,<EOL>'<STR_LIT>' + message_type,<EOL>None)<EOL>if handlerand callable(handler)and not handler(data.get(message_type)):<EOL><INDENT>break<EOL><DEDENT><DEDENT><DEDENT><DEDENT><DEDENT><DEDENT><DEDENT><DEDENT>response.close()<EOL>
Internal stream request handling