falconry / python-mimeparse Goto Github PK
View Code? Open in Web Editor NEWBasic functions for handling mime-types in Python
License: MIT License
Basic functions for handling mime-types in Python
License: MIT License
I have setup a new Python environment with version 3.3, and I didn't go with the default installation folder (preferring to install applications into the "C:\Program Files" folder).
When I run python-mimeparse-0.1.4.linux-x86_64.exe I get an error indicating "No python installation found in registry", and cannot manually enter the actual value. I googled python registry entries for what key it would be looking for and found it under the local machine, and added it to the current_user (since the article I found mentioned it would be under both) but to no avail.
Could you be so kind as to share what registry key your installation program is looking for so I can manually add it and see if I can successfully run the installer?
And thanks so much for creating python-mimeparse and for your help on this question.
We should remove python2 support from the code. python 3.6+ (maybe 3.7 since 3.6 does eol in a couple of months)
What steps will reproduce the problem?
In [3]: mimeparse.parse_mime_type("text/html, image/gif, image/jpeg, ; q=.2, */; q=.2")
What is the expected output? What do you see instead?
ValueError Traceback (most recent call last)
/tmp/ in ()
/tmp/mimeparse.py in parse_mime_type(mime_type)
36 # Turn it into a legal wildcard.
37 if full_type == '': full_type = '/*'
---> 38 (type, subtype) = full_type.split("/")
39 return (type.strip(), subtype.strip(), params)
40
ValueError: too many values to unpack
What version of the product are you using? On what operating system?
1.3
Please provide any additional information below.
https://bitbucket.org/benoitc/django-authopenid/issue/54/type-subtype-parts-0-split-valueerror-too#comment-483268
Hi.
I've tried to do best_match()
on acceptable types defined as ['application/json;q=1.0', 'text/html;q=0.9', 'text/plain;q=0.1']
. Accept
header was set to */*
. I'm expecting that mimeparse.best_match()
will return application/json
as a best matching type (due to the highest qvalue), but function returns text/plain
instead.
The problem lies inside best_match()
function, where every acceptable media type is checked separately, and every type is scored (0, 1.0)
. As a result a [((0, 1.0), 'application/json;q=1.0'), ((0, 1.0), 'text/html;q=0.9'), ((0, 1.0), 'text/plain;q=0.1')]
list is sorted, then the last element is returned.
I would ask - am I wrong expecting application/json
as a result in that case, or is there a bug?
Test with Accept: application/json, text/javascript, */*;
Once python 2 is dropped in #37 we can modernize the code to use py3 conventions
Howdy,
While doing some packaging work for Fedora, I noticed that both mimeparse and python-mimeparse are available on PyPI. After digging through the commit history, I see that python-mimeparse was originally forked from mimeparse. Mimeparse only has one commit after the fork happened.
To reduce the confusion, would it be possible for the projects to be merged back together? Or put another way, what would it take for this module to claim the mimeparse name on PyPI and become the single official source?
Hi guys,
python 3.13 is in beta now. Any chance to release a version with the dependency on cgi
removed?
What steps will reproduce the problem?
mimeparse.parse_media_range('/;q=0')
Expected Output: ('', '', {'q': '0'})
Actual Output: ('', '', {'q': '1'})
I encountered this while parsing an request Accept header with
'application/xml,/;q=0' and the only acceptable type on the
server is application/json. It freely let the server return a
JSON representation, but should have failed since the user agent
explicitly defined a quality of 0 for all other mimetypes. The
value of 0 for / was being overwritten with 1.
56c56,57
not float(params['q']) or float(params['q']) > 1\ or float(params['q']) < 0:
What version of the product are you using? On what operating system?
Python version of mimeparse 0.1.3
Using Python 2.7.1
(Moved from falconry/falcon#1183)
Optimizations may include:
PyPI has changed the formatting of the tarball download links, and the one in setup.py is now broken:
https://bitbucket.org/pypa/pypi/issues/438/backwards-compatible-un-hashed-package
I would have suggested to use github tag URL there instead and submitted a PR, but unfortunately it looks like the python-mimeparse releases are not being tagged in the repository...
What steps will reproduce the problem?
mimeparse.best_match(["image/jpeg", "text/plain"], "text/*;q=0.3, text/html;q=0.7, text/html;level=1, text/html;level=2;q=0.4, */*;q=0.5")
What is the expected output? What do you see instead?
Expected: 'image/jpeg'
Instead: 'text/plain'
What version of the product are you using? On what operating system?
Version: 0.1.3
OS: Mac OS X 10.6.4, Python 2.6.1
(Using Python version of mimeparse library)
Please provide any additional information below.
The best_match function is using fitness_and_quality_parsed() to order the candidate media ranges, but the first value from that is the fitness, which corresponds to what rfc2616 calls the "precedence", or the specificity of the range to the particular candidate type. The specificity matters, but the major ordering factor should be the quality (the client's measure of which media ranges are most preferred).
In the example above, image/jpeg should have a quality of 0.5 (from the /) and text/plain should have a quality of 0.3 (from the text/*). The type with the higher quality factor is image/jpeg, and it should win.
I'm attaching a patch that fixes this by swapping the elements returned by fitness_and_quality_parsed(), along with an extra test for your suite. Hope this helps.
See:
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.