def encode_request(self, fields, files):
<EOL>parts = []<EOL>boundary = self.boundary<EOL>for k, values in fields:<EOL><INDENT>if not isinstance(values, (list, tuple)):<EOL><INDENT>values = [values]<EOL><DEDENT>for v in values:<EOL><INDENT>parts.extend((<EOL>b'<STR_LIT>' + boundary,<EOL>('<STR_LIT>' %<EOL>k).encode('<STR_LIT:utf-8>'),<EOL>b'<STR_LIT>',<EOL>v.encode('<STR_LIT:utf-8>')))<EOL><DEDENT><DEDENT>for key, filename, value in files:<EOL><INDENT>parts.extend((<EOL>b'<STR_LIT>' + boundary,<EOL>('<STR_LIT>' %<EOL>(key, filename)).encode('<STR_LIT:utf-8>'),<EOL>b'<STR_LIT>',<EOL>value))<EOL><DEDENT>parts.extend((b'<STR_LIT>' + boundary + b'<STR_LIT>', b'<STR_LIT>'))<EOL>body = b'<STR_LIT:\r\n>'.join(parts)<EOL>ct = b'<STR_LIT>' + boundary<EOL>headers = {<EOL>'<STR_LIT>': ct,<EOL>'<STR_LIT>': str(len(body))<EOL>}<EOL>return Request(self.url, body, headers)<EOL>
Encode fields and files for posting to an HTTP server.

:param fields: The fields to send as a list of (fieldname, value)
               tuples.
:param files: The files to send as a list of (fieldname, filename,
              file_bytes) tuple.