Git Product home page Git Product logo

rfc6266's Introduction

rfc6266

This module parses and generates HTTP Content-Disposition headers. These headers are used when getting resources for download; they provide a hint of whether the file should be downloaded, and of what filename to use when saving.

Usage

Receiver

parse_headers builds a ContentDisposition object from the Content-Disposition header and (as a fallback) the document location. Shortcuts work with response objects from httplib2 and the requests library.

Important attributes of ContentDisposition are is_inline, filename_unsafe, filename_sanitized.

Sender

build_header builds a header value from a filename.

Security

The Content-Disposition filename should be used with caution. Do not let the sender overwrite an arbitrary filesystem location, pick arbitrary extensions or filenames with special meaning, pick filenames containing unusual or misleading characters, etc. Read RFC 6266 section 4.3 for more details.

Testing

To test in the current Python implementation:

py.test

To test compatibility across Python releases:

tox

rfc6266 is currently tested under Python 2.7, Python 2.6, Python 3.3, Python 3.2, and PyPy (1.7).

image

References

rfc6266's People

Contributors

ccorbacho avatar ereon avatar g2p avatar redtoad avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

rfc6266's Issues

dependency LEPL develop discontinued

just left a notice here as I encounter some error with LEPL under python 3.7,
as this project have been left untouched for a really long time too.

Release 0.0.5?

We have run into issues on 0.0.4 due to the log handler being a class instead of an instantiated class, I know it has been a while, but could you possibly do a 0.0.5 release on master? It would help us out a lot.

Project is abandoned

Looking at #8, it appears as if this project is abandoned.

@g2p Is there any intention to maintain this project? I'd be willing to adopt it if you do not wish to maintain it.

I also see there's at least one fork and that project looks more actively maintained (only 2 years stale). @SWW13, is that project actively maintained?

ValueError with empty filename

How to reproduce:

rfc6266.parse_headers('attachment; filename=""')
Traceback (most recent call last):
  File "contentdisposition.py", line 3, in <module>
    rfc6266.parse_headers('attachment; filename=""')
  File "rfc6266.py", line 232, in parse_headers
    disposition=parsed[0], assocs=parsed[1:], location=location)
  File "rfc6266.py", line 86, in __init__
    self.assocs = dict((key.lower(), val) for (key, val) in assocs)
  File "rfc6266.py", line 86, in <genexpr>
    self.assocs = dict((key.lower(), val) for (key, val) in assocs)
ValueError: need more than 1 value to unpack

undeclared dependency on pytest, pytest failures?

It would be reasonable to consider me a Python n00b, so feel free to close this if you like:

  1. It looks to me like there's an undeclared dependency on pytest. Specifically, after installing with

python setup.py install --user

(python version is 2.7)

I try to run the test file with

python test_rfc6266.py

and discover that I need pytest.

Second, after installing pytest, I see this output:

python -m pytest
=========================================================================================== test session starts ============================================================================================
platform darwin -- Python 2.7.12, pytest-3.0.2, py-1.4.31, pluggy-0.3.1
rootdir: /private/tmp/rfc6266, inifile: 
collected 7 items 

test_rfc6266.py .EE....

================================================================================================== ERRORS ==================================================================================================
_____________________________________________________________________________________ ERROR at setup of test_httplib2 ______________________________________________________________________________________
file /private/tmp/rfc6266/test_rfc6266.py, line 26
  @pytest.mark.skipif("(3,0) <= sys.version_info < (3,3)")
  def test_httplib2(httpserver):
E       fixture 'httpserver' not found
>       available fixtures: cache, capfd, capsys, doctest_namespace, monkeypatch, pytestconfig, record_xml_property, recwarn, tmpdir, tmpdir_factory
>       use 'pytest --fixtures [testpath]' for help on them.

/private/tmp/rfc6266/test_rfc6266.py:26
_____________________________________________________________________________________ ERROR at setup of test_requests ______________________________________________________________________________________
file /private/tmp/rfc6266/test_rfc6266.py, line 36
  @pytest.mark.skipif("(3,0) <= sys.version_info < (3,3)")
  def test_requests(httpserver):
E       fixture 'httpserver' not found
>       available fixtures: cache, capfd, capsys, doctest_namespace, monkeypatch, pytestconfig, record_xml_property, recwarn, tmpdir, tmpdir_factory
>       use 'pytest --fixtures [testpath]' for help on them.

/private/tmp/rfc6266/test_rfc6266.py:36
==================================================================================== 5 passed, 2 error in 0.22 seconds =====================================================================================

Finally, I guess I was surprised by the test coverage--there's not much coverage of parsing of interesting Content-Disposition lines?

Many thanks, sorry for being so needy!

rfc6266 should not raise on unsafe lws

RFC 6266 section 3 "Conformance and Error Handling"

Recipients MAY take steps to recover a usable field value from an
invalid header field, but SHOULD NOT reject the message outright,
unless this is explicitly desirable behavior (e.g., the
implementation is a validator). As such, the default handling of
invalid fields is to ignore them.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.