Skip to content

Raise an exception when the header cannot be parsed#8

Merged
dbtsai merged 1 commit intofalconry:masterfrom
wojcikstefan:raise-parse-exception
Jan 27, 2016
Merged

Raise an exception when the header cannot be parsed#8
dbtsai merged 1 commit intofalconry:masterfrom
wojcikstefan:raise-parse-exception

Conversation

@wojcikstefan
Copy link
Copy Markdown
Collaborator

Also refactors unit tests so that they produce an expected output upon success and failure.

The main rationale behind MimeTypeParseException is that if somebody sends a request as follows:

requests.get(url, headers={ 'Accept': 'text' })

... the server should respond with a 400 saying that the header is not formatted properly. Right now, we'd have to do the validation outside of the library (introducing somewhat duplicate code) or we'd have to catch a ValueError (because (type, subtype) = full_type.split('/') would raise ValueError: need more than 1 value to unpack), which is too generic. Merging this PR will help me submit a similar PR to https://github.com/martinblech/mimerender utilizing the new exception type and returning a valid response.

dbtsai added a commit that referenced this pull request Jan 27, 2016
Raise an exception when the header cannot be parsed
@dbtsai dbtsai merged commit 2552c7b into falconry:master Jan 27, 2016
@dbtsai
Copy link
Copy Markdown
Collaborator

dbtsai commented Jan 27, 2016

Thanks. Merged.

@wojcikstefan
Copy link
Copy Markdown
Collaborator Author

Great, thank you @dbtsai! Could you release an updated pypi package?

@dbtsai
Copy link
Copy Markdown
Collaborator

dbtsai commented Jan 27, 2016

Let me do it durning the weekend. Thanks.

@dbtsai
Copy link
Copy Markdown
Collaborator

dbtsai commented Jan 27, 2016

@wojcikstefan The build is broken with your patch, https://travis-ci.org/dbtsai/python-mimeparse/builds/105085056
Can you fix it? Thanks.

@wojcikstefan
Copy link
Copy Markdown
Collaborator Author

Yup, will do. Thanks for pointing that out!

@mattbriancon
Copy link
Copy Markdown

This was a backwards-incompatible change and should have been released under a new major version. I'm guessing there are currently a lot of broken builds out there right now.

@dbtsai
Copy link
Copy Markdown
Collaborator

dbtsai commented Feb 1, 2016

@wojcikstefan Can you address the concerns raised by @mattbriancon? Thanks.

@wojcikstefan
Copy link
Copy Markdown
Collaborator Author

@mattbriancon could you elaborate? Providing an invalid mime type format already resulted in an exception here (though it indeed was a different exception type - ValueError vs MimeTypeParseException, which doesn't inherit from ValueError). Is that the incompatibility you refer to? Or is it the fact that the exception's message uses a .format function that's incompatible with py2.6 (which wasn't in tested as one of the supported versions)?

@mattbriancon
Copy link
Copy Markdown

@mattbriancon
Copy link
Copy Markdown

Tracking the issue here: django-tastypie/django-tastypie#1429

@wojcikstefan
Copy link
Copy Markdown
Collaborator Author

@mattbriancon let me clone django-tastypie and propose a fix to python-mimeparse that'll fix your tests.

@wojcikstefan
Copy link
Copy Markdown
Collaborator Author

@mattbriancon @dbtsai I just opened #13 - it should fix the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants