def filename_from_headers(headers):
if type(headers) == str:<EOL><INDENT>headers = headers.splitlines()<EOL><DEDENT>if type(headers) == list:<EOL><INDENT>headers = dict([x.split('<STR_LIT::>', <NUM_LIT:1>) for x in headers])<EOL><DEDENT>cdisp = headers.get("<STR_LIT>")<EOL>if not cdisp:<EOL><INDENT>return None<EOL><DEDENT>cdtype = cdisp.split('<STR_LIT:;>')<EOL>if len(cdtype) == <NUM_LIT:1>:<EOL><INDENT>return None<EOL><DEDENT>if cdtype[<NUM_LIT:0>].strip().lower() not in ('<STR_LIT>', '<STR_LIT>'):<EOL><INDENT>return None<EOL><DEDENT>fnames = [x for x in cdtype[<NUM_LIT:1>:] if x.strip().startswith('<STR_LIT>')]<EOL>if len(fnames) > <NUM_LIT:1>:<EOL><INDENT>return None<EOL><DEDENT>name = fnames[<NUM_LIT:0>].split('<STR_LIT:=>')[<NUM_LIT:1>].strip('<STR_LIT>')<EOL>name = os.path.basename(name)<EOL>if not name:<EOL><INDENT>return None<EOL><DEDENT>return name<EOL>
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