summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason Madden <jamadden@gmail.com>2017-08-08 10:12:51 -0500
committerJason Madden <jamadden@gmail.com>2017-08-08 10:12:51 -0500
commit98b8b0b117fb5cbd38a794d97c83a1fa612edbae (patch)
treea91f5b32429d818a86518cdee11422dbce26f50d
parent8d6ed96b7718af5829bc03f7992432348c0b4396 (diff)
downloadzope-contenttype-docs.tar.gz
Enable Sphinx for RTDdocs
Also fix usage of zope.contenttype as a main module.
-rw-r--r--.gitignore1
-rw-r--r--CHANGES.rst2
-rw-r--r--MANIFEST.in4
-rw-r--r--README.rst14
-rw-r--r--docs/Makefile225
-rw-r--r--docs/api.rst33
-rw-r--r--docs/changelog.rst1
-rw-r--r--docs/conf.py366
-rw-r--r--docs/index.rst35
-rw-r--r--setup.py4
-rw-r--r--src/zope/contenttype/__init__.py32
-rw-r--r--src/zope/contenttype/__main__.py17
-rw-r--r--src/zope/contenttype/parse.py35
-rw-r--r--tox.ini6
14 files changed, 761 insertions, 14 deletions
diff --git a/.gitignore b/.gitignore
index 7663f4a..ad20d92 100644
--- a/.gitignore
+++ b/.gitignore
@@ -5,3 +5,4 @@
coverage.xml
nosetests.xml
htmlcov/
+docs/_build/
diff --git a/CHANGES.rst b/CHANGES.rst
index f6aeae9..686ee21 100644
--- a/CHANGES.rst
+++ b/CHANGES.rst
@@ -9,6 +9,8 @@
- Drop support for Python 3.3.
+- Host documentation at https://zopecontenttype.readthedocs.io
+
4.2.0 (2016-08-26)
==================
diff --git a/MANIFEST.in b/MANIFEST.in
index 670b350..30d8a08 100644
--- a/MANIFEST.in
+++ b/MANIFEST.in
@@ -9,4 +9,8 @@ exclude coverage.xml
recursive-include src *
+recursive-include docs *.py
+recursive-include docs *.rst
+recursive-include docs Makefile
+
global-exclude *.pyc
diff --git a/README.rst b/README.rst
index 1874241..bc38651 100644
--- a/README.rst
+++ b/README.rst
@@ -16,4 +16,16 @@
.. image:: https://coveralls.io/repos/github/zopefoundation/zope.contenttype/badge.svg?branch=master
:target: https://coveralls.io/github/zopefoundation/zope.contenttype?branch=master
-A utility module for content-type handling.
+.. image:: https://readthedocs.org/projects/zopecontenttype/badge/?version=latest
+ :target: https://zopecontenttype.readthedocs.io/en/latest/
+ :alt: Documentation Status
+
+A utility module for content-type (MIME type) handling.
+
+Functions include:
+
+- Guessing a content type given a name and (optional) body data.
+- Guessing a content type given some text.
+- Parsing MIME types.
+
+Documentation is hosted at https://zopecontenttype.readthedocs.io/en/latest/
diff --git a/docs/Makefile b/docs/Makefile
new file mode 100644
index 0000000..b44c7f7
--- /dev/null
+++ b/docs/Makefile
@@ -0,0 +1,225 @@
+# Makefile for Sphinx documentation
+#
+
+# You can set these variables from the command line.
+SPHINXOPTS =
+SPHINXBUILD = sphinx-build
+PAPER =
+BUILDDIR = _build
+
+# Internal variables.
+PAPEROPT_a4 = -D latex_paper_size=a4
+PAPEROPT_letter = -D latex_paper_size=letter
+ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) .
+# the i18n builder cannot share the environment and doctrees with the others
+I18NSPHINXOPTS = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) .
+
+.PHONY: help
+help:
+ @echo "Please use \`make <target>' where <target> is one of"
+ @echo " html to make standalone HTML files"
+ @echo " dirhtml to make HTML files named index.html in directories"
+ @echo " singlehtml to make a single large HTML file"
+ @echo " pickle to make pickle files"
+ @echo " json to make JSON files"
+ @echo " htmlhelp to make HTML files and a HTML help project"
+ @echo " qthelp to make HTML files and a qthelp project"
+ @echo " applehelp to make an Apple Help Book"
+ @echo " devhelp to make HTML files and a Devhelp project"
+ @echo " epub to make an epub"
+ @echo " epub3 to make an epub3"
+ @echo " latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter"
+ @echo " latexpdf to make LaTeX files and run them through pdflatex"
+ @echo " latexpdfja to make LaTeX files and run them through platex/dvipdfmx"
+ @echo " text to make text files"
+ @echo " man to make manual pages"
+ @echo " texinfo to make Texinfo files"
+ @echo " info to make Texinfo files and run them through makeinfo"
+ @echo " gettext to make PO message catalogs"
+ @echo " changes to make an overview of all changed/added/deprecated items"
+ @echo " xml to make Docutils-native XML files"
+ @echo " pseudoxml to make pseudoxml-XML files for display purposes"
+ @echo " linkcheck to check all external links for integrity"
+ @echo " doctest to run all doctests embedded in the documentation (if enabled)"
+ @echo " coverage to run coverage check of the documentation (if enabled)"
+ @echo " dummy to check syntax errors of document sources"
+
+.PHONY: clean
+clean:
+ rm -rf $(BUILDDIR)/*
+
+.PHONY: html
+html:
+ $(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html
+ @echo
+ @echo "Build finished. The HTML pages are in $(BUILDDIR)/html."
+
+.PHONY: dirhtml
+dirhtml:
+ $(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml
+ @echo
+ @echo "Build finished. The HTML pages are in $(BUILDDIR)/dirhtml."
+
+.PHONY: singlehtml
+singlehtml:
+ $(SPHINXBUILD) -b singlehtml $(ALLSPHINXOPTS) $(BUILDDIR)/singlehtml
+ @echo
+ @echo "Build finished. The HTML page is in $(BUILDDIR)/singlehtml."
+
+.PHONY: pickle
+pickle:
+ $(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) $(BUILDDIR)/pickle
+ @echo
+ @echo "Build finished; now you can process the pickle files."
+
+.PHONY: json
+json:
+ $(SPHINXBUILD) -b json $(ALLSPHINXOPTS) $(BUILDDIR)/json
+ @echo
+ @echo "Build finished; now you can process the JSON files."
+
+.PHONY: htmlhelp
+htmlhelp:
+ $(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) $(BUILDDIR)/htmlhelp
+ @echo
+ @echo "Build finished; now you can run HTML Help Workshop with the" \
+ ".hhp project file in $(BUILDDIR)/htmlhelp."
+
+.PHONY: qthelp
+qthelp:
+ $(SPHINXBUILD) -b qthelp $(ALLSPHINXOPTS) $(BUILDDIR)/qthelp
+ @echo
+ @echo "Build finished; now you can run "qcollectiongenerator" with the" \
+ ".qhcp project file in $(BUILDDIR)/qthelp, like this:"
+ @echo "# qcollectiongenerator $(BUILDDIR)/qthelp/zcintid.qhcp"
+ @echo "To view the help file:"
+ @echo "# assistant -collectionFile $(BUILDDIR)/qthelp/zcintid.qhc"
+
+.PHONY: applehelp
+applehelp:
+ $(SPHINXBUILD) -b applehelp $(ALLSPHINXOPTS) $(BUILDDIR)/applehelp
+ @echo
+ @echo "Build finished. The help book is in $(BUILDDIR)/applehelp."
+ @echo "N.B. You won't be able to view it unless you put it in" \
+ "~/Library/Documentation/Help or install it in your application" \
+ "bundle."
+
+.PHONY: devhelp
+devhelp:
+ $(SPHINXBUILD) -b devhelp $(ALLSPHINXOPTS) $(BUILDDIR)/devhelp
+ @echo
+ @echo "Build finished."
+ @echo "To view the help file:"
+ @echo "# mkdir -p $$HOME/.local/share/devhelp/zcintid"
+ @echo "# ln -s $(BUILDDIR)/devhelp $$HOME/.local/share/devhelp/zcintid"
+ @echo "# devhelp"
+
+.PHONY: epub
+epub:
+ $(SPHINXBUILD) -b epub $(ALLSPHINXOPTS) $(BUILDDIR)/epub
+ @echo
+ @echo "Build finished. The epub file is in $(BUILDDIR)/epub."
+
+.PHONY: epub3
+epub3:
+ $(SPHINXBUILD) -b epub3 $(ALLSPHINXOPTS) $(BUILDDIR)/epub3
+ @echo
+ @echo "Build finished. The epub3 file is in $(BUILDDIR)/epub3."
+
+.PHONY: latex
+latex:
+ $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex
+ @echo
+ @echo "Build finished; the LaTeX files are in $(BUILDDIR)/latex."
+ @echo "Run \`make' in that directory to run these through (pdf)latex" \
+ "(use \`make latexpdf' here to do that automatically)."
+
+.PHONY: latexpdf
+latexpdf:
+ $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex
+ @echo "Running LaTeX files through pdflatex..."
+ $(MAKE) -C $(BUILDDIR)/latex all-pdf
+ @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex."
+
+.PHONY: latexpdfja
+latexpdfja:
+ $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex
+ @echo "Running LaTeX files through platex and dvipdfmx..."
+ $(MAKE) -C $(BUILDDIR)/latex all-pdf-ja
+ @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex."
+
+.PHONY: text
+text:
+ $(SPHINXBUILD) -b text $(ALLSPHINXOPTS) $(BUILDDIR)/text
+ @echo
+ @echo "Build finished. The text files are in $(BUILDDIR)/text."
+
+.PHONY: man
+man:
+ $(SPHINXBUILD) -b man $(ALLSPHINXOPTS) $(BUILDDIR)/man
+ @echo
+ @echo "Build finished. The manual pages are in $(BUILDDIR)/man."
+
+.PHONY: texinfo
+texinfo:
+ $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo
+ @echo
+ @echo "Build finished. The Texinfo files are in $(BUILDDIR)/texinfo."
+ @echo "Run \`make' in that directory to run these through makeinfo" \
+ "(use \`make info' here to do that automatically)."
+
+.PHONY: info
+info:
+ $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo
+ @echo "Running Texinfo files through makeinfo..."
+ make -C $(BUILDDIR)/texinfo info
+ @echo "makeinfo finished; the Info files are in $(BUILDDIR)/texinfo."
+
+.PHONY: gettext
+gettext:
+ $(SPHINXBUILD) -b gettext $(I18NSPHINXOPTS) $(BUILDDIR)/locale
+ @echo
+ @echo "Build finished. The message catalogs are in $(BUILDDIR)/locale."
+
+.PHONY: changes
+changes:
+ $(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) $(BUILDDIR)/changes
+ @echo
+ @echo "The overview file is in $(BUILDDIR)/changes."
+
+.PHONY: linkcheck
+linkcheck:
+ $(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) $(BUILDDIR)/linkcheck
+ @echo
+ @echo "Link check complete; look for any errors in the above output " \
+ "or in $(BUILDDIR)/linkcheck/output.txt."
+
+.PHONY: doctest
+doctest:
+ $(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest
+ @echo "Testing of doctests in the sources finished, look at the " \
+ "results in $(BUILDDIR)/doctest/output.txt."
+
+.PHONY: coverage
+coverage:
+ $(SPHINXBUILD) -b coverage $(ALLSPHINXOPTS) $(BUILDDIR)/coverage
+ @echo "Testing of coverage in the sources finished, look at the " \
+ "results in $(BUILDDIR)/coverage/python.txt."
+
+.PHONY: xml
+xml:
+ $(SPHINXBUILD) -b xml $(ALLSPHINXOPTS) $(BUILDDIR)/xml
+ @echo
+ @echo "Build finished. The XML files are in $(BUILDDIR)/xml."
+
+.PHONY: pseudoxml
+pseudoxml:
+ $(SPHINXBUILD) -b pseudoxml $(ALLSPHINXOPTS) $(BUILDDIR)/pseudoxml
+ @echo
+ @echo "Build finished. The pseudo-XML files are in $(BUILDDIR)/pseudoxml."
+
+.PHONY: dummy
+dummy:
+ $(SPHINXBUILD) -b dummy $(ALLSPHINXOPTS) $(BUILDDIR)/dummy
+ @echo
+ @echo "Build finished. Dummy builder generates no files."
diff --git a/docs/api.rst b/docs/api.rst
new file mode 100644
index 0000000..d96b0fe
--- /dev/null
+++ b/docs/api.rst
@@ -0,0 +1,33 @@
+=====
+ API
+=====
+
+There are two major features provided by this package: determining
+content types, and parsing text representations of content types into
+structured data.
+
+.. currentmodule:: zope.contenttype
+
+.. note:: When this module is imported, it uses :func:`add_files` to
+ extend the standard :mod:`mimetypes` database with a set of common
+ office and multimedia types and filename extensions.
+
+.. tip:: When used as the main module (e.g., ``python -m
+ zope.contenttype``) this module will print out the
+ :mod:`mimetypes` database.
+
+Determining Content Types
+=========================
+
+.. autofunction:: guess_content_type
+.. autofunction:: text_type
+
+Utility Functions
+-----------------
+
+.. autofunction:: add_files
+
+Parsing Text Representations
+============================
+
+.. automodule:: zope.contenttype.parse
diff --git a/docs/changelog.rst b/docs/changelog.rst
new file mode 100644
index 0000000..d9e113e
--- /dev/null
+++ b/docs/changelog.rst
@@ -0,0 +1 @@
+.. include:: ../CHANGES.rst
diff --git a/docs/conf.py b/docs/conf.py
new file mode 100644
index 0000000..f1c8a08
--- /dev/null
+++ b/docs/conf.py
@@ -0,0 +1,366 @@
+# -*- coding: utf-8 -*-
+#
+# zope.app.apidoc documentation build configuration file, created by
+# sphinx-quickstart on Tue Sep 13 15:00:43 2016.
+#
+# This file is execfile()d with the current directory set to its
+# containing dir.
+#
+# Note that not all possible configuration values are present in this
+# autogenerated file.
+#
+# All configuration values have a default; values that are commented out
+# serve to show the default.
+
+# If extensions (or modules to document with autodoc) are in another directory,
+# add these directories to sys.path here. If the directory is relative to the
+# documentation root, use os.path.abspath to make it absolute, like shown here.
+#
+# import os
+# import sys
+# sys.path.insert(0, os.path.abspath('.'))
+import os
+import sys
+import pkg_resources
+sys.path.append(os.path.abspath('../src'))
+rqmt = pkg_resources.require('zope.contenttype')[0]
+
+# -- General configuration ------------------------------------------------
+
+# If your documentation needs a minimal Sphinx version, state it here.
+#
+# needs_sphinx = '1.0'
+
+# Add any Sphinx extension module names here, as strings. They can be
+# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
+# ones.
+extensions = [
+ 'sphinx.ext.autodoc',
+ 'sphinx.ext.intersphinx',
+ 'sphinx.ext.viewcode',
+ 'sphinx.ext.extlinks',
+]
+
+# Add any paths that contain templates here, relative to this directory.
+templates_path = ['_templates']
+
+# The suffix(es) of source filenames.
+# You can specify multiple suffix as a list of string:
+#
+# source_suffix = ['.rst', '.md']
+source_suffix = '.rst'
+
+# The encoding of source files.
+#
+# source_encoding = 'utf-8-sig'
+
+# The master toctree document.
+master_doc = 'index'
+
+# General information about the project.
+project = u'zope.contenttype'
+copyright = u'2017, Zope Community'
+author = u'Zope Community'
+
+# The version info for the project you're documenting, acts as replacement for
+# |version| and |release|, also used in various other places throughout the
+# built documents.
+#
+# The short X.Y version.
+version = '%s.%s' % tuple(map(int, rqmt.version.split('.')[:2]))
+# The full version, including alpha/beta/rc tags.
+release = rqmt.version
+
+# The language for content autogenerated by Sphinx. Refer to documentation
+# for a list of supported languages.
+#
+# This is also used if you do content translation via gettext catalogs.
+# Usually you set "language" from the command line for these cases.
+language = None
+
+# There are two options for replacing |today|: either, you set today to some
+# non-false value, then it is used:
+#
+# today = ''
+#
+# Else, today_fmt is used as the format for a strftime call.
+#
+# today_fmt = '%B %d, %Y'
+
+# List of patterns, relative to source directory, that match files and
+# directories to ignore when looking for source files.
+# This patterns also effect to html_static_path and html_extra_path
+exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
+
+# The reST default role (used for this markup: `text`) to use for all
+# documents.
+#
+# default_role = None
+
+# If true, '()' will be appended to :func: etc. cross-reference text.
+#
+# add_function_parentheses = True
+
+# If true, the current module name will be prepended to all description
+# unit titles (such as .. function::).
+#
+# add_module_names = True
+
+# If true, sectionauthor and moduleauthor directives will be shown in the
+# output. They are ignored by default.
+#
+# show_authors = False
+
+# The name of the Pygments (syntax highlighting) style to use.
+pygments_style = 'sphinx'
+
+# A list of ignored prefixes for module index sorting.
+# modindex_common_prefix = []
+
+# If true, keep warnings as "system message" paragraphs in the built documents.
+# keep_warnings = False
+
+# If true, `todo` and `todoList` produce output, else they produce nothing.
+todo_include_todos = False
+
+
+# -- Options for HTML output ----------------------------------------------
+
+# The theme to use for HTML and HTML Help pages. See the documentation for
+# a list of builtin themes.
+#
+html_theme = 'sphinx_rtd_theme'
+
+# Theme options are theme-specific and customize the look and feel of a theme
+# further. For a list of options available for each theme, see the
+# documentation.
+#
+# html_theme_options = {}
+
+# Add any paths that contain custom themes here, relative to this directory.
+# html_theme_path = []
+
+# The name for this set of Sphinx documents.
+# "<project> v<release> documentation" by default.
+#
+# html_title = u'zope.contenttype vXXX'
+
+# A shorter title for the navigation bar. Default is the same as html_title.
+#
+# html_short_title = None
+
+# The name of an image file (relative to this directory) to place at the top
+# of the sidebar.
+#
+# html_logo = None
+
+# The name of an image file (relative to this directory) to use as a favicon of
+# the docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32
+# pixels large.
+#
+# html_favicon = None
+
+# Add any paths that contain custom static files (such as style sheets) here,
+# relative to this directory. They are copied after the builtin static files,
+# so a file named "default.css" will overwrite the builtin "default.css".
+html_static_path = ['_static']
+
+# Add any extra paths that contain custom files (such as robots.txt or
+# .htaccess) here, relative to this directory. These files are copied
+# directly to the root of the documentation.
+#
+# html_extra_path = []
+
+# If not None, a 'Last updated on:' timestamp is inserted at every page
+# bottom, using the given strftime format.
+# The empty string is equivalent to '%b %d, %Y'.
+#
+# html_last_updated_fmt = None
+
+# If true, SmartyPants will be used to convert quotes and dashes to
+# typographically correct entities.
+#
+# html_use_smartypants = True
+
+# Custom sidebar templates, maps document names to template names.
+#
+# html_sidebars = {}
+
+# Additional templates that should be rendered to pages, maps page names to
+# template names.
+#
+# html_additional_pages = {}
+
+# If false, no module index is generated.
+#
+# html_domain_indices = True
+
+# If false, no index is generated.
+#
+# html_use_index = True
+
+# If true, the index is split into individual pages for each letter.
+#
+# html_split_index = False
+
+# If true, links to the reST sources are added to the pages.
+#
+# html_show_sourcelink = True
+
+# If true, "Created using Sphinx" is shown in the HTML footer. Default is True.
+#
+# html_show_sphinx = True
+
+# If true, "(C) Copyright ..." is shown in the HTML footer. Default is True.
+#
+# html_show_copyright = True
+
+# If true, an OpenSearch description file will be output, and all pages will
+# contain a <link> tag referring to it. The value of this option must be the
+# base URL from which the finished HTML is served.
+#
+# html_use_opensearch = ''
+
+# This is the file name suffix for HTML files (e.g. ".xhtml").
+# html_file_suffix = None
+
+# Language to be used for generating the HTML full-text search index.
+# Sphinx supports the following languages:
+# 'da', 'de', 'en', 'es', 'fi', 'fr', 'hu', 'it', 'ja'
+# 'nl', 'no', 'pt', 'ro', 'ru', 'sv', 'tr', 'zh'
+#
+# html_search_language = 'en'
+
+# A dictionary with options for the search language support, empty by default.
+# 'ja' uses this config value.
+# 'zh' user can custom change `jieba` dictionary path.
+#
+# html_search_options = {'type': 'default'}
+
+# The name of a javascript file (relative to the configuration directory) that
+# implements a search results scorer. If empty, the default will be used.
+#
+# html_search_scorer = 'scorer.js'
+
+# Output file base name for HTML help builder.
+htmlhelp_basename = 'zopecontenttype'
+
+# -- Options for LaTeX output ---------------------------------------------
+
+latex_elements = {
+ # The paper size ('letterpaper' or 'a4paper').
+ #
+ # 'papersize': 'letterpaper',
+
+ # The font size ('10pt', '11pt' or '12pt').
+ #
+ # 'pointsize': '10pt',
+
+ # Additional stuff for the LaTeX preamble.
+ #
+ # 'preamble': '',
+
+ # Latex figure (float) alignment
+ #
+ # 'figure_align': 'htbp',
+}
+
+# Grouping the document tree into LaTeX files. List of tuples
+# (source start file, target name, title,
+# author, documentclass [howto, manual, or own class]).
+latex_documents = [
+ (master_doc, 'zopecontenttype.tex', u'zope.contenttype Documentation',
+ u'Zope Community', 'manual'),
+]
+
+# The name of an image file (relative to this directory) to place at the top of
+# the title page.
+#
+# latex_logo = None
+
+# For "manual" documents, if this is true, then toplevel headings are parts,
+# not chapters.
+#
+# latex_use_parts = False
+
+# If true, show page references after internal links.
+#
+# latex_show_pagerefs = False
+
+# If true, show URL addresses after external links.
+#
+# latex_show_urls = False
+
+# Documents to append as an appendix to all manuals.
+#
+# latex_appendices = []
+
+# It false, will not define \strong, \code, itleref, \crossref ... but only
+# \sphinxstrong, ..., \sphinxtitleref, ... To help avoid clash with user added
+# packages.
+#
+# latex_keep_old_macro_names = True
+
+# If false, no module index is generated.
+#
+# latex_domain_indices = True
+
+
+# -- Options for manual page output ---------------------------------------
+
+# One entry per manual page. List of tuples
+# (source start file, name, description, authors, manual section).
+man_pages = [
+ (master_doc, 'zopecontenttype', u'zope.contenttype Documentation',
+ [author], 1)
+]
+
+# If true, show URL addresses after external links.
+#
+# man_show_urls = False
+
+
+# -- Options for Texinfo output -------------------------------------------
+
+# Grouping the document tree into Texinfo files. List of tuples
+# (source start file, target name, title, author,
+# dir menu entry, description, category)
+texinfo_documents = [
+ (master_doc, 'zopecontenttype', u'zope.contenttype Documentation',
+ author, 'zopecontenttype', 'One line description of project.',
+ 'Miscellaneous'),
+]
+
+# Documents to append as an appendix to all manuals.
+#
+# texinfo_appendices = []
+
+# If false, no module index is generated.
+#
+# texinfo_domain_indices = True
+
+# How to display URL addresses: 'footnote', 'no', or 'inline'.
+#
+# texinfo_show_urls = 'footnote'
+
+# If true, do not generate a @detailmenu in the "Top" node's menu.
+#
+# texinfo_no_detailmenu = False
+
+
+# Example configuration for intersphinx: refer to the Python standard library.
+intersphinx_mapping = {
+ 'https://docs.python.org/': None,
+}
+
+extlinks = {'issue': ('https://github.com/zopefoundation/zope.contenttype/issues/%s',
+ 'issue #'),
+ 'pr': ('https://github.com/zopefoundation/zope.contenttype/pull/%s',
+ 'pull request #')}
+
+autodoc_default_flags = [
+ 'members',
+ 'show-inheritance',
+]
+autoclass_content = 'both'
+autodoc_member_order = 'bysource'
diff --git a/docs/index.rst b/docs/index.rst
new file mode 100644
index 0000000..9a9c86c
--- /dev/null
+++ b/docs/index.rst
@@ -0,0 +1,35 @@
+.. include:: ../README.rst
+
+.. toctree::
+ :maxdepth: 2
+
+ api
+
+
+.. toctree::
+ :maxdepth: 2
+
+ changelog
+
+Development
+===========
+
+zope.contenttype is hosted at GitHub:
+
+ https://github.com/zopefoundation/zope.contenttype/
+
+
+
+Project URLs
+============
+
+* https://pypi.python.org/pypi/zope.contenttype (PyPI entry and downloads)
+
+
+====================
+ Indices and tables
+====================
+
+* :ref:`genindex`
+* :ref:`modindex`
+* :ref:`search`
diff --git a/setup.py b/setup.py
index 1846a36..79f6f10 100644
--- a/setup.py
+++ b/setup.py
@@ -67,6 +67,10 @@ setup(
tests_require=TESTS_REQUIRE,
extras_require={
'test': TESTS_REQUIRE,
+ 'docs': [
+ 'Sphinx',
+ 'sphinx_rtd_theme',
+ ],
},
include_package_data=True,
zip_safe=False,
diff --git a/src/zope/contenttype/__init__.py b/src/zope/contenttype/__init__.py
index 9208bbd..e2bac7f 100644
--- a/src/zope/contenttype/__init__.py
+++ b/src/zope/contenttype/__init__.py
@@ -21,10 +21,15 @@ find_binary = re.compile(b'[\0-\7]').search
def text_type(s):
- """Given an unnamed piece of text, try to guess its content type.
+ """
+ Given an unnamed piece of data, try to guess its content type.
+
+ Detects HTML, XML, and plain text.
- Detects HTML, XML, and plain text. Returns a MIME type string
- such as 'text/html'.
+ :return: A MIME type string such as 'text/html'.
+ :rtype: str
+
+ :param bytes s: The binary data to examine.
"""
# at least the maximum length of any tags we look for
max_tags = 14
@@ -50,13 +55,20 @@ def text_type(s):
def guess_content_type(name='', body=b'', default=None):
- """Given a named piece of content, try to guess its content type.
+ """
+ Given a named piece of content, try to guess its content type.
- The implementation relies on the 'mimetypes' standard Python module,
- the 'text_type' function also defined in this module, and a simple
+ The implementation relies on the :mod:`mimetypes` standard Python module,
+ the :func:`text_type` function also defined in this module, and a simple
heuristic for detecting binary data.
- Returns a MIME type string such as "text/html".
+ :return: A tuple of ``(type, encoding)`` like :func:`mimetypes.guess_type`.
+
+ :keyword str name: The file name for the content. This is given priority
+ when guessing the type.
+ :keyword bytes body: The binary data of the content.
+ :keyword str default: If given, and no content type can be guessed, this
+ will be returned as the ``type`` portion.
"""
# Attempt to determine the content type (and possibly
# content-encoding) based on an an object's name and
@@ -76,7 +88,8 @@ def guess_content_type(name='', body=b'', default=None):
def add_files(filenames):
- """Add the names of MIME type map files to the standard 'mimetypes' module.
+ """
+ Add the names of MIME type map files to the standard :mod:`mimetypes` module.
MIME type map files are used for detecting the MIME type of some content
based on the content's filename extension.
@@ -111,6 +124,3 @@ def main():
items = sorted(items)
for item in items:
print("%s:\t%s" % item)
-
-if __name__ == '__main__':
- main()
diff --git a/src/zope/contenttype/__main__.py b/src/zope/contenttype/__main__.py
new file mode 100644
index 0000000..266023c
--- /dev/null
+++ b/src/zope/contenttype/__main__.py
@@ -0,0 +1,17 @@
+##############################################################################
+#
+# Copyright (c) 2017 Zope Foundation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+
+if __name__ == '__main__':
+ import zope.contenttype
+ zope.contenttype.main()
diff --git a/src/zope/contenttype/parse.py b/src/zope/contenttype/parse.py
index 0436cc4..8658c34 100644
--- a/src/zope/contenttype/parse.py
+++ b/src/zope/contenttype/parse.py
@@ -13,8 +13,11 @@
##############################################################################
"""MIME Content-Type parsing helper functions.
-This supports parsing RFC 1341 Content-Type values, including
-quoted-string values as defined in RFC 822.
+This supports parsing `RFC 1341`_ Content-Type values, including
+quoted-string values as defined in `RFC 822`_.
+
+.. _RFC 1341: https://tools.ietf.org/html/rfc1341
+.. _RFC 822: https://tools.ietf.org/html/rfc822
"""
__docformat__ = "reStructuredText"
@@ -27,6 +30,17 @@ import re
def parse(string):
+ """
+ Parse the given string as a MIME type.
+
+ This uses :func:`parseOrdered` and can raise the same
+ exceptions it does.
+
+ :return: A tuple ``(major, minor, params)`` where ``major``
+ and ``minor`` are the two parts of the type, and ``params``
+ is a dictionary containing any parameters by name.
+ :param str string: The string to parse.
+ """
major, minor, params = parseOrdered(string)
d = {}
for (name, value) in params:
@@ -34,6 +48,15 @@ def parse(string):
return major, minor, d
def parseOrdered(string):
+ """
+ Parse the given string as a MIME type.
+
+ :return: A tuple ``(major, minor, params)`` where ``major``
+ and ``minor`` are the two parts of the type, and ``params`` is a
+ sequence of the parameters in order.
+ :raises ValueError: If the *string* is malformed.
+ :param str string: The string to parse.
+ """
if ";" in string:
type, params = string.split(";", 1)
params = _parse_params(params)
@@ -105,6 +128,14 @@ def _unescape(string):
def join(spec):
+ """
+ Given a three-part tuple as produced by :func:`parse` or :func:`parseOrdered`,
+ return the string representation.
+
+ :returns: The string representation. For example, given ``('text',
+ 'plain', [('encoding','utf-8')])``, this will produce ``'text/plain;encoding=utf-8'``.
+ :rtype: str
+ """
(major, minor, params) = spec
pstr = ""
try:
diff --git a/tox.ini b/tox.ini
index 514924e..eefe0cb 100644
--- a/tox.ini
+++ b/tox.ini
@@ -18,3 +18,9 @@ commands =
deps =
{[testenv]deps}
coverage
+
+[testenv:docs]
+commands =
+ sphinx-build -b html -d docs/_build/doctrees docs docs/_build/html
+deps =
+ .[docs]