--- a/.hgignore Mon Jan 05 12:02:01 2015 +0100
+++ b/.hgignore Sat Jan 03 22:06:03 2015 +0100
@@ -5,4 +5,5 @@
*.egg-info
+docs/_build
pyramid_cubicweb/tests/data/database
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/docs/Makefile Sat Jan 03 22:06:03 2015 +0100
@@ -0,0 +1,177 @@
+# Makefile for Sphinx documentation
+#
+
+# You can set these variables from the command line.
+SPHINXOPTS =
+SPHINXBUILD = sphinx-build
+PAPER =
+BUILDDIR = _build
+
+# User-friendly check for sphinx-build
+ifeq ($(shell which $(SPHINXBUILD) >/dev/null 2>&1; echo $$?), 1)
+$(error The '$(SPHINXBUILD)' command was not found. Make sure you have Sphinx installed, then set the SPHINXBUILD environment variable to point to the full path of the '$(SPHINXBUILD)' executable. Alternatively you can add the directory with the executable to your PATH. If you don't have Sphinx installed, grab it from http://sphinx-doc.org/)
+endif
+
+# 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 clean html dirhtml singlehtml pickle json htmlhelp qthelp devhelp epub latex latexpdf text man changes linkcheck doctest gettext
+
+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 " devhelp to make HTML files and a Devhelp project"
+ @echo " epub to make an epub"
+ @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)"
+
+clean:
+ rm -rf $(BUILDDIR)/*
+
+html:
+ $(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html
+ @echo
+ @echo "Build finished. The HTML pages are in $(BUILDDIR)/html."
+
+dirhtml:
+ $(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml
+ @echo
+ @echo "Build finished. The HTML pages are in $(BUILDDIR)/dirhtml."
+
+singlehtml:
+ $(SPHINXBUILD) -b singlehtml $(ALLSPHINXOPTS) $(BUILDDIR)/singlehtml
+ @echo
+ @echo "Build finished. The HTML page is in $(BUILDDIR)/singlehtml."
+
+pickle:
+ $(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) $(BUILDDIR)/pickle
+ @echo
+ @echo "Build finished; now you can process the pickle files."
+
+json:
+ $(SPHINXBUILD) -b json $(ALLSPHINXOPTS) $(BUILDDIR)/json
+ @echo
+ @echo "Build finished; now you can process the JSON files."
+
+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."
+
+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/PyramidCubicweb.qhcp"
+ @echo "To view the help file:"
+ @echo "# assistant -collectionFile $(BUILDDIR)/qthelp/PyramidCubicweb.qhc"
+
+devhelp:
+ $(SPHINXBUILD) -b devhelp $(ALLSPHINXOPTS) $(BUILDDIR)/devhelp
+ @echo
+ @echo "Build finished."
+ @echo "To view the help file:"
+ @echo "# mkdir -p $$HOME/.local/share/devhelp/PyramidCubicweb"
+ @echo "# ln -s $(BUILDDIR)/devhelp $$HOME/.local/share/devhelp/PyramidCubicweb"
+ @echo "# devhelp"
+
+epub:
+ $(SPHINXBUILD) -b epub $(ALLSPHINXOPTS) $(BUILDDIR)/epub
+ @echo
+ @echo "Build finished. The epub file is in $(BUILDDIR)/epub."
+
+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)."
+
+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."
+
+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."
+
+text:
+ $(SPHINXBUILD) -b text $(ALLSPHINXOPTS) $(BUILDDIR)/text
+ @echo
+ @echo "Build finished. The text files are in $(BUILDDIR)/text."
+
+man:
+ $(SPHINXBUILD) -b man $(ALLSPHINXOPTS) $(BUILDDIR)/man
+ @echo
+ @echo "Build finished. The manual pages are in $(BUILDDIR)/man."
+
+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)."
+
+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."
+
+gettext:
+ $(SPHINXBUILD) -b gettext $(I18NSPHINXOPTS) $(BUILDDIR)/locale
+ @echo
+ @echo "Build finished. The message catalogs are in $(BUILDDIR)/locale."
+
+changes:
+ $(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) $(BUILDDIR)/changes
+ @echo
+ @echo "The overview file is in $(BUILDDIR)/changes."
+
+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."
+
+doctest:
+ $(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest
+ @echo "Testing of doctests in the sources finished, look at the " \
+ "results in $(BUILDDIR)/doctest/output.txt."
+
+xml:
+ $(SPHINXBUILD) -b xml $(ALLSPHINXOPTS) $(BUILDDIR)/xml
+ @echo
+ @echo "Build finished. The XML files are in $(BUILDDIR)/xml."
+
+pseudoxml:
+ $(SPHINXBUILD) -b pseudoxml $(ALLSPHINXOPTS) $(BUILDDIR)/pseudoxml
+ @echo
+ @echo "Build finished. The pseudo-XML files are in $(BUILDDIR)/pseudoxml."
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/docs/api.rst Sat Jan 03 22:06:03 2015 +0100
@@ -0,0 +1,17 @@
+:mod:`pyramid_cubicweb`
+=======================
+
+.. automodule:: pyramid_cubicweb
+
+ .. autofunction:: make_cubicweb_application
+
+ .. autofunction:: wsgi_application_from_cwconfig
+
+ .. autofunction:: wsgi_application
+
+.. toctree::
+ :maxdepth: 1
+ :glob:
+
+ api/*
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/docs/api/auth.rst Sat Jan 03 22:06:03 2015 +0100
@@ -0,0 +1,12 @@
+.. _auth_module:
+
+:mod:`pyramid_cubicweb.auth`
+----------------------------
+
+.. automodule:: pyramid_cubicweb.auth
+
+ .. autofunction:: includeme
+
+ .. autoclass:: CubicWebAuthTktAuthenticationPolicy
+ :show-inheritance:
+ :members:
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/docs/api/authplugin.rst Sat Jan 03 22:06:03 2015 +0100
@@ -0,0 +1,10 @@
+.. _authplugin_module:
+
+:mod:`pyramid_cubicweb.authplugin`
+----------------------------------
+
+.. automodule:: pyramid_cubicweb.authplugin
+
+ .. autoclass:: DirectAuthentifier
+ :show-inheritance:
+ :members:
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/docs/api/bwcompat.rst Sat Jan 03 22:06:03 2015 +0100
@@ -0,0 +1,19 @@
+.. _bwcompat_module:
+
+:mod:`pyramid_cubicweb.bwcompat`
+--------------------------------
+
+.. automodule:: pyramid_cubicweb.bwcompat
+
+ .. autofunction:: includeme
+
+ .. autoclass:: PyramidSessionHandler
+ :members:
+
+ .. autoclass:: CubicWebPyramidHandler
+ :members:
+
+ .. automethod:: __call__
+
+ .. autoclass:: TweenHandler
+ :members:
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/docs/api/core.rst Sat Jan 03 22:06:03 2015 +0100
@@ -0,0 +1,23 @@
+.. _core_module:
+
+:mod:`pyramid_cubicweb.core`
+----------------------------
+
+.. automodule:: pyramid_cubicweb.core
+
+ .. autofunction:: includeme
+
+ .. autofunction:: cw_to_pyramid
+
+ .. autofunction:: render_view
+
+ .. autofunction:: repo_connect
+ .. autofunction:: get_principals
+
+ .. autoclass:: CubicWebPyramidRequest
+ :show-inheritance:
+ :members:
+
+ .. autofunction:: _cw_session
+ .. autofunction:: _cw_cnx
+ .. autofunction:: _cw_request
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/docs/api/defaults.rst Sat Jan 03 22:06:03 2015 +0100
@@ -0,0 +1,8 @@
+.. _defaults_module:
+
+:mod:`pyramid_cubicweb.defaults`
+--------------------------------
+
+.. automodule:: pyramid_cubicweb.defaults
+
+ .. autofunction:: includeme
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/docs/api/login.rst Sat Jan 03 22:06:03 2015 +0100
@@ -0,0 +1,16 @@
+.. _login_module:
+
+:mod:`pyramid_cubicweb.login`
+-----------------------------
+
+.. automodule:: pyramid_cubicweb.login
+
+ .. autofunction:: includeme
+
+
+ Views
+ -----
+
+ .. autofunction:: login_form
+ .. autofunction:: login_password_login
+ .. autofunction:: login_already_loggedin
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/docs/api/profile.rst Sat Jan 03 22:06:03 2015 +0100
@@ -0,0 +1,19 @@
+.. _profile_module:
+
+:mod:`pyramid_cubicweb.profile`
+===============================
+
+.. automodule:: pyramid_cubicweb.profile
+
+ Views
+ -----
+
+ .. autofunction:: ping
+
+ .. autofunction:: cnx
+
+ WSGI
+ ----
+
+ .. autofunction:: wsgi_profile
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/docs/api/session.rst Sat Jan 03 22:06:03 2015 +0100
@@ -0,0 +1,10 @@
+.. _session_module:
+
+:mod:`pyramid_cubicweb.session`
+-------------------------------
+
+.. automodule:: pyramid_cubicweb.session
+
+ .. autofunction:: includeme
+
+ .. autofunction:: CWSessionFactory
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/docs/conf.py Sat Jan 03 22:06:03 2015 +0100
@@ -0,0 +1,283 @@
+# -*- coding: utf-8 -*-
+#
+# Pyramid Cubicweb documentation build configuration file, created by
+# sphinx-quickstart on Sat Jan 3 21:00:05 2015.
+#
+# 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.
+
+import sys
+import os
+
+# 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.
+#sys.path.insert(0, os.path.abspath('.'))
+
+# -- 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.coverage',
+ 'sphinx.ext.viewcode',
+]
+
+# Add any paths that contain templates here, relative to this directory.
+templates_path = ['_templates']
+
+# The suffix of source filenames.
+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'Pyramid Cubicweb'
+copyright = u'2015, Christophe de Vienne'
+
+# 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.
+import pkg_resources
+
+d = pkg_resources.require('pyramid_cubicweb')
+
+version = d[0].version.split('.')[:2]
+
+# The full version, including alpha/beta/rc tags.
+release = d[0].version
+
+# The language for content autogenerated by Sphinx. Refer to documentation
+# for a list of supported languages.
+#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.
+exclude_patterns = ['_build']
+
+# 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
+
+
+# -- Options for HTML output ----------------------------------------------
+
+# The theme to use for HTML and HTML Help pages. See the documentation for
+# a list of builtin themes.
+import sphinx_rtd_theme
+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 = [sphinx_rtd_theme.get_html_theme_path()]
+
+# The name for this set of Sphinx documents. If None, it defaults to
+# "<project> v<release> documentation".
+#html_title = None
+
+# 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 (within the static path) to use as 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 '', a 'Last updated on:' timestamp is inserted at every page bottom,
+# using the given strftime format.
+#html_last_updated_fmt = '%b %d, %Y'
+
+# 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
+
+# Output file base name for HTML help builder.
+htmlhelp_basename = 'PyramidCubicwebdoc'
+
+
+# -- 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': '',
+}
+
+# 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 = [
+ ('index', 'PyramidCubicweb.tex', u'Pyramid Cubicweb Documentation',
+ u'Christophe de Vienne', '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 = []
+
+# 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 = [
+ ('index', 'pyramidcubicweb', u'Pyramid Cubicweb Documentation',
+ [u'Christophe de Vienne'], 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 = [
+ ('index', 'PyramidCubicweb', u'Pyramid Cubicweb Documentation',
+ u'Christophe de Vienne', 'PyramidCubicweb', '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 = {
+ 'http://docs.python.org/': None,
+ 'http://pyramid.readthedocs.org/en/latest/': None,
+ 'http://docs.cubicweb.org/': None
+}
+
+
+def setup(app):
+ app.add_object_type('confval', 'confval',
+ objname='configuration value',
+ indextemplate='pair: %s; configuration value')
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/docs/index.rst Sat Jan 03 22:06:03 2015 +0100
@@ -0,0 +1,45 @@
+================
+Pyramid Cubicweb
+================
+
+Pyramid Cubicweb is an attempt to rebase the CubicWeb_ framework on pyramid.
+
+It can be used in two different ways:
+
+- Within CubicWeb, through the 'pyramid' cube and the
+ :ref:`pyramid command <cubicweb-ctl_pyramid>`.
+ In this mode, the Pyramid CubicWeb replaces some parts of
+ CubicWeb and make the pyramid api available to the cubes.
+
+- Within a pyramid application, it provides easy access to a CubicWeb
+ instance and registry.
+
+Narrative Documentation
+=======================
+
+.. toctree::
+ :maxdepth: 2
+
+ narr/quickstart
+ narr/ctl
+ narr/settings
+ narr/profiling
+
+Api Documentation
+=================
+
+.. toctree::
+ :maxdepth: 2
+ :glob:
+
+ api
+
+Indices and tables
+==================
+
+* :ref:`genindex`
+* :ref:`modindex`
+* :ref:`search`
+
+
+.. _CubicWeb: http://www.cubicweb.org/
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/docs/make.bat Sat Jan 03 22:06:03 2015 +0100
@@ -0,0 +1,242 @@
+@ECHO OFF
+
+REM Command file for Sphinx documentation
+
+if "%SPHINXBUILD%" == "" (
+ set SPHINXBUILD=sphinx-build
+)
+set BUILDDIR=_build
+set ALLSPHINXOPTS=-d %BUILDDIR%/doctrees %SPHINXOPTS% .
+set I18NSPHINXOPTS=%SPHINXOPTS% .
+if NOT "%PAPER%" == "" (
+ set ALLSPHINXOPTS=-D latex_paper_size=%PAPER% %ALLSPHINXOPTS%
+ set I18NSPHINXOPTS=-D latex_paper_size=%PAPER% %I18NSPHINXOPTS%
+)
+
+if "%1" == "" goto help
+
+if "%1" == "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. devhelp to make HTML files and a Devhelp project
+ echo. epub to make an epub
+ echo. latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter
+ echo. text to make text files
+ echo. man to make manual pages
+ echo. texinfo to make Texinfo files
+ echo. gettext to make PO message catalogs
+ echo. changes to make an overview over 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
+ goto end
+)
+
+if "%1" == "clean" (
+ for /d %%i in (%BUILDDIR%\*) do rmdir /q /s %%i
+ del /q /s %BUILDDIR%\*
+ goto end
+)
+
+
+%SPHINXBUILD% 2> nul
+if errorlevel 9009 (
+ echo.
+ echo.The 'sphinx-build' command was not found. Make sure you have Sphinx
+ echo.installed, then set the SPHINXBUILD environment variable to point
+ echo.to the full path of the 'sphinx-build' executable. Alternatively you
+ echo.may add the Sphinx directory to PATH.
+ echo.
+ echo.If you don't have Sphinx installed, grab it from
+ echo.http://sphinx-doc.org/
+ exit /b 1
+)
+
+if "%1" == "html" (
+ %SPHINXBUILD% -b html %ALLSPHINXOPTS% %BUILDDIR%/html
+ if errorlevel 1 exit /b 1
+ echo.
+ echo.Build finished. The HTML pages are in %BUILDDIR%/html.
+ goto end
+)
+
+if "%1" == "dirhtml" (
+ %SPHINXBUILD% -b dirhtml %ALLSPHINXOPTS% %BUILDDIR%/dirhtml
+ if errorlevel 1 exit /b 1
+ echo.
+ echo.Build finished. The HTML pages are in %BUILDDIR%/dirhtml.
+ goto end
+)
+
+if "%1" == "singlehtml" (
+ %SPHINXBUILD% -b singlehtml %ALLSPHINXOPTS% %BUILDDIR%/singlehtml
+ if errorlevel 1 exit /b 1
+ echo.
+ echo.Build finished. The HTML pages are in %BUILDDIR%/singlehtml.
+ goto end
+)
+
+if "%1" == "pickle" (
+ %SPHINXBUILD% -b pickle %ALLSPHINXOPTS% %BUILDDIR%/pickle
+ if errorlevel 1 exit /b 1
+ echo.
+ echo.Build finished; now you can process the pickle files.
+ goto end
+)
+
+if "%1" == "json" (
+ %SPHINXBUILD% -b json %ALLSPHINXOPTS% %BUILDDIR%/json
+ if errorlevel 1 exit /b 1
+ echo.
+ echo.Build finished; now you can process the JSON files.
+ goto end
+)
+
+if "%1" == "htmlhelp" (
+ %SPHINXBUILD% -b htmlhelp %ALLSPHINXOPTS% %BUILDDIR%/htmlhelp
+ if errorlevel 1 exit /b 1
+ echo.
+ echo.Build finished; now you can run HTML Help Workshop with the ^
+.hhp project file in %BUILDDIR%/htmlhelp.
+ goto end
+)
+
+if "%1" == "qthelp" (
+ %SPHINXBUILD% -b qthelp %ALLSPHINXOPTS% %BUILDDIR%/qthelp
+ if errorlevel 1 exit /b 1
+ echo.
+ echo.Build finished; now you can run "qcollectiongenerator" with the ^
+.qhcp project file in %BUILDDIR%/qthelp, like this:
+ echo.^> qcollectiongenerator %BUILDDIR%\qthelp\PyramidCubicweb.qhcp
+ echo.To view the help file:
+ echo.^> assistant -collectionFile %BUILDDIR%\qthelp\PyramidCubicweb.ghc
+ goto end
+)
+
+if "%1" == "devhelp" (
+ %SPHINXBUILD% -b devhelp %ALLSPHINXOPTS% %BUILDDIR%/devhelp
+ if errorlevel 1 exit /b 1
+ echo.
+ echo.Build finished.
+ goto end
+)
+
+if "%1" == "epub" (
+ %SPHINXBUILD% -b epub %ALLSPHINXOPTS% %BUILDDIR%/epub
+ if errorlevel 1 exit /b 1
+ echo.
+ echo.Build finished. The epub file is in %BUILDDIR%/epub.
+ goto end
+)
+
+if "%1" == "latex" (
+ %SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex
+ if errorlevel 1 exit /b 1
+ echo.
+ echo.Build finished; the LaTeX files are in %BUILDDIR%/latex.
+ goto end
+)
+
+if "%1" == "latexpdf" (
+ %SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex
+ cd %BUILDDIR%/latex
+ make all-pdf
+ cd %BUILDDIR%/..
+ echo.
+ echo.Build finished; the PDF files are in %BUILDDIR%/latex.
+ goto end
+)
+
+if "%1" == "latexpdfja" (
+ %SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex
+ cd %BUILDDIR%/latex
+ make all-pdf-ja
+ cd %BUILDDIR%/..
+ echo.
+ echo.Build finished; the PDF files are in %BUILDDIR%/latex.
+ goto end
+)
+
+if "%1" == "text" (
+ %SPHINXBUILD% -b text %ALLSPHINXOPTS% %BUILDDIR%/text
+ if errorlevel 1 exit /b 1
+ echo.
+ echo.Build finished. The text files are in %BUILDDIR%/text.
+ goto end
+)
+
+if "%1" == "man" (
+ %SPHINXBUILD% -b man %ALLSPHINXOPTS% %BUILDDIR%/man
+ if errorlevel 1 exit /b 1
+ echo.
+ echo.Build finished. The manual pages are in %BUILDDIR%/man.
+ goto end
+)
+
+if "%1" == "texinfo" (
+ %SPHINXBUILD% -b texinfo %ALLSPHINXOPTS% %BUILDDIR%/texinfo
+ if errorlevel 1 exit /b 1
+ echo.
+ echo.Build finished. The Texinfo files are in %BUILDDIR%/texinfo.
+ goto end
+)
+
+if "%1" == "gettext" (
+ %SPHINXBUILD% -b gettext %I18NSPHINXOPTS% %BUILDDIR%/locale
+ if errorlevel 1 exit /b 1
+ echo.
+ echo.Build finished. The message catalogs are in %BUILDDIR%/locale.
+ goto end
+)
+
+if "%1" == "changes" (
+ %SPHINXBUILD% -b changes %ALLSPHINXOPTS% %BUILDDIR%/changes
+ if errorlevel 1 exit /b 1
+ echo.
+ echo.The overview file is in %BUILDDIR%/changes.
+ goto end
+)
+
+if "%1" == "linkcheck" (
+ %SPHINXBUILD% -b linkcheck %ALLSPHINXOPTS% %BUILDDIR%/linkcheck
+ if errorlevel 1 exit /b 1
+ echo.
+ echo.Link check complete; look for any errors in the above output ^
+or in %BUILDDIR%/linkcheck/output.txt.
+ goto end
+)
+
+if "%1" == "doctest" (
+ %SPHINXBUILD% -b doctest %ALLSPHINXOPTS% %BUILDDIR%/doctest
+ if errorlevel 1 exit /b 1
+ echo.
+ echo.Testing of doctests in the sources finished, look at the ^
+results in %BUILDDIR%/doctest/output.txt.
+ goto end
+)
+
+if "%1" == "xml" (
+ %SPHINXBUILD% -b xml %ALLSPHINXOPTS% %BUILDDIR%/xml
+ if errorlevel 1 exit /b 1
+ echo.
+ echo.Build finished. The XML files are in %BUILDDIR%/xml.
+ goto end
+)
+
+if "%1" == "pseudoxml" (
+ %SPHINXBUILD% -b pseudoxml %ALLSPHINXOPTS% %BUILDDIR%/pseudoxml
+ if errorlevel 1 exit /b 1
+ echo.
+ echo.Build finished. The pseudo-XML files are in %BUILDDIR%/pseudoxml.
+ goto end
+)
+
+:end
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/docs/narr/ctl.rst Sat Jan 03 22:06:03 2015 +0100
@@ -0,0 +1,55 @@
+.. _cubicweb-ctl_pyramid:
+
+The 'pyramid' command
+=====================
+
+.. program:: cubicweb-ctl pyramid
+
+The 'pyramid' command is a replacement for the 'start' command of :ref:`cubicweb-ctl`.
+It provides the same options and a few other ones.
+
+.. note::
+
+ The 'pyramid' command is provided by the ``pyramid`` cube.
+
+Options
+-------
+
+
+.. option:: --no-daemon
+
+ Run the server in the foreground.
+
+
+.. option:: --debug-mode
+
+ Activate the repository debug mode (logs in the console and the debug
+ toolbar). Implies :option:`--no-daemon`
+
+.. option:: -D, --debug
+
+ Equals to :option:`--debug-mode` :option:`--no-daemon` :option:`--reload`
+
+.. option:: --reload
+
+ Restart the server if any source file is changed
+
+.. option:: --reload-interval=RELOAD_INTERVAL
+
+ Interval, in seconds, between file modifications checks [current: 1]
+
+.. option:: -l <log level>, --loglevel=<log level>
+
+ Set the loglevel. debug if -D is set, error otherwise
+
+.. option:: -p, --profile
+
+ Enable profiling. See :ref:`profiling`.
+
+.. option:: --profile-output=PROFILE_OUTPUT
+
+ Profiling output file (default: "program.prof")
+
+.. option:: --profile-dump-every=N
+
+ Dump profile stats to ouput every N requests (default: 100)
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/docs/narr/profiling.rst Sat Jan 03 22:06:03 2015 +0100
@@ -0,0 +1,52 @@
+.. _profiling:
+
+Profiling
+=========
+
+Profiling of requests by the pyramid debug toolbar can be a little restrictive
+when a specific url needs thin profiling that includes the whole pyramid
+dispatch.
+
+Pyramid CubicWeb provides facilities to profile requests as a
+:func:`wsgi middleware <pyramid_cubicweb.profile.wsgi_profile>`, and a few
+views that facilitate profiling of basic features.
+
+The views and the wsgi middleware are activated when the 'profile' option is
+given. This can be done on the command line
+(:option:`cubicweb-ctl pyramid --profile`) or in the :ref:`pyramid_settings`.
+
+Views
+-----
+
+The following routes and corresponding views are provided when profiling is on:
+
+- ``/_profile/ping``: Reply 'ping' without doing anything else. See also
+ :func:`pyramid_cubicweb.profile.ping`.
+
+- ``/_profile/cnx``: Reply 'ping' after getting a cnx. See also
+ :func:`pyramid_cubicweb.profile.cnx`.
+
+Typical Usage
+-------------
+
+Let's say we want to measure the cost of having a ``cnx``.
+
+- Start the application with profile enabled:
+
+ .. code-block:: console
+
+ $ cubicweb-ctl pyramid --no-daemon --profile --profile-dump-every 100
+
+- Use 'ab' or any other http benchmark tool to throw a lot of requests:
+
+ .. code-block:: console
+
+ $ ab -c 1 -n 100 http://localhost:8080/_profile/cnx
+
+- Analyse the results. I personnaly fancy SnakeViz_:
+
+ .. code-block:: console
+
+ $ snakeviz program.prof
+
+.. _SnakeViz: http://jiffyclub.github.io/snakeviz/
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/docs/narr/quickstart.rst Sat Jan 03 22:06:03 2015 +0100
@@ -0,0 +1,37 @@
+Quick start
+===========
+
+.. highlight:: console
+
+From CubicWeb
+-------------
+
+- Install everything (here with pip, possibly in a virtualenv)::
+
+ pip install pyramid-cubicweb cubicweb-pyramid pyramid_debugtoolbar
+
+- Make sure CubicWeb is in user mode::
+
+ export CW_MODE=user
+
+- Create a CubicWeb instance, and install the 'pyramid' cube on it (see
+ :ref:`configenv` for more details on this step)::
+
+ cubicweb-ctl create pyramid myinstance
+
+ .. warning::
+
+ You `must` allow anonymous access.
+
+- Edit your ``~/etc/cubicweb.d/myinstance/all-in-one.conf`` and set values for
+ :confval:`pyramid-auth-secret` and :confval:`pyramid-session-secret`.
+
+- Start the instance with the :ref:`'pyramid' command <cubicweb-ctl_pyramid>`
+ instead of 'start'::
+
+ cubicweb-ctl pyramid --debug myinstance
+
+In a pyramid application
+------------------------
+
+Coming soon.
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/docs/narr/settings.rst Sat Jan 03 22:06:03 2015 +0100
@@ -0,0 +1,88 @@
+Settings
+========
+
+.. _cubicweb_settings:
+
+Cubicweb Settings
+-----------------
+
+Pyramid CubicWeb will make use of the following configuration entries if found
+in the cubicweb configuration (a.k.a. `all-in-one.conf`):
+
+.. warning::
+
+ These settings requires the `pyramid` cube to be enabled on the instance.
+
+.. confval:: pyramid-session-secret
+
+ Secret phrase to sign the session cookie
+
+ Used by :func:`pyramid_cubicweb.session.includeme` to configure the default session factory.
+
+ .. code-block:: ini
+
+ pyramid-session-secret = <some very secret passphrase>
+
+.. confval:: pyramid-auth-secret
+
+ Secret phrase to sign the authentication cookie
+
+ Used by :func:`pyramid_cubicweb.auth.includeme` to configure the default authentication policy.
+
+ .. code-block:: ini
+
+ pyramid-session-secret = <some other very secret passphrase>
+
+
+.. _pyramid_settings:
+
+Pyramid Settings
+----------------
+
+If a ``pyramid.ini`` file is found in the instance home directory (where the
+``all-in-one.conf`` file is), its ``[main]`` section will be read and used as the
+``settings`` of the pyramid Configurator.
+
+This configuration file is almost the same as the one read by ``pserve``, which
+allow to easily add any pyramid extension and configure it.
+
+A typical ``pyramid.ini`` file is:
+
+.. code-block:: ini
+
+ [main]
+ pyramid.includes =
+ pyramid_redis_sessions
+
+ cubicweb.defaults = no
+ cubicweb.includes =
+ pyramid_cubicweb.auth
+ pyramid_cubicweb.login
+
+ cubicweb.profile = no
+
+ redis.sessions.secret = your_cookie_signing_secret
+ redis.sessions.timeout = 1200
+
+ redis.sessions.host = mywheezy
+
+The Pyramid CubicWeb specific configuration entries are:
+
+.. confval:: cubicweb.includes (list)
+
+ Same as ``pyramid.includes``, but the includes are done after the cubicweb
+ specific registry entries are initialized.
+
+ Useful to include extensions that requires these entries.
+
+.. confval:: cubicweb.bwcompat (bool)
+
+ (True) Enable/disable backward compatibility. See :ref:`bwcompat_module`.
+
+.. confval:: cubicweb.defaults (bool)
+
+ (True) Enable/disable defaults. See :ref:`defaults_module`.
+
+.. confval:: cubicweb.profile (bool)
+
+ (False) Enable/disable profiling. See :ref:`profiling`.
--- a/pyramid_cubicweb/__init__.py Mon Jan 05 12:02:01 2015 +0100
+++ b/pyramid_cubicweb/__init__.py Sat Jan 03 22:06:03 2015 +0100
@@ -16,6 +16,9 @@
Create a pyramid-based CubicWeb instance from a cubicweb configuration.
It is initialy meant to be used by the 'pyramid' command of cubicweb-ctl.
+
+ :param cwconfig: A CubicWeb configuration
+ :returns: A Pyramid config object
"""
settings_filenames = [os.path.join(cwconfig.apphome, 'pyramid.ini')]
@@ -61,6 +64,16 @@
def wsgi_application_from_cwconfig(
cwconfig,
profile=False, profile_output=None, profile_dump_every=None):
+ """ Build a WSGI application from a cubicweb configuration
+
+ :param cwconfig: A CubicWeb configuration
+ :param profile: Enable profiling. See :ref:`profiling`.
+ :param profile_output: Profiling output filename. See :ref:`profiling`.
+ :param profile_dump_every: Profiling number of requests before dumping the
+ stats. See :ref:`profiling`.
+
+ :returns: A fully operationnal WSGI application
+ """
config = make_cubicweb_application(cwconfig)
profile = profile or asbool(config.registry.settings.get(
'cubicweb.profile.enable', False))
@@ -89,6 +102,40 @@
def wsgi_application(instance_name=None, debug=None):
+ """ Build a WSGI application from a cubicweb instance name
+
+ :param instance_name: Name of the cubicweb instance (optional). If not
+ provided, :envvar:`CW_INSTANCE` must exists.
+ :param debug: Enable/disable the debug mode. If defined to True or False,
+ overrides :envvar:`CW_DEBUG`.
+
+ The following environment variables are used if they exist:
+
+ .. envvar:: CW_INSTANCE
+
+ A CubicWeb instance name.
+
+ .. envvar:: CW_DEBUG
+
+ If defined, the debugmode is enabled.
+
+ The function can be used as an entry-point for third-party wsgi containers.
+ Below is a sample uswgi configuration file:
+
+ .. code-block:: ini
+
+ [uwsgi]
+ http = 127.0.1.1:8080
+ env = CW_INSTANCE=myinstance
+ env = CW_DEBUG=1
+ module = pyramid_cubicweb:wsgi_application()
+ virtualenv = /home/user/.virtualenvs/myvirtualenv
+ processes = 1
+ threads = 8
+ stats = 127.0.0.1:9191
+ plugins = http,python
+
+ """
if instance_name is None:
instance_name = os.environ.get('CW_INSTANCE')
if debug is None:
--- a/pyramid_cubicweb/auth.py Mon Jan 05 12:02:01 2015 +0100
+++ b/pyramid_cubicweb/auth.py Sat Jan 03 22:06:03 2015 +0100
@@ -18,6 +18,8 @@
Meaning, the last_login_time is updated reissue_time seconds (maximum)
before the last request by the user.
+
+ Usually used via :func:`includeme`.
"""
def remember(self, request, principal, **kw):
@@ -37,6 +39,12 @@
def includeme(config):
+ """ Activate the CubicWeb AuthTkt authentication policy.
+
+ Usually called via ``config.include('pyramid_cubicweb.auth')``.
+
+ See also :ref:`defaults_module`
+ """
secret = config.registry['cubicweb.config']['pyramid-auth-secret']
if not secret:
--- a/pyramid_cubicweb/authplugin.py Mon Jan 05 12:02:01 2015 +0100
+++ b/pyramid_cubicweb/authplugin.py Sat Jan 03 22:06:03 2015 +0100
@@ -19,8 +19,8 @@
class DirectAuthentifier(native.BaseAuthentifier):
"""return CWUser eid for the given login.
- Before doing so, it makes sure the authentication request comes from
- xxx by checking the special '__externalauth_directauth' kwarg.
+ Before doing so, it makes sure the authentication request is not coming
+ from ouside by checking the special '__externalauth_directauth' kwarg.
"""
--- a/pyramid_cubicweb/bwcompat.py Mon Jan 05 12:02:01 2015 +0100
+++ b/pyramid_cubicweb/bwcompat.py Sat Jan 03 22:06:03 2015 +0100
@@ -15,7 +15,11 @@
class PyramidSessionHandler(object):
"""A CW Session handler that rely on the pyramid API to fetch the needed
- informations"""
+ informations.
+
+ It implements the :class:`cubicweb.web.application.CookieSessionHandler`
+ API.
+ """
def __init__(self, appli):
self.appli = appli
@@ -28,6 +32,11 @@
class CubicWebPyramidHandler(object):
+ """ A Pyramid request handler that rely on a cubicweb instance to do the
+ whole job
+
+ :param appli: A CubicWeb 'Application' object.
+ """
def __init__(self, appli):
self.appli = appli
@@ -107,6 +116,12 @@
class TweenHandler(object):
+ """ A Pyramid tween handler that submit unhandled requests to a Cubicweb
+ handler.
+
+ The CubicWeb handler to use is expected to be in the pyramid registry, at
+ key ``'cubicweb.handler'``.
+ """
def __init__(self, handler, registry):
self.handler = handler
self.cwhandler = registry['cubicweb.handler']
@@ -124,10 +139,22 @@
def includeme(config):
- # Set up a tween app that will handle the request if the main application
- # raises a HTTPNotFound exception.
- # This is to keep legacy compatibility for cubes that makes use of the
- # cubicweb controllers.
+ """ Set up a tween app that will handle the request if the main application
+ raises a HTTPNotFound exception.
+
+ This is to keep legacy compatibility for cubes that makes use of the
+ cubicweb urlresolvers.
+
+ It provides, for now, support for cubicweb controllers, but this feature
+ will be reimplemented separatly in a less compatible way.
+
+ It is automatically included by the configuration system, but can be
+ disabled in the :ref:`pyramid_settings`:
+
+ .. code-block:: ini
+
+ cubicweb.bwcompat = no
+ """
cwconfig = config.registry['cubicweb.config']
repository = config.registry['cubicweb.repository']
cwappli = CubicWebPublisher(
--- a/pyramid_cubicweb/core.py Mon Jan 05 12:02:01 2015 +0100
+++ b/pyramid_cubicweb/core.py Sat Jan 03 22:06:03 2015 +0100
@@ -22,7 +22,7 @@
@contextmanager
def cw_to_pyramid(request):
- """Wrap a call to the cubicweb API.
+ """ Context manager to wrap a call to the cubicweb API.
All CW exceptions will be transformed into their pyramid equivalent.
When needed, some CW reponse bits may be converted too (mainly headers)"""
@@ -53,6 +53,11 @@
class CubicWebPyramidRequest(CubicWebRequestBase):
+ """ A CubicWeb request that only wraps a pyramid request.
+
+ :param request: A pyramid request
+
+ """
def __init__(self, request):
self._request = request
@@ -121,6 +126,13 @@
def render_view(request, vid, **kwargs):
+ """ Helper function to render a CubicWeb view.
+
+ :param request: A pyramid request
+ :param vid: A CubicWeb view id
+ :param **kwargs: Keyword arguments to select and instanciate the view
+ :returns: The rendered view content
+ """
vreg = request.registry['cubicweb.registry']
# XXX The select() function could, know how to handle a pyramid
# request, and feed it directly to the views that supports it.
@@ -135,6 +147,17 @@
def _cw_cnx(request):
+ """ Obtains a cw session from a pyramid request
+
+ The connection will be commited or rolled-back in a request finish
+ callback (this is temporary, we should make use of the transaction manager
+ in a later version).
+
+ Not meant for direct use, use ``request.cw_cnx`` instead.
+
+ :param request: A pyramid request
+ :returns type: :class:`cubicweb.server.session.Connection`
+ """
cnx = repoapi.ClientConnection(request.cw_session)
def cleanup(request):
@@ -153,8 +176,9 @@
def repo_connect(repo, eid):
- """A lightweight version of repo.connect that does not keep track of opened
- sessions, removing the need of closing them"""
+ """A lightweight version of
+ :meth:`cubicweb.server.repository.Repository.connect` that does not keep
+ track of opened sessions, removing the need of closing them"""
with repo.internal_cnx() as cnx:
user = repo._build_user(cnx, eid=eid)
session = Session(user, repo, None)
@@ -170,7 +194,13 @@
def _cw_session(request):
- """Obtains a cw session from a pyramid request"""
+ """Obtains a cw session from a pyramid request
+
+ :param request: A pyramid request
+ :returns type: :class:`cubicweb.server.session.Session`
+
+ Not meant for direct use, use ``request.cw_session`` instead.
+ """
repo = request.registry['cubicweb.repository']
if not request.authenticated_userid:
@@ -187,12 +217,37 @@
def _cw_request(request):
+ """ Obtains a CubicWeb request wrapper for the pyramid request.
+
+ :param request: A pyramid request
+ :return: A CubicWeb request
+ :returns type: :class:`CubicWebPyramidRequest`
+
+ Not meant for direct use, use ``request.cw_request`` instead.
+
+ """
req = CubicWebPyramidRequest(request)
req.set_cnx(request.cw_cnx)
return req
def get_principals(login, request):
+ """ Returns the group names of the authenticated user.
+
+ This function is meant to be used as an authentication policy callback.
+
+ It also pre-open the cubicweb session and put it in
+ request._cw_cached_session for later usage by :func:`_cw_session`.
+
+ .. note::
+
+ It the default authentication policy is not used, make sure this
+ function gets called by the active authentication policy.
+
+ :param login: A cubicweb user eid
+ :param request: A pyramid request
+ :returns: A list of group names
+ """
repo = request.registry['cubicweb.repository']
try:
@@ -206,6 +261,21 @@
def includeme(config):
+ """ Enables the core features of Pyramid CubicWeb.
+
+ Automatically called by the 'pyramid' command, or via
+ ``config.include('pyramid_cubicweb.code')``. In the later case,
+ the following registry entries must be defined first:
+
+ 'cubicweb.config'
+ A cubicweb 'config' instance.
+
+ 'cubicweb.repository'
+ The correponding cubicweb repository.
+
+ 'cubicweb.registry'
+ The vreg.
+ """
repo = config.registry['cubicweb.repository']
with repo.internal_cnx() as cnx:
--- a/pyramid_cubicweb/defaults.py Mon Jan 05 12:02:01 2015 +0100
+++ b/pyramid_cubicweb/defaults.py Sat Jan 03 22:06:03 2015 +0100
@@ -1,4 +1,24 @@
+""" Defaults for a classical CubicWeb instance. """
+
+
def includeme(config):
+ """ Enable the defaults that make the application behave like a classical
+ CubicWeb instance.
+
+ The following modules get included:
+
+ - :func:`pyramid_cubicweb.session <pyramid_cubicweb.session.includeme>`
+ - :func:`pyramid_cubicweb.auth <pyramid_cubicweb.auth.includeme>`
+ - :func:`pyramid_cubicweb.login <pyramid_cubicweb.login.includeme>`
+
+ It is automatically included by the configuration system, unless the
+ following entry is added to the :ref:`pyramid_settings`:
+
+ .. code-block:: ini
+
+ cubicweb.defaults = no
+
+ """
config.include('pyramid_cubicweb.session')
config.include('pyramid_cubicweb.auth')
config.include('pyramid_cubicweb.login')
--- a/pyramid_cubicweb/login.py Mon Jan 05 12:02:01 2015 +0100
+++ b/pyramid_cubicweb/login.py Sat Jan 03 22:06:03 2015 +0100
@@ -1,3 +1,4 @@
+""" Provide login views that reproduce a classical CubicWeb behavior"""
from pyramid import security
from pyramid.httpexceptions import HTTPSeeOther
from pyramid.view import view_config
@@ -9,12 +10,30 @@
@view_config(route_name='login')
def login_form(request):
+ """ Default view for the 'login' route.
+
+ Display the 'login' CubicWeb view, which is should be a login form"""
request.response.text = render_view(request, 'login')
return request.response
@view_config(route_name='login', request_param=('__login', '__password'))
def login_password_login(request):
+ """ Handle GET/POST of __login/__password on the 'login' route.
+
+ The authentication itself is delegated to the CubicWeb repository.
+
+ Request parameters:
+
+ :param __login: The user login (or email if :confval:`allow-email-login` is
+ on.
+ :param __password: The user password
+ :param __setauthcookie: (optional) If defined and equal to '1', set the
+ authentication cookie maxage to 1 week.
+
+ If not, the authentication cookie is a session
+ cookie.
+ """
repo = request.registry['cubicweb.repository']
user_eid = None
@@ -48,9 +67,13 @@
@view_config(route_name='login', effective_principals=security.Authenticated)
def login_already_loggedin(request):
+ """ 'login' route view for Authenticated users.
+
+ Simply redirect the user to '/'."""
raise HTTPSeeOther('/')
def includeme(config):
+ """ Create the 'login' route ('/login') and load this module views"""
config.add_route('login', '/login')
config.scan('pyramid_cubicweb.login')
--- a/pyramid_cubicweb/profile.py Mon Jan 05 12:02:01 2015 +0100
+++ b/pyramid_cubicweb/profile.py Sat Jan 03 22:06:03 2015 +0100
@@ -1,3 +1,6 @@
+""" Tools for profiling.
+
+See :ref:`profiling`."""
import cProfile
import itertools
from pyramid.view import view_config
@@ -5,18 +8,40 @@
@view_config(route_name='profile_ping')
def ping(request):
+ """ View that handle '/_profile/ping'
+
+ It simply reply 'ping', without requiring connection to the repository.
+ It is a useful as a comparison point to evaluate the actual overhead of
+ more costly views.
+ """
request.response.text = u'pong'
return request.response
@view_config(route_name='profile_cnx')
def cnx(request):
+ """ View that handle '/_profile/cnx'
+
+ Same as :func:`ping`, but it first ask for a connection to the repository.
+ Useful to evaluate the overhead of opening a connection.
+ """
request.cw_cnx
request.response.text = u'pong'
return request.response
def wsgi_profile(app, filename='program.prof', dump_every=50):
+ """ A WSGI middleware for profiling
+
+ It enable the profiler before passing the request to the underlying
+ application, and disable it just after.
+
+ The stats will be dumped after ``dump_every`` requests
+
+ :param filename: The filename to dump the stats to.
+ :param dump_every: Number of requests after which to dump the stats.
+ """
+
profile = cProfile.Profile()
counter = itertools.count(1)
--- a/pyramid_cubicweb/session.py Mon Jan 05 12:02:01 2015 +0100
+++ b/pyramid_cubicweb/session.py Sat Jan 03 22:06:03 2015 +0100
@@ -35,6 +35,26 @@
hashalg='sha512',
salt='pyramid.session.',
serializer=None):
+ """ A pyramid session factory that store session data in the CubicWeb
+ database.
+
+ Storage is done with the 'CWSession' entity, which is provided by the
+ 'pyramid' cube.
+
+ .. warning::
+
+ Although it provides a sane default behavior, this session storage has
+ a serious overhead because it uses RQL to access the database.
+
+ Using pure SQL would improve a bit (it is roughly twice faster), but it
+ is still pretty slow and thus not an immediate priority.
+
+ It is recommended to use faster session factory
+ (pyramid_redis_sessions_ for example) if you need speed.
+
+ .. _pyramid_redis_sessions: http://pyramid-redis-sessions.readthedocs.org/
+ en/latest/index.html
+ """
SignedCookieSession = SignedCookieSessionFactory(
secret,
@@ -118,6 +138,12 @@
def includeme(config):
+ """ Activate the CubicWeb session factory.
+
+ Usually called via ``config.include('pyramid_cubicweb.auth')``.
+
+ See also :ref:`defaults_module`
+ """
secret = config.registry['cubicweb.config']['pyramid-session-secret']
if not secret:
secret = 'notsosecret'