(self, fields, files)
return Request(self.url, body, headers)
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.
Encode fields and files for posting to an HTTP server.
Encode fields and files for posting to an HTTP server .
def encode_request(self, fields, files):
        """
        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.
        """
        # Adapted from packaging, which in turn was adapted from
        # http://code.activestate.com/recipes/146306

        parts = []
        boundary = self.boundary
        for k, values in fields:
            if not isinstance(values, (list, tuple)):
                values = [values]

            for v in values:
                parts.extend((
                    b'--' + boundary,
                    ('Content-Disposition: form-data; name="%s"' %
                     k).encode('utf-8'),
                    b'',
                    v.encode('utf-8')))
        for key, filename, value in files:
            parts.extend((
                b'--' + boundary,
                ('Content-Disposition: form-data; name="%s"; filename="%s"' %
                 (key, filename)).encode('utf-8'),
                b'',
                value))

        parts.extend((b'--' + boundary + b'--', b''))

        body = b'\r\n'.join(parts)
        ct = b'multipart/form-data; boundary=' + boundary
        headers = {
            'Content-type': ct,
            'Content-length': str(len(body))
        }
        return Request(self.url, body, headers)
def encode_request ( self , fields , files ) : # Adapted from packaging, which in turn was adapted from # http://code.activestate.com/recipes/146306 parts = [ ] boundary = self . boundary for k , values in fields : if not isinstance ( values , ( list , tuple ) ) : values = [ values ] for v in values : parts . extend ( ( b'--' + boundary , ( 'Content-Disposition: form-data; name="%s"' % k ) . encode ( 'utf-8' ) , b'' , v . encode ( 'utf-8' ) ) ) for key , filename , value in files : parts . extend ( ( b'--' + boundary , ( 'Content-Disposition: form-data; name="%s"; filename="%s"' % ( key , filename ) ) . encode ( 'utf-8' ) , b'' , value ) ) parts . extend ( ( b'--' + boundary + b'--' , b'' ) ) body = b'\r\n' . join ( parts ) ct = b'multipart/form-data; boundary=' + boundary headers = { 'Content-type' : ct , 'Content-length' : str ( len ( body ) ) } return Request ( self . url , body , headers )