third_party/blink/tools/blinkpy/common/net/file_uploader.py
def _encode_multipart_form_data(fields, files):
    """Encode form fields for multipart/form-data.

    Args:
      fields: A sequence of (name, value) elements for regular form fields.
      files: A sequence of (name, filename, value) elements for data to be
             uploaded as files.
    Returns:
      (content_type, body) ready for httplib.HTTP instance.

    Source:
      https://github.com/rietveld-codereview/rietveld/blob/1be266f92fbd6e01732e1bde10589bc408d65633/upload.py#L964
    """
    BOUNDARY = '-M-A-G-I-C---B-O-U-N-D-A-R-Y-'
    CRLF = '\r\n'
    lines = []

    for key, value in fields:
        lines.append('--' + BOUNDARY)
        lines.append('Content-Disposition: form-data; name="%s"' % key)
        lines.append('')
        if isinstance(value, unicode):
            value = value.encode('utf-8')
        lines.append(value)

    for key, filename, value in files:
        lines.append('--' + BOUNDARY)
        lines.append('Content-Disposition: form-data; name="%s"; filename="%s"'
                     % (key, filename))
        lines.append('Content-Type: %s' % get_mime_type(filename))
        lines.append('')
        if isinstance(value, unicode):
            value = value.encode('utf-8')
        lines.append(value)

    lines.append('--' + BOUNDARY + '--')
    lines.append('')
    body = CRLF.join(lines)
    content_type = 'multipart/form-data; boundary=%s' % BOUNDARY
    return content_type, body
Encode form fields for multipart/form-data.

    Args:
      fields: A sequence of (name, value) elements for regular form fields.
      files: A sequence of (name, filename, value) elements for data to be
             uploaded as files.
    Returns:
      (content_type, body) ready for httplib.HTTP instance.

    Source:
      https://github.com/rietveld-codereview/rietveld/blob/1be266f92fbd6e01732e1bde10589bc408d65633/upload.py#L964
    
Encode form fields for multipart/form-data.
Encode form fields for multipart / form - data .
def _encode_multipart_form_data(fields, files):
    BOUNDARY = '-M-A-G-I-C---B-O-U-N-D-A-R-Y-'
    CRLF = '\r\n'
    lines = []
    for key, value in fields:
        lines.append('--' + BOUNDARY)
        lines.append('Content-Disposition: form-data; name="%s"' % key)
        lines.append('')
        if isinstance(value, unicode):
            value = value.encode('utf-8')
        lines.append(value)
    for key, filename, value in files:
        lines.append('--' + BOUNDARY)
        lines.append('Content-Disposition: form-data; name="%s"; filename="%s"'
                     % (key, filename))
        lines.append('Content-Type: %s' % get_mime_type(filename))
        lines.append('')
        if isinstance(value, unicode):
            value = value.encode('utf-8')
        lines.append(value)
    lines.append('--' + BOUNDARY + '--')
    lines.append('')
    body = CRLF.join(lines)
    content_type = 'multipart/form-data; boundary=%s' % BOUNDARY
    return content_type, body
def _encode_multipart_form_data ( fields , files ) : BOUNDARY = '-M-A-G-I-C---B-O-U-N-D-A-R-Y-' CRLF = '\r\n' lines = [ ] for key , value in fields : lines . append ( '--' + BOUNDARY ) lines . append ( 'Content-Disposition: form-data; name="%s"' % key ) lines . append ( '' ) if isinstance ( value , unicode ) : value = value . encode ( 'utf-8' ) lines . append ( value ) for key , filename , value in files : lines . append ( '--' + BOUNDARY ) lines . append ( 'Content-Disposition: form-data; name="%s"; filename="%s"' % ( key , filename ) ) lines . append ( 'Content-Type: %s' % get_mime_type ( filename ) ) lines . append ( '' ) if isinstance ( value , unicode ) : value = value . encode ( 'utf-8' ) lines . append ( value ) lines . append ( '--' + BOUNDARY + '--' ) lines . append ( '' ) body = CRLF . join ( lines ) content_type = 'multipart/form-data; boundary=%s' % BOUNDARY return content_type , body
Encode form fields for multipart/form-data.
Encode form fields for multipart / form - data .
"""Encode form fields for multipart/form-data.

    Args:
      fields: A sequence of (name, value) elements for regular form fields.
      files: A sequence of (name, filename, value) elements for data to be
             uploaded as files.
    Returns:
      (content_type, body) ready for httplib.HTTP instance.

    Source:
      https://github.com/rietveld-codereview/rietveld/blob/1be266f92fbd6e01732e1bde10589bc408d65633/upload.py#L964
    """
(content_type, body) ready for httplib.HTTP instance.
( content_type body ) ready for httplib . HTTP instance .
fields
A sequence of (name, value) elements for regular form fields.
A sequence of ( name value ) elements for regular form fields .
files
A sequence of (name, filename, value) elements for data to be
uploaded as files.
A sequence of ( name filename value ) elements for data to be uploaded as files .