def _do_request(method, url, headers, data=None, query_params=None, timeout=<NUM_LIT:20>):
if query_params:<EOL><INDENT>url += '<STR_LIT:?>' + urlencode(query_params).replace('<STR_LIT:+>', '<STR_LIT>')<EOL><DEDENT>if isinstance(data, dict):<EOL><INDENT>data_bytes = {}<EOL>for key in data:<EOL><INDENT>data_bytes[key.encode('<STR_LIT:utf-8>')] = data[key].encode('<STR_LIT:utf-8>')<EOL><DEDENT>data = urlencode(data_bytes)<EOL>headers['<STR_LIT:Content-Type>'] = '<STR_LIT>'<EOL><DEDENT>if isinstance(data, str_cls):<EOL><INDENT>raise TypeError('<STR_LIT>')<EOL><DEDENT>try:<EOL><INDENT>tempfd, tempf_path = tempfile.mkstemp('<STR_LIT>')<EOL>os.write(tempfd, data or b'<STR_LIT>')<EOL>os.close(tempfd)<EOL>if sys.platform == '<STR_LIT:win32>':<EOL><INDENT>powershell_exe = os.path.join('<STR_LIT>')<EOL>code = "<STR_LIT>"<EOL>code += "<STR_LIT>"<EOL>for key in headers:<EOL><INDENT>code += "<STR_LIT>" % (key, headers[key])<EOL><DEDENT>code += "<STR_LIT>" % (url, method, tempf_path)<EOL>code += "<STR_LIT>"<EOL>code += "<STR_LIT>"<EOL>stdout, stderr = _execute([powershell_exe, '<STR_LIT>', code], os.getcwd())<EOL>if stdout[-<NUM_LIT:2>:] == b'<STR_LIT:\r\n>' and b'<STR_LIT>' in stdout:<EOL><INDENT>stdout = stdout[<NUM_LIT:0>:-<NUM_LIT:2>]<EOL>parts = stdout.split(b'<STR_LIT>', <NUM_LIT:1>)<EOL>if len(parts) == <NUM_LIT:2>:<EOL><INDENT>stdout = parts[<NUM_LIT:0>] + b'<STR_LIT>' + codecs.decode(parts[<NUM_LIT:1>].replace(b'<STR_LIT:->', b'<STR_LIT>'), '<STR_LIT>')<EOL><DEDENT><DEDENT><DEDENT>else:<EOL><INDENT>args = [<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>method,<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>', '<STR_LIT>'<EOL>]<EOL>for key in headers:<EOL><INDENT>args.append('<STR_LIT>')<EOL>args.append("<STR_LIT>" % (key, headers[key]))<EOL><DEDENT>args.append('<STR_LIT>')<EOL>args.append('<STR_LIT>' % tempf_path)<EOL>args.append(url)<EOL>stdout, stderr = _execute(args, os.getcwd())<EOL><DEDENT><DEDENT>finally:<EOL><INDENT>if tempf_path and os.path.exists(tempf_path):<EOL><INDENT>os.remove(tempf_path)<EOL><DEDENT><DEDENT>if len(stderr) > <NUM_LIT:0>:<EOL><INDENT>raise URLError("<STR_LIT>" % (method, url, stderr))<EOL><DEDENT>parts = stdout.split(b'<STR_LIT>', <NUM_LIT:1>)<EOL>if len(parts) != <NUM_LIT:2>:<EOL><INDENT>raise URLError("<STR_LIT>" % (method, url, stdout))<EOL><DEDENT>header_block, body = parts<EOL>content_type_header = None<EOL>content_len_header = None<EOL>for hline in header_block.decode('<STR_LIT>').splitlines():<EOL><INDENT>hline_parts = hline.split('<STR_LIT::>', <NUM_LIT:1>)<EOL>if len(hline_parts) != <NUM_LIT:2>:<EOL><INDENT>continue<EOL><DEDENT>name, val = hline_parts<EOL>name = name.strip().lower()<EOL>val = val.strip()<EOL>if name == '<STR_LIT>':<EOL><INDENT>content_type_header = val<EOL><DEDENT>if name == '<STR_LIT>':<EOL><INDENT>content_len_header = val<EOL><DEDENT><DEDENT>if content_type_header is None and content_len_header != '<STR_LIT:0>':<EOL><INDENT>raise URLError("<STR_LIT>" % (method, url, stdout))<EOL><DEDENT>if content_type_header is None:<EOL><INDENT>content_type = '<STR_LIT>'<EOL>encoding = '<STR_LIT:utf-8>'<EOL><DEDENT>else:<EOL><INDENT>content_type, params = cgi.parse_header(content_type_header)<EOL>encoding = params.get('<STR_LIT>')<EOL><DEDENT>return (content_type, encoding, body)<EOL>
Performs an HTTP request

:param method:
    A unicode string of 'POST' or 'PUT'

:param url;
    A unicode string of the URL to request

:param headers:
    A dict of unicode strings, where keys are header names and values are
    the header values.

:param data:
    A dict of unicode strings (to be encoded as
    application/x-www-form-urlencoded), or a byte string of data.

:param query_params:
    A dict of unicode keys and values to pass as query params

:param timeout:
    An integer number of seconds to use as the timeout

:return:
    A 3-element tuple:
     - 0: A unicode string of the response content-type
     - 1: A unicode string of the response encoding, or None
     - 2: A byte string of the response body