code: def guess_filename(obj):
      
      name = getattr(obj, 'name', None)
      if (name and isinstance(name, basestring) and name[0] != '<' and
              name[-1] != '>'):
          return os.path.basename(name)
docs: Tries to guess the filename of the given object.