code: def add_body_part(self, key, data, mime_type, size=None):
      
      if isinstance(data, str):
        size = len(data)
      if hasattr(data, "fileno"):
        size = os.fstat(data.fileno())[stat.ST_SIZE]
      if size is None:
        # TODO: support chunked transfer if some of the body is of unknown size.
        raise UnknownSize('Each part of the body must have a known size.')
      if 'Content-Length' in self.headers:
        content_length = int(self.headers['Content-Length'])
      else:
        content_length = 0
      # If this is the first part added to the body, then this is not a multipart
      # request.
      boundary_string = '\r\n--%s\r\n' % (MIME_BOUNDARY,)
      self._body_parts.append(boundary_string)
      content_length += len(boundary_string) + size
      # Include the mime type of this part.
      cd = 'Content-Disposition: form-data; name="%s"' % key
      mt = mime_type
      if hasattr(data, "fileno"):
          cd += '; filename="%s"' % data.name.split('/')[-1]
          mt = mimetypes.guess_type(data.name)[0] or 'application/octet-stream'
      cd += '\r\n'
      type_string = 'Content-Type: %s\r\n\r\n' % (mt)
      self._body_parts.append(cd)
      self._body_parts.append(type_string)
      content_length += len(type_string) + len(cd)
      self._body_parts.append(data)
      self.headers['Content-Length'] = str(content_length)
docs: Adds data to the HTTP request body.
     
      If more than one part is added, this is assumed to be a mime-multipart
      request. This method is designed to create MIME 1.0 requests as specified
      in RFC 1341.
  
      Args:
        data: str or a file-like object containing a part of the request body.
        mime_type: str The MIME type describing the data
        size: int Required if the data is a file like object. If the data is a
              string, the size is calculated so this parameter is ignored.