def _encode_filename_header(self, filename):
        """
        The filename, encoded to use in a ``Content-Disposition`` header.
        """
        # Based on https://www.djangosnippets.org/snippets/1710/
        user_agent = self.request.META.get('HTTP_USER_AGENT', None)
        if 'WebKit' in user_agent:
            # Support available for UTF-8 encoded strings.
            # This also matches Edgee.
            return u'filename={}'.format(filename).encode("utf-8")
        elif 'MSIE' in user_agent:
            # IE does not support RFC2231 for internationalized headers, but somehow
            # percent-decodes it so this can be used instead. Note that using the word
            # "attachment" anywhere in the filename overrides an inline content-disposition.
            url_encoded = quote(filename.encode("utf-8")).replace('attachment', "a%74tachment")
            return "filename={}".format(url_encoded).encode("utf-8")
        else:
            # For others like Firefox, we follow RFC2231 (encoding extension in HTTP headers).
            rfc2231_filename = quote(filename.encode("utf-8"))
            return "filename*=UTF-8''{}".format(rfc2231_filename).encode("utf-8")
def _encode_filename_header ( self , filename ) : user_agent = self . request . META . get ( 'HTTP_USER_AGENT' , None ) if 'WebKit' in user_agent : return u'filename={}' . format ( filename ) . encode ( "utf-8" ) elif 'MSIE' in user_agent : url_encoded = quote ( filename . encode ( "utf-8" ) ) . replace ( 'attachment' , "a%74tachment" ) return "filename={}" . format ( url_encoded ) . encode ( "utf-8" ) else : rfc2231_filename = quote ( filename . encode ( "utf-8" ) ) return "filename*=UTF-8''{}" . format ( rfc2231_filename ) . encode ( "utf-8" )
The filename, encoded to use in a ``Content-Disposition`` header.