--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/docs/build/html/zca.html Tue Nov 22 21:35:46 2016 +0100
@@ -0,0 +1,352 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+
+
+<html xmlns="http://www.w3.org/1999/xhtml">
+ <head>
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+
+ <title>Managing ZCA with PyAMS — PyAMS_utils 0.1.4 documentation</title>
+
+ <link rel="stylesheet" href="_static/pyramid.css" type="text/css" />
+ <link rel="stylesheet" href="_static/pygments.css" type="text/css" />
+
+ <script type="text/javascript">
+ var DOCUMENTATION_OPTIONS = {
+ URL_ROOT: './',
+ VERSION: '0.1.4',
+ COLLAPSE_INDEX: false,
+ FILE_SUFFIX: '.html',
+ HAS_SOURCE: true
+ };
+ </script>
+ <script type="text/javascript" src="_static/jquery.js"></script>
+ <script type="text/javascript" src="_static/underscore.js"></script>
+ <script type="text/javascript" src="_static/doctools.js"></script>
+ <link rel="index" title="Index" href="genindex.html" />
+ <link rel="search" title="Search" href="search.html" />
+ <link rel="top" title="PyAMS_utils 0.1.4 documentation" href="index.html" />
+ <link rel="next" title="PyAMS site management" href="site.html" />
+ <link rel="prev" title="Installing PyAMS" href="install.html" />
+<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Neuton&subset=latin" type="text/css" media="screen" charset="utf-8" />
+<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Nobile:regular,italic,bold,bolditalic&subset=latin" type="text/css" media="screen" charset="utf-8" />
+<!--[if lte IE 6]>
+<link rel="stylesheet" href="_static/ie6.css" type="text/css" media="screen" charset="utf-8" />
+<![endif]-->
+
+ </head>
+ <body role="document">
+
+ <div class="related" role="navigation" aria-label="related navigation">
+ <h3>Navigation</h3>
+ <ul>
+ <li class="right" style="margin-right: 10px">
+ <a href="genindex.html" title="General Index"
+ accesskey="I">index</a></li>
+ <li class="right" >
+ <a href="py-modindex.html" title="Python Module Index"
+ >modules</a> |</li>
+ <li class="right" >
+ <a href="site.html" title="PyAMS site management"
+ accesskey="N">next</a> |</li>
+ <li class="right" >
+ <a href="install.html" title="Installing PyAMS"
+ accesskey="P">previous</a> |</li>
+ <li class="nav-item nav-item-0"><a href="index.html">PyAMS_utils 0.1.4 documentation</a> »</li>
+ </ul>
+ </div>
+
+ <div class="document">
+ <div class="documentwrapper">
+ <div class="bodywrapper">
+ <div class="body" role="main">
+
+ <div class="section" id="managing-zca-with-pyams">
+<span id="zca"></span><h1>Managing ZCA with PyAMS<a class="headerlink" href="#managing-zca-with-pyams" title="Permalink to this headline">¶</a></h1>
+<p>The <strong>Zope Component Architecture</strong> (aka ZCA) is used by the Pyramid framework “under the hood” to handle interfaces,
+adapters and utilities. You don’t <strong>have to</strong> use it in your own applications. But you can.</p>
+<p>The ZCA is mainly adding elements like <strong>interfaces</strong>, <strong>adapters</strong> and <strong>utilities</strong> to the Python language. It
+allows you to write a framework or an application by using <strong>components</strong> which can be extended easily.</p>
+<p>You will find several useful resources about ZCA concepts on the internet.</p>
+<div class="section" id="local-utilities">
+<h2>Local utilities<a class="headerlink" href="#local-utilities" title="Permalink to this headline">¶</a></h2>
+<p>In ZCA, a <strong>utility</strong> is a <strong>registered</strong> component which provides an <strong>interface</strong>. This interface is the
+<strong>contract</strong> which defines features provided by the component which implements it.</p>
+<p>When a Pyramid application starts, a <strong>global registry</strong> is created to register a whole set of utilities and
+adapters; this registration can be done via ZCML directives or via native Python code.
+In addition, PyAMS allows you to define <strong>local utilities</strong>, which are stored and registered in the ZODB via a <strong>site
+manager</strong>.</p>
+</div>
+<div class="section" id="defining-site-root">
+<h2>Defining site root<a class="headerlink" href="#defining-site-root" title="Permalink to this headline">¶</a></h2>
+<p>One of PyAMS pre-requisites is to use the ZODB, at least to store the site root application, it’s configuration and a
+set of local utilities. <a class="reference internal" href="site.html#site"><span class="std std-ref">PyAMS site management</span></a> describes application startup and <strong>local site manager</strong>
+initialization process.</p>
+<p>This site can be used to store <strong>local utilities</strong> whose configuration, which is easily available to site
+administrators through management interface, is stored in the ZODB.</p>
+</div>
+<div class="section" id="registering-global-utilities">
+<h2>Registering global utilities<a class="headerlink" href="#registering-global-utilities" title="Permalink to this headline">¶</a></h2>
+<p><strong>Global utilities</strong> are components providing an interface which are registered in the global registry.
+PyAMS_utils package provides custom annotations to register global utilities without using ZCML. For example, a skin
+is nothing more than a simple utility providing the <em>ISkin</em> interface:</p>
+<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">pyams_default_theme.layer</span> <span class="kn">import</span> <span class="n">IPyAMSDefaultLayer</span>
+<span class="kn">from</span> <span class="nn">pyams_skin.interfaces</span> <span class="kn">import</span> <span class="n">ISkin</span>
+<span class="kn">from</span> <span class="nn">pyams_utils.registry</span> <span class="kn">import</span> <span class="n">utility_config</span>
+
+<span class="nd">@utility_config</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="s">'PyAMS default skin'</span><span class="p">,</span> <span class="n">provides</span><span class="o">=</span><span class="n">ISkin</span><span class="p">)</span>
+<span class="k">class</span> <span class="nc">PyAMSDefaultSkin</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span>
+ <span class="sd">"""PyAMS default skin"""</span>
+
+ <span class="n">label</span> <span class="o">=</span> <span class="n">_</span><span class="p">(</span><span class="s">"PyAMS default skin"</span><span class="p">)</span>
+ <span class="n">layer</span> <span class="o">=</span> <span class="n">IPyAMSDefaultLayer</span>
+</pre></div>
+</div>
+<p>This annotation registers a utility, named <em>PyAMS default skin</em>, providing the <em>ISkin</em> interface. It’s the developer
+responsibility to provide all attributes and methods required by the provided interface.</p>
+</div>
+<div class="section" id="registering-local-utilities">
+<h2>Registering local utilities<a class="headerlink" href="#registering-local-utilities" title="Permalink to this headline">¶</a></h2>
+<p>A local utility is a persistent object, registered in a <em>local site manager</em>, and providing a specific interface (if
+a component provides several interfaces, it can be registered several times).</p>
+<p>Some components can be required by a given package, and created automatically via the <em>pyams_upgrade</em> command line
+script; this process relies on the <em>ISiteGenerations</em> interface, for example for the timezone utility, a component
+provided by PyAMS_utils package to handle server timezone and display times correctly:</p>
+<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">pyams_utils.interfaces.site</span> <span class="kn">import</span> <span class="n">ISiteGenerations</span>
+<span class="kn">from</span> <span class="nn">pyams_utils.interfaces.timezone</span> <span class="kn">import</span> <span class="n">IServerTimezone</span>
+
+<span class="kn">from</span> <span class="nn">persistent</span> <span class="kn">import</span> <span class="n">Persistent</span>
+<span class="kn">from</span> <span class="nn">pyams_utils.registry</span> <span class="kn">import</span> <span class="n">utility_config</span>
+<span class="kn">from</span> <span class="nn">pyams_utils.site</span> <span class="kn">import</span> <span class="n">check_required_utilities</span>
+<span class="kn">from</span> <span class="nn">pyramid.events</span> <span class="kn">import</span> <span class="n">subscriber</span>
+<span class="kn">from</span> <span class="nn">zope.container.contained</span> <span class="kn">import</span> <span class="n">Contained</span>
+<span class="kn">from</span> <span class="nn">zope.interface</span> <span class="kn">import</span> <span class="n">implementer</span>
+<span class="kn">from</span> <span class="nn">zope.schema.fieldproperty</span> <span class="kn">import</span> <span class="n">FieldProperty</span>
+
+<span class="nd">@implementer</span><span class="p">(</span><span class="n">IServerTimezone</span><span class="p">)</span>
+<span class="k">class</span> <span class="nc">ServerTimezoneUtility</span><span class="p">(</span><span class="n">Persistent</span><span class="p">,</span> <span class="n">Contained</span><span class="p">):</span>
+
+ <span class="n">timezone</span> <span class="o">=</span> <span class="n">FieldProperty</span><span class="p">(</span><span class="n">IServerTimezone</span><span class="p">[</span><span class="s">'timezone'</span><span class="p">])</span>
+
+<span class="n">REQUIRED_UTILITIES</span> <span class="o">=</span> <span class="p">((</span><span class="n">IServerTimezone</span><span class="p">,</span> <span class="s">''</span><span class="p">,</span> <span class="n">ServerTimezoneUtility</span><span class="p">,</span> <span class="s">'Server timezone'</span><span class="p">),)</span>
+
+<span class="nd">@subscriber</span><span class="p">(</span><span class="n">INewLocalSite</span><span class="p">)</span>
+<span class="k">def</span> <span class="nf">handle_new_local_site</span><span class="p">(</span><span class="n">event</span><span class="p">):</span>
+ <span class="sd">"""Create a new ServerTimezoneUtility when a site is created"""</span>
+ <span class="n">site</span> <span class="o">=</span> <span class="n">event</span><span class="o">.</span><span class="n">manager</span><span class="o">.</span><span class="n">__parent__</span>
+ <span class="n">check_required_utilities</span><span class="p">(</span><span class="n">site</span><span class="p">,</span> <span class="n">REQUIRED_UTILITIES</span><span class="p">)</span>
+
+<span class="nd">@utility_config</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="s">'PyAMS timezone'</span><span class="p">,</span> <span class="n">provides</span><span class="o">=</span><span class="n">ISiteGenerations</span><span class="p">)</span>
+<span class="k">class</span> <span class="nc">TimezoneGenerationsChecker</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span>
+ <span class="sd">"""Timezone generations checker"""</span>
+
+ <span class="n">generation</span> <span class="o">=</span> <span class="mi">1</span>
+
+ <span class="k">def</span> <span class="nf">evolve</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">site</span><span class="p">,</span> <span class="n">current</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
+ <span class="sd">"""Check for required utilities"""</span>
+ <span class="n">check_required_utilities</span><span class="p">(</span><span class="n">site</span><span class="p">,</span> <span class="n">REQUIRED_UTILITIES</span><span class="p">)</span>
+</pre></div>
+</div>
+<p>Some utilities can also be created manually by an administrator through the management interface, and registered
+automatically after their creation. For example, this is how a ZEO connection utility (which is managing settings to
+define a ZEO connection) is registered:</p>
+<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">pyams_utils.interfaces.site</span> <span class="kn">import</span> <span class="n">IOptionalUtility</span>
+<span class="kn">from</span> <span class="nn">pyams_utils.interfaces.zeo</span> <span class="kn">import</span> <span class="n">IZEOConnection</span>
+<span class="kn">from</span> <span class="nn">zope.annotation.interfaces</span> <span class="kn">import</span> <span class="n">IAttributeAnnotatable</span>
+<span class="kn">from</span> <span class="nn">zope.lifecycleevent.interfaces</span> <span class="kn">import</span> <span class="n">IObjectAddedEvent</span><span class="p">,</span> <span class="n">IObjectRemovedEvent</span>
+
+<span class="kn">from</span> <span class="nn">persistent</span> <span class="kn">import</span> <span class="n">Persistent</span>
+<span class="kn">from</span> <span class="nn">pyramid.events</span> <span class="kn">import</span> <span class="n">subscriber</span>
+<span class="kn">from</span> <span class="nn">zope.container.contained</span> <span class="kn">import</span> <span class="n">Contained</span>
+
+<span class="nd">@implementer</span><span class="p">(</span><span class="n">IZEOConnection</span><span class="p">)</span>
+<span class="k">class</span> <span class="nc">ZEOConnection</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span>
+ <span class="sd">"""ZEO connection object. See source code to get full implementation..."""</span>
+
+<span class="nd">@implementer</span><span class="p">(</span><span class="n">IOptionalUtility</span><span class="p">,</span> <span class="n">IAttributeAnnotatable</span><span class="p">)</span>
+<span class="k">class</span> <span class="nc">ZEOConnectionUtility</span><span class="p">(</span><span class="n">ZEOConnection</span><span class="p">,</span> <span class="n">Persistent</span><span class="p">,</span> <span class="n">Contained</span><span class="p">):</span>
+ <span class="sd">"""Persistent ZEO connection utility"""</span>
+
+<span class="nd">@subscriber</span><span class="p">(</span><span class="n">IObjectAddedEvent</span><span class="p">,</span> <span class="n">context_selector</span><span class="o">=</span><span class="n">IZEOConnection</span><span class="p">)</span>
+<span class="k">def</span> <span class="nf">handle_added_connection</span><span class="p">(</span><span class="n">event</span><span class="p">):</span>
+ <span class="sd">"""Register new ZEO connection when added"""</span>
+ <span class="n">manager</span> <span class="o">=</span> <span class="n">event</span><span class="o">.</span><span class="n">newParent</span>
+ <span class="n">manager</span><span class="o">.</span><span class="n">registerUtility</span><span class="p">(</span><span class="n">event</span><span class="o">.</span><span class="n">object</span><span class="p">,</span> <span class="n">IZEOConnection</span><span class="p">,</span> <span class="n">name</span><span class="o">=</span><span class="n">event</span><span class="o">.</span><span class="n">object</span><span class="o">.</span><span class="n">name</span><span class="p">)</span>
+
+<span class="nd">@subscriber</span><span class="p">(</span><span class="n">IObjectRemovedEvent</span><span class="p">,</span> <span class="n">context_selector</span><span class="o">=</span><span class="n">IZEOConnection</span><span class="p">)</span>
+<span class="k">def</span> <span class="nf">handle_removed_connection</span><span class="p">(</span><span class="n">event</span><span class="p">):</span>
+ <span class="sd">"""Un-register ZEO connection when deleted"""</span>
+ <span class="n">manager</span> <span class="o">=</span> <span class="n">event</span><span class="o">.</span><span class="n">oldParent</span>
+ <span class="n">manager</span><span class="o">.</span><span class="n">unregisterUtility</span><span class="p">(</span><span class="n">event</span><span class="o">.</span><span class="n">object</span><span class="p">,</span> <span class="n">IZEOConnection</span><span class="p">,</span> <span class="n">name</span><span class="o">=</span><span class="n">event</span><span class="o">.</span><span class="n">object</span><span class="o">.</span><span class="n">name</span><span class="p">)</span>
+</pre></div>
+</div>
+<p><em>context_selector</em> is a custom subscriber predicate, so that subscriber event is activated only if object concerned
+by an event is providing given interface.</p>
+</div>
+<div class="section" id="looking-for-utilities">
+<h2>Looking for utilities<a class="headerlink" href="#looking-for-utilities" title="Permalink to this headline">¶</a></h2>
+<p>ZCA provides the <em>getUtility</em> and <em>queryUtility</em> functions to look for a utility. But these methods only applies to
+global registry.</p>
+<p>PyAMS package provides equivalent functions, which are looking for components into local registry before looking into
+the global one. For example:</p>
+<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">pyams_security.interfaces</span> <span class="kn">import</span> <span class="n">ISecurityManager</span>
+<span class="kn">from</span> <span class="nn">pyams_utils.registry</span> <span class="kn">import</span> <span class="n">query_utility</span>
+
+<span class="n">manager</span> <span class="o">=</span> <span class="n">query_utility</span><span class="p">(</span><span class="n">ISecurityManager</span><span class="p">)</span>
+<span class="k">if</span> <span class="n">manager</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
+ <span class="k">print</span><span class="p">(</span><span class="s">"Manager is there!"</span><span class="p">)</span>
+</pre></div>
+</div>
+<p>All ZCA utility functions have been ported to use local registry: <em>registered_utilities</em>, <em>query_utility</em>,
+<em>get_utility</em>, <em>get_utilities_for</em>, <em>get_all_utilities_registered_for</em> functions all follow the equivalent ZCA
+functions API, but are looking for utilities in the local registry before looking in the global registry.</p>
+</div>
+<div class="section" id="registering-adapters">
+<h2>Registering adapters<a class="headerlink" href="#registering-adapters" title="Permalink to this headline">¶</a></h2>
+<p>An adapter is also a kind of utility. But instead of <em>just</em> providing an interface, it adapts an input object,
+providing a given interface, to provide another interface. An adapter can also be named, so that you can choose which
+adapter to use at a given time.</p>
+<p>PyAMS_utils provide another annotation, to help registering adapters without using ZCML files. An adapter can be a
+function which directly returns an object providing the requested interface, or an object which provides the interface.</p>
+<p>The first example is an adapter which adapts any persistent object to get it’s associated transaction manager:</p>
+<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">persistent.interfaces</span> <span class="kn">import</span> <span class="n">IPersistent</span>
+<span class="kn">from</span> <span class="nn">transaction.interfaces</span> <span class="kn">import</span> <span class="n">ITransactionManager</span>
+<span class="kn">from</span> <span class="nn">ZODB.interfaces</span> <span class="kn">import</span> <span class="n">IConnection</span>
+
+<span class="kn">from</span> <span class="nn">pyams_utils.adapter</span> <span class="kn">import</span> <span class="n">adapter_config</span>
+
+<span class="nd">@adapter_config</span><span class="p">(</span><span class="n">context</span><span class="o">=</span><span class="n">IPersistent</span><span class="p">,</span> <span class="n">provides</span><span class="o">=</span><span class="n">ITransactionManager</span><span class="p">)</span>
+<span class="k">def</span> <span class="nf">get_transaction_manager</span><span class="p">(</span><span class="n">obj</span><span class="p">):</span>
+ <span class="n">conn</span> <span class="o">=</span> <span class="n">IConnection</span><span class="p">(</span><span class="n">obj</span><span class="p">)</span>
+ <span class="k">try</span><span class="p">:</span>
+ <span class="k">return</span> <span class="n">conn</span><span class="o">.</span><span class="n">transaction_manager</span>
+ <span class="k">except</span> <span class="ne">AttributeError</span><span class="p">:</span>
+ <span class="k">return</span> <span class="n">conn</span><span class="o">.</span><span class="n">_txn_mgr</span>
+</pre></div>
+</div>
+<p>This is another adapter which adapts any contained object to the <em>IPathElements</em> interface; this interface can be
+used to build index that you can use to find objects based on a parent object:</p>
+<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">pyams_utils.interfaces.traversing</span> <span class="kn">import</span> <span class="n">IPathElements</span>
+<span class="kn">from</span> <span class="nn">zope.intid.interfaces</span> <span class="kn">import</span> <span class="n">IIntIds</span>
+<span class="kn">from</span> <span class="nn">zope.location.interfaces</span> <span class="kn">import</span> <span class="n">IContained</span>
+
+<span class="kn">from</span> <span class="nn">pyams_utils.adapter</span> <span class="kn">import</span> <span class="n">ContextAdapter</span>
+<span class="kn">from</span> <span class="nn">pyams_utils.registry</span> <span class="kn">import</span> <span class="n">query_utility</span>
+<span class="kn">from</span> <span class="nn">pyramid.location</span> <span class="kn">import</span> <span class="n">lineage</span>
+
+<span class="nd">@adapter_config</span><span class="p">(</span><span class="n">context</span><span class="o">=</span><span class="n">IContained</span><span class="p">,</span> <span class="n">provides</span><span class="o">=</span><span class="n">IPathElements</span><span class="p">)</span>
+<span class="k">class</span> <span class="nc">PathElementsAdapter</span><span class="p">(</span><span class="n">ContextAdapter</span><span class="p">):</span>
+ <span class="sd">"""Contained object path elements adapter"""</span>
+
+ <span class="nd">@property</span>
+ <span class="k">def</span> <span class="nf">parents</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
+ <span class="n">intids</span> <span class="o">=</span> <span class="n">query_utility</span><span class="p">(</span><span class="n">IIntIds</span><span class="p">)</span>
+ <span class="k">if</span> <span class="n">intids</span> <span class="ow">is</span> <span class="bp">None</span><span class="p">:</span>
+ <span class="k">return</span> <span class="p">[]</span>
+ <span class="k">return</span> <span class="p">[</span><span class="n">intids</span><span class="o">.</span><span class="n">register</span><span class="p">(</span><span class="n">parent</span><span class="p">)</span> <span class="k">for</span> <span class="n">parent</span> <span class="ow">in</span> <span class="n">lineage</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">context</span><span class="p">)]</span>
+</pre></div>
+</div>
+<p>An adapter can also be a multi-adapter, when several input objects are requested to provide a given interface. For
+example, many adapters require a context and a request, eventually a view, to provide another feature. This is how,
+for example, we define a custom <em>name</em> column in a security manager table displaying a list of plug-ins:</p>
+<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">pyams_zmi.layer</span> <span class="kn">import</span> <span class="n">IAdminLayer</span>
+<span class="kn">from</span> <span class="nn">z3c.table.interfaces</span> <span class="kn">import</span> <span class="n">IColumn</span>
+
+<span class="kn">from</span> <span class="nn">pyams_skin.table</span> <span class="kn">import</span> <span class="n">I18nColumn</span>
+<span class="kn">from</span> <span class="nn">z3c.table.column</span> <span class="kn">import</span> <span class="n">GetAttrColumn</span>
+
+<span class="nd">@adapter_config</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="s">'name'</span><span class="p">,</span> <span class="n">context</span><span class="o">=</span><span class="p">(</span><span class="n">Interface</span><span class="p">,</span> <span class="n">IAdminLayer</span><span class="p">,</span> <span class="n">SecurityManagerPluginsTable</span><span class="p">),</span> <span class="n">provides</span><span class="o">=</span><span class="n">IColumn</span><span class="p">)</span>
+<span class="k">class</span> <span class="nc">SecurityManagerPluginsNameColumn</span><span class="p">(</span><span class="n">I18nColumn</span><span class="p">,</span> <span class="n">GetAttrColumn</span><span class="p">):</span>
+ <span class="sd">"""Security manager plugins name column"""</span>
+
+ <span class="n">_header</span> <span class="o">=</span> <span class="n">_</span><span class="p">(</span><span class="s">"Name"</span><span class="p">)</span>
+ <span class="n">attrName</span> <span class="o">=</span> <span class="s">'title'</span>
+ <span class="n">weight</span> <span class="o">=</span> <span class="mi">10</span>
+</pre></div>
+</div>
+</div>
+<div class="section" id="registering-vocabularies">
+<h2>Registering vocabularies<a class="headerlink" href="#registering-vocabularies" title="Permalink to this headline">¶</a></h2>
+<p>A <strong>vocabulary</strong> is a custom factory which can be used as source for several field types, like <em>choices</em> or <em>lists</em>.
+Vocabularies have to be registered in a custom registry, so PyAMS_utils provide another annotation to register them.
+This example is based on the <em>Timezone</em> component which allows you to select a timezone between a list of references:</p>
+<div class="highlight-python"><div class="highlight"><pre><span class="kn">import</span> <span class="nn">pytz</span>
+<span class="kn">from</span> <span class="nn">pyams_utils.vocabulary</span> <span class="kn">import</span> <span class="n">vocabulary_config</span>
+<span class="kn">from</span> <span class="nn">zope.schema.vocabulary</span> <span class="kn">import</span> <span class="n">SimpleTerm</span><span class="p">,</span> <span class="n">SimpleVocabulary</span>
+
+<span class="nd">@vocabulary_config</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="s">'PyAMS timezones'</span><span class="p">)</span>
+<span class="k">class</span> <span class="nc">TimezonesVocabulary</span><span class="p">(</span><span class="n">SimpleVocabulary</span><span class="p">):</span>
+ <span class="sd">"""Timezones vocabulary"""</span>
+
+ <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kw</span><span class="p">):</span>
+ <span class="n">terms</span> <span class="o">=</span> <span class="p">[</span><span class="n">SimpleTerm</span><span class="p">(</span><span class="n">t</span><span class="p">,</span> <span class="n">t</span><span class="p">,</span> <span class="n">t</span><span class="p">)</span> <span class="k">for</span> <span class="n">t</span> <span class="ow">in</span> <span class="n">pytz</span><span class="o">.</span><span class="n">all_timezones</span><span class="p">]</span>
+ <span class="nb">super</span><span class="p">(</span><span class="n">TimezonesVocabulary</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="n">__init__</span><span class="p">(</span><span class="n">terms</span><span class="p">)</span>
+</pre></div>
+</div>
+</div>
+</div>
+
+
+ </div>
+ </div>
+ </div>
+ <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
+ <div class="sphinxsidebarwrapper">
+ <h3><a href="index.html">Table Of Contents</a></h3>
+ <ul>
+<li><a class="reference internal" href="#">Managing ZCA with PyAMS</a><ul>
+<li><a class="reference internal" href="#local-utilities">Local utilities</a></li>
+<li><a class="reference internal" href="#defining-site-root">Defining site root</a></li>
+<li><a class="reference internal" href="#registering-global-utilities">Registering global utilities</a></li>
+<li><a class="reference internal" href="#registering-local-utilities">Registering local utilities</a></li>
+<li><a class="reference internal" href="#looking-for-utilities">Looking for utilities</a></li>
+<li><a class="reference internal" href="#registering-adapters">Registering adapters</a></li>
+<li><a class="reference internal" href="#registering-vocabularies">Registering vocabularies</a></li>
+</ul>
+</li>
+</ul>
+
+ <h4>Previous topic</h4>
+ <p class="topless"><a href="install.html"
+ title="previous chapter">Installing PyAMS</a></p>
+ <h4>Next topic</h4>
+ <p class="topless"><a href="site.html"
+ title="next chapter">PyAMS site management</a></p>
+<div id="searchbox" style="display: none" role="search">
+ <h3>Quick search</h3>
+ <form class="search" action="search.html" method="get">
+ <div><input type="text" name="q" /></div>
+ <div><input type="submit" value="Go" /></div>
+ <input type="hidden" name="check_keywords" value="yes" />
+ <input type="hidden" name="area" value="default" />
+ </form>
+</div>
+<script type="text/javascript">$('#searchbox').show(0);</script>
+ </div>
+ </div>
+ <div class="clearer"></div>
+ </div>
+ <div class="related" role="navigation" aria-label="related navigation">
+ <h3>Navigation</h3>
+ <ul>
+ <li class="right" style="margin-right: 10px">
+ <a href="genindex.html" title="General Index"
+ >index</a></li>
+ <li class="right" >
+ <a href="py-modindex.html" title="Python Module Index"
+ >modules</a> |</li>
+ <li class="right" >
+ <a href="site.html" title="PyAMS site management"
+ >next</a> |</li>
+ <li class="right" >
+ <a href="install.html" title="Installing PyAMS"
+ >previous</a> |</li>
+ <li class="nav-item nav-item-0"><a href="index.html">PyAMS_utils 0.1.4 documentation</a> »</li>
+ </ul>
+ </div>
+ <div class="footer" role="contentinfo">
+ © Copyright 2016, Thierry Florac <tflorac@ulthar.net>.
+ Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.4.8.
+ </div>
+ </body>
+</html>
\ No newline at end of file