コード例 #1
0
ファイル: response_helpers.py プロジェクト: vytas7/falcon
def format_content_disposition(value, disposition_type='attachment'):
    """Format a Content-Disposition header given a filename."""

    # NOTE(vytas): RFC 6266, Appendix D.
    #   Include a "filename" parameter when US-ASCII ([US-ASCII]) is
    #   sufficiently expressive.
    if isascii(value):
        return '%s; filename="%s"' % (disposition_type, value)

    # NOTE(vytas): RFC 6266, Appendix D.
    #   * Include a "filename*" parameter where the desired filename cannot be
    #     expressed faithfully using the "filename" form.  Note that legacy
    #     user agents will not process this, and will fall back to using the
    #     "filename" parameter's content.
    #   * When a "filename*" parameter is sent, to also generate a "filename"
    #     parameter as a fallback for user agents that do not support the
    #     "filename*" form, if possible.
    #   * When a "filename" parameter is included as a fallback (as per above),
    #     "filename" should occur first, due to parsing problems in some
    #     existing implementations.
    return "%s; filename=%s; filename*=UTF-8''%s" % (
        disposition_type,
        secure_filename(value),
        uri.encode_value(value),
    )
コード例 #2
0
 def test_misc_isascii(self, string, expected_ascii):
     if expected_ascii:
         assert misc.isascii(string)
     else:
         assert not misc.isascii(string)