Hello community, here is the log from the commit of package python3-python-mimeparse for openSUSE:Factory checked in at 2016-11-21 14:26:04 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Comparing /work/SRC/openSUSE:Factory/python3-python-mimeparse (Old) and /work/SRC/openSUSE:Factory/.python3-python-mimeparse.new (New) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "python3-python-mimeparse" Changes: -------- --- /work/SRC/openSUSE:Factory/python3-python-mimeparse/python3-python-mimeparse.changes 2016-05-25 21:27:02.000000000 +0200 +++ /work/SRC/openSUSE:Factory/.python3-python-mimeparse.new/python3-python-mimeparse.changes 2016-11-21 14:26:05.000000000 +0100 @@ -1,0 +2,33 @@ +Sun Nov 20 18:44:57 UTC 2016 - a...@gmx.de + +- specfile: + * changed README.md -> README.rst + +- update to version 1.6.0: + * let acceptable types specify their quality (#26) + * more readable formatting of test data + * Run PyPy tests with pypy-5.4 on Travis (#30) + * Ignore more dirs in flake8 tests (#31) + * ignore .venv instead of venv + * flake8 tweaks (#27) + * ignore build/ and venv/ dirs + +- changes from version 1.5.5: + (no changelog available) + +- changes from version 1.5.4: + * Release as a universal wheel (#28) + * Remove __init__.py (#29) + +- changes from version 1.5.3: + * extra test based on RFC 7231 page 38 + * cleaner code for quality_and_fitness_parsed + * more readable testdata.json + * readme tweaks + * setup.py sanity check + pep8 tweaks to mimeparse.py + * setup.py + README tidying (#22) + * Document return types (#24) + * Add pypy3 to test matrix + * update download_url (fixes #18) + +------------------------------------------------------------------- Old: ---- python-mimeparse-1.5.2.tar.gz New: ---- python-mimeparse-1.6.0.tar.gz ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ python3-python-mimeparse.spec ++++++ --- /var/tmp/diff_new_pack.FaCvnk/_old 2016-11-21 14:26:06.000000000 +0100 +++ /var/tmp/diff_new_pack.FaCvnk/_new 2016-11-21 14:26:06.000000000 +0100 @@ -17,7 +17,7 @@ Name: python3-python-mimeparse -Version: 1.5.2 +Version: 1.6.0 Release: 0 Url: https://github.com/dbtsai/python-mimeparse Summary: Basic functions for parsing and matching mime-type names @@ -48,7 +48,7 @@ %files %defattr(-,root,root,-) -%doc LICENSE README.md +%doc LICENSE README.rst %{python3_sitelib}/* %changelog ++++++ python-mimeparse-1.5.2.tar.gz -> python-mimeparse-1.6.0.tar.gz ++++++ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/python-mimeparse-1.5.2/MANIFEST.in new/python-mimeparse-1.6.0/MANIFEST.in --- old/python-mimeparse-1.5.2/MANIFEST.in 2016-04-26 18:54:58.000000000 +0200 +++ new/python-mimeparse-1.6.0/MANIFEST.in 2016-09-28 22:16:52.000000000 +0200 @@ -1 +1 @@ -include README.md LICENSE mimeparse_test.py testdata.json +include README.rst LICENSE mimeparse_test.py testdata.json diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/python-mimeparse-1.5.2/PKG-INFO new/python-mimeparse-1.6.0/PKG-INFO --- old/python-mimeparse-1.5.2/PKG-INFO 2016-04-26 19:55:46.000000000 +0200 +++ new/python-mimeparse-1.6.0/PKG-INFO 2016-10-17 00:54:15.000000000 +0200 @@ -1,42 +1,75 @@ Metadata-Version: 1.1 Name: python-mimeparse -Version: 1.5.2 +Version: 1.6.0 Summary: A module provides basic functions for parsing mime-type names and matching them against a list of media-ranges. Home-page: https://github.com/dbtsai/python-mimeparse Author: DB Tsai Author-email: dbt...@dbtsai.com License: UNKNOWN -Download-URL: http://pypi.python.org/packages/source/p/python-mimeparse/python-mimeparse-1.5.2.tar.gz -Description: # Travis CI Build Status [![Build Status](https://travis-ci.org/dbtsai/python-mimeparse.svg?branch=master)](https://travis-ci.org/dbtsai/python-mimeparse) +Download-URL: https://github.com/dbtsai/python-mimeparse/tarball/1.6.0 +Description: Python-MimeParse + ================ - This module provides basic functions for handling mime-types. It can handle - matching mime-types against a list of media-ranges. See section 14.1 of - the HTTP specification [RFC 2616] for a complete explanation. - - http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.1 - - Contents: - - parse_mime_type(): Parses a mime-type into its component parts. - - parse_media_range(): Media-ranges are mime-types with wild-cards and a "q" quality parameter. - - quality(): Determines the quality ("q") of a mime-type when compared against a list of media-ranges. - - quality_parsed(): Just like quality() except the second parameter must be pre-parsed. - - best_match(): Choose the mime-type with the highest quality ("q") from a list of candidates. + .. image:: https://travis-ci.org/dbtsai/python-mimeparse.svg?branch=master + :target: https://travis-ci.org/dbtsai/python-mimeparse + + This module provides basic functions for handling mime-types. It can + handle matching mime-types against a list of media-ranges. See section + 5.3.2 of the HTTP 1.1 Semantics and Content specification [RFC 7231] for + a complete explanation: https://tools.ietf.org/html/rfc7231#section-5.3.2 + + Installation + ------------ + + Use **pip**: + + .. code-block:: sh + + $ pip install python-mimeparse + + It supports Python 2.7 - 3.5 and PyPy. + + Functions + --------- + + **parse_mime_type()** + + Parses a mime-type into its component parts. + + **parse_media_range()** + + Media-ranges are mime-types with wild-cards and a "q" quality parameter. + + **quality()** + + Determines the quality ("q") of a mime-type when compared against a list of + media-ranges. + + **quality_parsed()** + + Just like ``quality()`` except the second parameter must be pre-parsed. + + **best_match()** + + Choose the mime-type with the highest quality ("q") from a list of candidates. Testing - ======= - The format of the JSON test data file is as follows: - A top-level JSON object which has a key for each of the functions to be tested. The value corresponding to that key is a list of tests. Each test contains: the argument or arguments to the function being tested, the expected results and an optional description. - - Python - ====== - The Python tests require Python 2.6. - - Run the tests by typing: - python mimeparse_test.py - - To make sure that the package works in all the supported environments, you can run tox tests: - pip install tox - tox + ------- + + Run the tests by typing: ``python mimeparse_test.py``. The tests require Python 2.6. + + To make sure that the package works in all the supported environments, you can + run **tox** tests: + + .. code-block:: sh + + $ pip install tox + $ tox + + The format of the JSON test data file is as follows: A top-level JSON object + which has a key for each of the functions to be tested. The value corresponding + to that key is a list of tests. Each test contains: the argument or arguments + to the function being tested, the expected results and an optional description. Keywords: mime-type Platform: UNKNOWN diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/python-mimeparse-1.5.2/README.md new/python-mimeparse-1.6.0/README.md --- old/python-mimeparse-1.5.2/README.md 2016-04-26 18:54:58.000000000 +0200 +++ new/python-mimeparse-1.6.0/README.md 1970-01-01 01:00:00.000000000 +0100 @@ -1,30 +0,0 @@ -# Travis CI Build Status [![Build Status](https://travis-ci.org/dbtsai/python-mimeparse.svg?branch=master)](https://travis-ci.org/dbtsai/python-mimeparse) - -This module provides basic functions for handling mime-types. It can handle -matching mime-types against a list of media-ranges. See section 14.1 of -the HTTP specification [RFC 2616] for a complete explanation. - - http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.1 - -Contents: - - parse_mime_type(): Parses a mime-type into its component parts. - - parse_media_range(): Media-ranges are mime-types with wild-cards and a "q" quality parameter. - - quality(): Determines the quality ("q") of a mime-type when compared against a list of media-ranges. - - quality_parsed(): Just like quality() except the second parameter must be pre-parsed. - - best_match(): Choose the mime-type with the highest quality ("q") from a list of candidates. - -Testing -======= -The format of the JSON test data file is as follows: -A top-level JSON object which has a key for each of the functions to be tested. The value corresponding to that key is a list of tests. Each test contains: the argument or arguments to the function being tested, the expected results and an optional description. - -Python -====== -The Python tests require Python 2.6. - -Run the tests by typing: -python mimeparse_test.py - -To make sure that the package works in all the supported environments, you can run tox tests: -pip install tox -tox diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/python-mimeparse-1.5.2/README.rst new/python-mimeparse-1.6.0/README.rst --- old/python-mimeparse-1.5.2/README.rst 1970-01-01 01:00:00.000000000 +0100 +++ new/python-mimeparse-1.6.0/README.rst 2016-09-28 22:23:21.000000000 +0200 @@ -0,0 +1,63 @@ +Python-MimeParse +================ + +.. image:: https://travis-ci.org/dbtsai/python-mimeparse.svg?branch=master + :target: https://travis-ci.org/dbtsai/python-mimeparse + +This module provides basic functions for handling mime-types. It can +handle matching mime-types against a list of media-ranges. See section +5.3.2 of the HTTP 1.1 Semantics and Content specification [RFC 7231] for +a complete explanation: https://tools.ietf.org/html/rfc7231#section-5.3.2 + +Installation +------------ + +Use **pip**: + +.. code-block:: sh + + $ pip install python-mimeparse + +It supports Python 2.7 - 3.5 and PyPy. + +Functions +--------- + +**parse_mime_type()** + +Parses a mime-type into its component parts. + +**parse_media_range()** + +Media-ranges are mime-types with wild-cards and a "q" quality parameter. + +**quality()** + +Determines the quality ("q") of a mime-type when compared against a list of +media-ranges. + +**quality_parsed()** + +Just like ``quality()`` except the second parameter must be pre-parsed. + +**best_match()** + +Choose the mime-type with the highest quality ("q") from a list of candidates. + +Testing +------- + +Run the tests by typing: ``python mimeparse_test.py``. The tests require Python 2.6. + +To make sure that the package works in all the supported environments, you can +run **tox** tests: + +.. code-block:: sh + + $ pip install tox + $ tox + +The format of the JSON test data file is as follows: A top-level JSON object +which has a key for each of the functions to be tested. The value corresponding +to that key is a list of tests. Each test contains: the argument or arguments +to the function being tested, the expected results and an optional description. diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/python-mimeparse-1.5.2/mimeparse.py new/python-mimeparse-1.6.0/mimeparse.py --- old/python-mimeparse-1.5.2/mimeparse.py 2016-04-26 18:55:28.000000000 +0200 +++ new/python-mimeparse-1.6.0/mimeparse.py 2016-10-17 00:53:37.000000000 +0200 @@ -1,25 +1,6 @@ -"""MIME-Type Parser +import cgi -This module provides basic functions for handling mime-types. It can handle -matching mime-types against a list of media-ranges. See section 14.1 of the -HTTP specification [RFC 2616] for a complete explanation. - - http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.1 - -Contents: - - parse_mime_type(): Parses a mime-type into its component parts. - - parse_media_range(): Media-ranges are mime-types with wild-cards and a 'q' - quality parameter. - - quality(): Determines the quality ('q') of a mime-type when - compared against a list of media-ranges. - - quality_parsed(): Just like quality() except the second parameter must be - pre-parsed. - - best_match(): Choose the mime-type with the highest quality ('q') - from a list of candidates. -""" -from functools import reduce - -__version__ = '1.5.2' +__version__ = '1.6.0' __author__ = 'Joe Gregorio' __email__ = 'j...@bitworking.org' __license__ = 'MIT License' @@ -39,12 +20,10 @@ into: ('application', 'xhtml', {'q', '0.5'}) + + :rtype: (str,str,dict) """ - parts = mime_type.split(';') - params = dict([tuple([s.strip() for s in param.split('=', 1)]) - for param in parts[1:] - ]) - full_type = parts[0].strip() + full_type, params = cgi.parse_header(mime_type) # Java URLConnection class sends an Accept header that includes a # single '*'. Turn it into a legal wildcard. if full_type == '*': @@ -52,7 +31,8 @@ type_parts = full_type.split('/') if '/' in full_type else None if not type_parts or len(type_parts) > 2: - raise MimeTypeParseException("Can't parse type \"{}\"".format(full_type)) + raise MimeTypeParseException( + "Can't parse type \"{}\"".format(full_type)) (type, subtype) = type_parts @@ -72,10 +52,15 @@ In addition this function also guarantees that there is a value for 'q' in the params dictionary, filling it in with a proper default if necessary. + + :rtype: (str,str,dict) """ (type, subtype, params) = parse_mime_type(range) - if 'q' not in params or not params['q'] or \ - float(params['q']) > 1 or float(params['q']) < 0: + params.setdefault('q', params.pop('Q', None)) # q is case insensitive + try: + if not params['q'] or not 0 <= float(params['q']) <= 1: + params['q'] = '1' + except ValueError: # from float() params['q'] = '1' return (type, subtype, params) @@ -89,25 +74,45 @@ the fitness value and the value of the 'q' quality parameter of the best match, or (-1, 0) if no match was found. Just as for quality_parsed(), 'parsed_ranges' must be a list of parsed media ranges. + + :rtype: (float,int) """ best_fitness = -1 best_fit_q = 0 - (target_type, target_subtype, target_params) =\ + (target_type, target_subtype, target_params) = \ parse_media_range(mime_type) + for (type, subtype, params) in parsed_ranges: - type_match = (type == target_type or - type == '*' or - target_type == '*') - subtype_match = (subtype == target_subtype or - subtype == '*' or - target_subtype == '*') + + # check if the type and the subtype match + type_match = ( + type in (target_type, '*') or + target_type == '*' + ) + subtype_match = ( + subtype in (target_subtype, '*') or + target_subtype == '*' + ) + + # if they do, assess the "fitness" of this mime_type if type_match and subtype_match: - param_matches = reduce(lambda x, y: x + y, [1 for (key, value) in - target_params.items() if key != 'q' and - key in params and value == params[key]], 0) - fitness = (type == target_type) and 100 or 0 - fitness += (subtype == target_subtype) and 10 or 0 + + # 100 points if the type matches w/o a wildcard + fitness = type == target_type and 100 or 0 + + # 10 points if the subtype matches w/o a wildcard + fitness += subtype == target_subtype and 10 or 0 + + # 1 bonus point for each matching param besides "q" + param_matches = sum([ + 1 for (key, value) in target_params.items() + if key != 'q' and key in params and value == params[key] + ]) fitness += param_matches + + # finally, add the target's "q" param (between 0 and 1) + fitness += float(target_params.get('q', 1)) + if fitness > best_fitness: best_fitness = fitness best_fit_q = params['q'] @@ -122,7 +127,10 @@ that have already been parsed by parse_media_range(). Returns the 'q' quality parameter of the best match, 0 if no match was found. This function behaves the same as quality() except that 'parsed_ranges' must be a list of - parsed media ranges. """ + parsed media ranges. + + :rtype: float + """ return quality_and_fitness_parsed(mime_type, parsed_ranges)[0] @@ -137,6 +145,7 @@ text/html;level=1, text/html;level=2;q=0.4, */*;q=0.5') 0.7 + :rtype: float """ parsed_ranges = [parse_media_range(r) for r in ranges.split(',')] @@ -156,14 +165,19 @@ >>> best_match(['application/xbel+xml', 'text/xml'], 'text/*;q=0.5,*/*; q=0.1') 'text/xml' + + :rtype: str """ split_header = _filter_blank(header.split(',')) parsed_header = [parse_media_range(r) for r in split_header] weighted_matches = [] pos = 0 for mime_type in supported: - weighted_matches.append((quality_and_fitness_parsed(mime_type, - parsed_header), pos, mime_type)) + weighted_matches.append(( + quality_and_fitness_parsed(mime_type, parsed_header), + pos, + mime_type + )) pos += 1 weighted_matches.sort() @@ -171,6 +185,7 @@ def _filter_blank(i): + """Return all non-empty items in the list.""" for s in i: if s.strip(): yield s diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/python-mimeparse-1.5.2/mimeparse_test.py new/python-mimeparse-1.6.0/mimeparse_test.py --- old/python-mimeparse-1.5.2/mimeparse_test.py 2016-04-26 18:54:58.000000000 +0200 +++ new/python-mimeparse-1.6.0/mimeparse_test.py 2016-10-17 00:39:42.000000000 +0200 @@ -6,9 +6,10 @@ of PyUnitTestCases. Then it uses PyUnit to run them and report their status. """ import json -import mimeparse import unittest +import mimeparse + __version__ = "0.1" __author__ = 'Ade Oshineye' @@ -36,15 +37,19 @@ def _test_best_match(self, args, expected, description): if expected is None: - self.assertRaises(mimeparse.MimeTypeParseException, mimeparse.best_match, args[0], args[1]) + self.assertRaises(mimeparse.MimeTypeParseException, + mimeparse.best_match, args[0], args[1]) else: result = mimeparse.best_match(args[0], args[1]) - message = "Expected: '%s' but got %s. Description for this test: %s" % (expected, result, description) + message = \ + "Expected: '%s' but got %s. Description for this test: %s" % \ + (expected, result, description) self.assertEqual(expected, result, message) def _test_parse_mime_type(self, args, expected): if expected is None: - self.assertRaises(mimeparse.MimeTypeParseException, mimeparse.parse_mime_type, args) + self.assertRaises(mimeparse.MimeTypeParseException, + mimeparse.parse_mime_type, args) else: expected = tuple(expected) result = mimeparse.parse_mime_type(args) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/python-mimeparse-1.5.2/python_mimeparse.egg-info/PKG-INFO new/python-mimeparse-1.6.0/python_mimeparse.egg-info/PKG-INFO --- old/python-mimeparse-1.5.2/python_mimeparse.egg-info/PKG-INFO 2016-04-26 19:55:46.000000000 +0200 +++ new/python-mimeparse-1.6.0/python_mimeparse.egg-info/PKG-INFO 2016-10-17 00:54:15.000000000 +0200 @@ -1,42 +1,75 @@ Metadata-Version: 1.1 Name: python-mimeparse -Version: 1.5.2 +Version: 1.6.0 Summary: A module provides basic functions for parsing mime-type names and matching them against a list of media-ranges. Home-page: https://github.com/dbtsai/python-mimeparse Author: DB Tsai Author-email: dbt...@dbtsai.com License: UNKNOWN -Download-URL: http://pypi.python.org/packages/source/p/python-mimeparse/python-mimeparse-1.5.2.tar.gz -Description: # Travis CI Build Status [![Build Status](https://travis-ci.org/dbtsai/python-mimeparse.svg?branch=master)](https://travis-ci.org/dbtsai/python-mimeparse) +Download-URL: https://github.com/dbtsai/python-mimeparse/tarball/1.6.0 +Description: Python-MimeParse + ================ - This module provides basic functions for handling mime-types. It can handle - matching mime-types against a list of media-ranges. See section 14.1 of - the HTTP specification [RFC 2616] for a complete explanation. - - http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.1 - - Contents: - - parse_mime_type(): Parses a mime-type into its component parts. - - parse_media_range(): Media-ranges are mime-types with wild-cards and a "q" quality parameter. - - quality(): Determines the quality ("q") of a mime-type when compared against a list of media-ranges. - - quality_parsed(): Just like quality() except the second parameter must be pre-parsed. - - best_match(): Choose the mime-type with the highest quality ("q") from a list of candidates. + .. image:: https://travis-ci.org/dbtsai/python-mimeparse.svg?branch=master + :target: https://travis-ci.org/dbtsai/python-mimeparse + + This module provides basic functions for handling mime-types. It can + handle matching mime-types against a list of media-ranges. See section + 5.3.2 of the HTTP 1.1 Semantics and Content specification [RFC 7231] for + a complete explanation: https://tools.ietf.org/html/rfc7231#section-5.3.2 + + Installation + ------------ + + Use **pip**: + + .. code-block:: sh + + $ pip install python-mimeparse + + It supports Python 2.7 - 3.5 and PyPy. + + Functions + --------- + + **parse_mime_type()** + + Parses a mime-type into its component parts. + + **parse_media_range()** + + Media-ranges are mime-types with wild-cards and a "q" quality parameter. + + **quality()** + + Determines the quality ("q") of a mime-type when compared against a list of + media-ranges. + + **quality_parsed()** + + Just like ``quality()`` except the second parameter must be pre-parsed. + + **best_match()** + + Choose the mime-type with the highest quality ("q") from a list of candidates. Testing - ======= - The format of the JSON test data file is as follows: - A top-level JSON object which has a key for each of the functions to be tested. The value corresponding to that key is a list of tests. Each test contains: the argument or arguments to the function being tested, the expected results and an optional description. - - Python - ====== - The Python tests require Python 2.6. - - Run the tests by typing: - python mimeparse_test.py - - To make sure that the package works in all the supported environments, you can run tox tests: - pip install tox - tox + ------- + + Run the tests by typing: ``python mimeparse_test.py``. The tests require Python 2.6. + + To make sure that the package works in all the supported environments, you can + run **tox** tests: + + .. code-block:: sh + + $ pip install tox + $ tox + + The format of the JSON test data file is as follows: A top-level JSON object + which has a key for each of the functions to be tested. The value corresponding + to that key is a list of tests. Each test contains: the argument or arguments + to the function being tested, the expected results and an optional description. Keywords: mime-type Platform: UNKNOWN diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/python-mimeparse-1.5.2/python_mimeparse.egg-info/SOURCES.txt new/python-mimeparse-1.6.0/python_mimeparse.egg-info/SOURCES.txt --- old/python-mimeparse-1.5.2/python_mimeparse.egg-info/SOURCES.txt 2016-04-26 19:55:46.000000000 +0200 +++ new/python-mimeparse-1.6.0/python_mimeparse.egg-info/SOURCES.txt 2016-10-17 00:54:15.000000000 +0200 @@ -1,8 +1,9 @@ LICENSE MANIFEST.in -README.md +README.rst mimeparse.py mimeparse_test.py +setup.cfg setup.py testdata.json python_mimeparse.egg-info/PKG-INFO diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/python-mimeparse-1.5.2/setup.cfg new/python-mimeparse-1.6.0/setup.cfg --- old/python-mimeparse-1.5.2/setup.cfg 2016-04-26 19:55:46.000000000 +0200 +++ new/python-mimeparse-1.6.0/setup.cfg 2016-10-17 00:54:15.000000000 +0200 @@ -1,3 +1,6 @@ +[bdist_wheel] +universal = 1 + [egg_info] tag_build = tag_date = 0 diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/python-mimeparse-1.5.2/setup.py new/python-mimeparse-1.6.0/setup.py --- old/python-mimeparse-1.5.2/setup.py 2016-04-26 18:54:58.000000000 +0200 +++ new/python-mimeparse-1.6.0/setup.py 2016-10-17 00:39:42.000000000 +0200 @@ -1,26 +1,41 @@ #!/usr/bin/env python -import os import codecs -import mimeparse +import os +import re from setuptools import setup +def get_version(filename): + """ + Return package version as listed in `__version__` in 'filename'. + """ + with open(filename) as fp: + contents = fp.read() + return re.search("__version__ = ['\"]([^'\"]+)['\"]", contents).group(1) + +version = get_version('mimeparse.py') +if not version: + raise RuntimeError('Cannot find version information') + + def read(fname): path = os.path.join(os.path.dirname(__file__), fname) - return codecs.open(path, encoding='utf-8').read() + with codecs.open(path, encoding='utf-8') as fp: + return fp.read() + setup( name="python-mimeparse", py_modules=["mimeparse"], - version=mimeparse.__version__, + version=version, description=("A module provides basic functions for parsing mime-type " "names and matching them against a list of media-ranges."), author="DB Tsai", author_email="dbt...@dbtsai.com", url="https://github.com/dbtsai/python-mimeparse", - download_url=("http://pypi.python.org/packages/source/p/python-mimeparse/" - "python-mimeparse-" + mimeparse.__version__ + ".tar.gz"), + download_url=("https://github.com/dbtsai/python-mimeparse/tarball/" + + version), keywords=["mime-type"], classifiers=[ "Programming Language :: Python", @@ -32,5 +47,5 @@ "Topic :: Internet :: WWW/HTTP", "Topic :: Software Development :: Libraries :: Python Modules", ], - long_description=read('README.md') + long_description=read('README.rst') ) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/python-mimeparse-1.5.2/testdata.json new/python-mimeparse-1.6.0/testdata.json --- old/python-mimeparse-1.5.2/testdata.json 2016-04-26 18:54:58.000000000 +0200 +++ new/python-mimeparse-1.6.0/testdata.json 2016-10-17 00:53:25.000000000 +0200 @@ -1,47 +1,234 @@ { -"parse_media_range": [ - ["application/xml;q=1", ["application", "xml", {"q": "1"}]], - ["application/xml", ["application", "xml", {"q": "1"}]], - ["application/xml;q=",["application", "xml", {"q": "1"}]], - ["application/xml ;q=",["application", "xml", {"q": "1"}]], - ["application/xml ; q=1;b=other",["application", "xml", {"q": "1", "b":"other"}]], - ["application/xml ; q=2;b=other",["application", "xml", {"q": "1", "b":"other"}]], - ["application/xml ; q=0",["application", "xml", {"q": "0"}]], - [" *; q=.2",["*", "*", {"q": ".2"}]] -], + "parse_media_range": [ + ["application/xml;q=1", ["application", "xml", {"q": "1"}]], + ["application/xml", ["application", "xml", {"q": "1"}]], + ["application/xml;q=",["application", "xml", {"q": "1"}]], + ["application/xml ;q=",["application", "xml", {"q": "1"}]], + ["application/xml ;q=-1",["application", "xml", {"q": "1"}]], + ["application/xml ; q=1;b=other",["application", "xml", {"q": "1", "b":"other"}]], + ["application/xml ; q=2;b=other",["application", "xml", {"q": "1", "b":"other"}]], + ["application/xml ; q=0",["application", "xml", {"q": "0"}]], + ["application/xml ; q=foo", ["application", "xml", {"q": "1"}]], + ["application/xml ; Q=0.6", ["application", "xml", {"q": "0.6"}]], + [" *; q=.2", ["*", "*", {"q": ".2"}]] + ], -"quality": [ - [["text/html;level=1", "text/*;q=0.3, text/html;q=0.7, text/html;level=1, text/html;level=2;q=0.4, */*;q=0.5"], 1], - [["text/html", "text/*;q=0.3, text/html;q=0.7, text/html;level=1, text/html;level=2;q=0.4, */*;q=0.5"], 0.7], - [["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"], 0.3], - [["image/jpeg", "text/*;q=0.3, text/html;q=0.7, text/html;level=1, text/html;level=2;q=0.4, */*;q=0.5"], 0.5], - [["text/html;level=2", "text/*;q=0.3, text/html;q=0.7, text/html;level=1, text/html;level=2;q=0.4, */*;q=0.5"], 0.4], - [["text/html;level=3", "text/*;q=0.3, text/html;q=0.7, text/html;level=1, text/html;level=2;q=0.4, */*;q=0.5"], 0.7], - [["text/plain", "text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2"], 0.2] -], + "quality": [ + [ + [ + "text/html;level=1", + "text/*;q=0.3, text/html;q=0.7, text/html;level=1, text/html;level=2;q=0.4, */*;q=0.5" + ], + 1 + ], + [ + [ + "text/html", + "text/*;q=0.3, text/html;q=0.7, text/html;level=1, text/html;level=2;q=0.4, */*;q=0.5" + ], + 0.7 + ], + [ + [ + "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" + ], + 0.3 + ], + [ + [ + "image/jpeg", + "text/*;q=0.3, text/html;q=0.7, text/html;level=1, text/html;level=2;q=0.4, */*;q=0.5" + ], + 0.5 + ], + [ + [ + "text/html;level=2", + "text/*;q=0.3, text/html;q=0.7, text/html;level=1, text/html;level=2;q=0.4, */*;q=0.5" + ], + 0.4 + ], + [ + [ + "text/html;level=3", + "text/*;q=0.3, text/html;q=0.7, text/html;level=1, text/html;level=2;q=0.4, */*;q=0.5" + ], + 0.7 + ], + [ + [ + "text/plain", + "text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2" + ], + 0.2 + ] + ], -"best_match": [ - [[["application/xbel+xml", "application/xml"], "application/xbel+xml"], "application/xbel+xml", "direct match"], - [[["application/xbel+xml", "application/xml"], "application/xbel+xml; q=1"], "application/xbel+xml", "direct match with a q parameter"], - [[["application/xbel+xml", "application/xml"], "application/xml; q=1"], "application/xml", "direct match of our second choice with a q parameter"], - [[["application/xbel+xml", "application/xml"], "application/*; q=1"], "application/xml", "match using a subtype wildcard"], - [[["application/xbel+xml", "application/xml"], "*/*", "application/xml"], "application/xml", "match using a type wildcard"], - [[["application/xbel+xml", "text/xml"], "text/*;q=0.5,*/*; q=0.1"], "text/xml", "match using a type versus a lower weighted subtype"], - [[["application/xbel+xml", "text/xml"], "text/html,application/atom+xml; q=0.9"], "", "fail to match anything"], - [[["application/json", "text/html"], "application/json, text/javascript, */*"], "application/json", "common AJAX scenario"], - [[["application/json", "text/html"], "application/json, text/html;q=0.9"], "application/json", "verify fitness ordering"], - [[["image/*", "application/xml"], "image/png"], "image/*", "match using a type wildcard"], - [[["image/*", "application/xml"], "image/*"], "image/*", "match using a wildcard for both requested and supported"], - [[["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"], "image/jpeg", "media type with highest associated quality factor should win, not necessarily most specific"], - [[["text/html", "application/rdf+xml"], "text/html, application/rdf+xml"], "application/rdf+xml", "match should use highest order of supported when there is a tie"], - [[["application/rdf+xml", "text/html"], "text/html, application/rdf+xml"], "text/html", "match should use highest order of supported when there is a tie"], - [[["application/json", "text/html"], "text"], null, "match should use the default if an invalid Accept header is passed"] -], + "best_match": [ + [ + [ + ["application/json", "text/html"], + "application/json, text/javascript, */*" + ], + "application/json", + "common AJAX scenario" + ], + [ + [ + ["application/xbel+xml", "application/xml"], + "application/xbel+xml" + ], + "application/xbel+xml", + "direct match" + ], + [ + [ + ["application/xbel+xml", "application/xml"], + "application/xbel+xml; q=1" + ], + "application/xbel+xml", + "direct match with a q parameter" + ], + [ + [ + ["application/xbel+xml", "application/xml"], + "application/xml; q=1" + ], + "application/xml", + "direct match of our second choice with a q parameter" + ], + [ + [ + ["application/xbel+xml", "application/xml"], + "application/*; q=1" + ], + "application/xml", + "match using a subtype wildcard" + ], + [ + [ + ["application/xbel+xml", "application/xml"], + "*/*" + ], + "application/xml", + "match using a type wildcard" + ], + [ + [ + ["application/xbel+xml", "text/xml"], + "text/*;q=0.5,*/*; q=0.1" + ], + "text/xml", + "match using a type versus a lower weighted subtype" + ], + [ + [ + ["application/xbel+xml", "text/xml"], + "text/html,application/atom+xml; q=0.9" + ], + "", + "fail to match anything" + ], + [ + [ + ["application/json", "text/html"], + "application/json, text/html;q=0.9" + ], + "application/json", + "verify fitness ordering" + ], + [ + [ + ["image/*", "application/xml"], + "image/png" + ], + "image/*", + "match using a type wildcard" + ], + [ + [ + ["image/*", "application/xml"], + "image/*" + ], + "image/*", + "match using a wildcard for both requested and supported" + ], + [ + [ + ["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" + ], + "image/jpeg", + "media type with highest associated quality factor should win, not necessarily most specific" + ], + [ + [ + ["text/html", "application/rdf+xml"], + "text/html, application/rdf+xml" + ], + "application/rdf+xml", + "match should use highest order of supported when there is a tie" + ], + [ + [ + ["text/plain", "text/plain;format=flowed", "text/html"], + "text/*, text/plain, text/plain;format=flowed, */*" + ], + "text/plain;format=flowed", + "most specific reference has precedence" + ], + [ + [ + ["application/rdf+xml", "text/html"], + "text/html, application/rdf+xml" + ], + "text/html", + "match should use highest order of supported when there is a tie" + ], + [ + [ + ["application/json;q=1.0", "text/html;q=0.9", "text/plain;q=0.1"], + "*/*" + ], + "application/json;q=1.0", + "*/* match should pick an acceptable type with the highest quality" + ], + [ + [ + ["text/html;q=0.9", "application/json", "text/plain;q=0.1"], + "*/*" + ], + "application/json", + "*/* match should pick an acceptable type with the highest quality, even if it's implicit" + ], + [ + [ + ["application/json", "text/html"], + "text" + ], + null, + "match should use the default if an invalid Accept header is passed" + ] + ], -"parse_mime_type": [ - ["application/xhtml;q=0.5", ["application", "xhtml", {"q": "0.5"}]], - ["application/xhtml;q=0.5;ver=1.2", ["application", "xhtml", {"q": "0.5", "ver": "1.2"}]], - ["text", null], - ["text/something/invalid", null] -] + "parse_mime_type": [ + [ + "application/xhtml;q=0.5", + ["application", "xhtml", {"q": "0.5"}] + ], + [ + "application/xhtml;q=0.5;ver=1.2", + ["application", "xhtml", {"q": "0.5", "ver": "1.2"}] + ], + [ + "application/xhtml;q=0.5;foo=\"bar quux\"", + ["application", "xhtml", {"q": "0.5", "foo": "bar quux"}]], + [ + "text", null + ], + [ + "text/something/invalid", null + ] + ] }