def extract_filename_from_headers(headers):
 cont_disp_regex = 'attachment; ?filename="?([^"]+)'
 res = None
 if ('content-disposition' in headers):
  cont_disp = headers['content-disposition']
  match = re.match(cont_disp_regex, cont_disp)
  if match:
   res = match.group(1)
   res = os.path.basename(res)
 return res

def extract_filename_from_headers ( headers ) : cont_disp_regex = 'attachment; ?filename="?([^"]+)' res = None if ( 'content-disposition' in headers ) : cont_disp = headers [ 'content-disposition' ] match = re . match ( cont_disp_regex , cont_disp ) if match : res = match . group ( 1 ) res = os . path . basename ( res ) return res
extracts a filename from the given dict of http headers .