You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

66 lines
1.6KB

  1. Python-MimeParse
  2. ================
  3. .. image:: https://travis-ci.org/dbtsai/python-mimeparse.svg?branch=master
  4. :target: https://travis-ci.org/dbtsai/python-mimeparse
  5. This module provides basic functions for handling mime-types. It can
  6. handle matching mime-types against a list of media-ranges. See section
  7. 5.3.2 of the HTTP 1.1 Semantics and Content specification [RFC 7231] for
  8. a complete explanation: https://tools.ietf.org/html/rfc7231#section-5.3.2
  9. Installation
  10. ------------
  11. Use **pip**:
  12. .. code-block:: sh
  13. $ pip install python-mimeparse
  14. It supports Python 2.7 - 3.5 and PyPy.
  15. Functions
  16. ---------
  17. **parse_mime_type()**
  18. Parses a mime-type into its component parts.
  19. **parse_media_range()**
  20. Media-ranges are mime-types with wild-cards and a "q" quality parameter.
  21. **quality()**
  22. Determines the quality ("q") of a mime-type when compared against a list of
  23. media-ranges.
  24. **quality_parsed()**
  25. Just like ``quality()`` except the second parameter must be pre-parsed.
  26. **best_match()**
  27. Choose the mime-type with the highest quality ("q") from a list of candidates.
  28. Testing
  29. -------
  30. Run the tests by typing: ``python mimeparse_test.py``. The tests require Python 2.6.
  31. To make sure that the package works in all the supported environments, you can
  32. run **tox** tests:
  33. .. code-block:: sh
  34. $ pip install tox
  35. $ tox
  36. The format of the JSON test data file is as follows: A top-level JSON object
  37. which has a key for each of the functions to be tested. The value corresponding
  38. to that key is a list of tests. Each test contains: the argument or arguments
  39. to the function being tested, the expected results and an optional description.