docs: def filename_from_headers(headers):
      """Detect filename from Content-Disposition headers if present.
      http://greenbytes.de/tech/tc2231/
  
      :param: headers as dict, list or string
      :return: filename from content-disposition header or None
      """
      if type(headers) == str:
          headers = headers.splitlines()
      if type(headers) == list:
          headers = dict([x.split(':', 1) for x in headers])
      cdisp = headers.get("Content-Disposition")
      if not cdisp:
          return None
      cdtype = cdisp.split(';')
      if len(cdtype) == 1:
          return None
      if cdtype[0].strip().lower() not in ('inline', 'attachment'):
          return None
      # several filename params is illegal, but just in case
      fnames = [x for x in cdtype[1:] if x.strip().startswith('filename=')]
      if len(fnames) > 1:
          return None
      name = fnames[0].split('=')[1].strip(' \t"')
      name = os.path.basename(name)
      if not name:
          return None
      return name