<!doctype html> <html xmlns="http://www.w3.org/1999/xhtml" lang="en"> <head> <meta http-equiv="X-UA-Compatible" content="IE=Edge" /> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>sqlobject.classregistry module — SQLObject 3.7.0 documentation</title> <link rel="stylesheet" href="../_static/bizstyle.css" type="text/css" /> <link rel="stylesheet" href="../_static/pygments.css" type="text/css" /> <script type="text/javascript" src="../_static/documentation_options.js"></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> <script type="text/javascript" src="../_static/bizstyle.js"></script> <link rel="index" title="Index" href="../genindex.html" /> <link rel="search" title="Search" href="../search.html" /> <meta name="viewport" content="width=device-width,initial-scale=1.0"> <!--[if lt IE 9]> <script type="text/javascript" src="_static/css3-mediaqueries.js"></script> <![endif]--> </head><body> <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="nav-item nav-item-0"><a href="../index.html">SQLObject 3.7.0 documentation</a> »</li> </ul> </div> <div class="sphinxsidebar" role="navigation" aria-label="main navigation"> <div class="sphinxsidebarwrapper"> <div role="note" aria-label="source link"> <h3>This Page</h3> <ul class="this-page-menu"> <li><a href="../_sources/api/sqlobject.classregistry.rst.txt" rel="nofollow">Show Source</a></li> </ul> </div> <div id="searchbox" style="display: none" role="search"> <h3>Quick search</h3> <div class="searchformwrapper"> <form class="search" action="../search.html" method="get"> <input type="text" name="q" /> <input type="submit" value="Go" /> <input type="hidden" name="check_keywords" value="yes" /> <input type="hidden" name="area" value="default" /> </form> </div> </div> <script type="text/javascript">$('#searchbox').show(0);</script> </div> </div> <div class="document"> <div class="documentwrapper"> <div class="bodywrapper"> <div class="body" role="main"> <div class="section" id="module-sqlobject.classregistry"> <span id="sqlobject-classregistry-module"></span><h1>sqlobject.classregistry module<a class="headerlink" href="#module-sqlobject.classregistry" title="Permalink to this headline">¶</a></h1> <dl class="docutils"> <dt>classresolver.py</dt> <dd>2 February 2004, Ian Bicking <<a class="reference external" href="mailto:ianb%40colorstudy.com">ianb<span>@</span>colorstudy<span>.</span>com</a>></dd> </dl> <p>Resolves strings to classes, and runs callbacks when referenced classes are created.</p> <p>Classes are referred to only by name, not by module. So that identically-named classes can coexist, classes are put into individual registries, which are keyed on strings (names). These registries are created on demand.</p> <p>Use like:</p> <div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="kn">import</span> <span class="nn">classregistry</span> <span class="gp">>>> </span><span class="n">registry</span> <span class="o">=</span> <span class="n">classregistry</span><span class="o">.</span><span class="n">registry</span><span class="p">(</span><span class="s1">'MyModules'</span><span class="p">)</span> <span class="gp">>>> </span><span class="k">def</span> <span class="nf">afterMyClassExists</span><span class="p">(</span><span class="bp">cls</span><span class="p">):</span> <span class="gp">... </span> <span class="nb">print</span><span class="p">(</span><span class="s1">'Class finally exists: </span><span class="si">%s</span><span class="s1">'</span> <span class="o">%</span> <span class="bp">cls</span><span class="p">)</span> <span class="gp">>>> </span><span class="n">registry</span><span class="o">.</span><span class="n">addClassCallback</span><span class="p">(</span><span class="s1">'MyClass'</span><span class="p">,</span> <span class="n">afterMyClassExists</span><span class="p">)</span> <span class="gp">>>> </span><span class="k">class</span> <span class="nc">MyClass</span><span class="p">:</span> <span class="gp">... </span> <span class="k">pass</span> <span class="gp">>>> </span><span class="n">registry</span><span class="o">.</span><span class="n">addClass</span><span class="p">(</span><span class="n">MyClass</span><span class="p">)</span> <span class="go">Class finally exists: MyClass</span> </pre></div> </div> <dl class="class"> <dt id="sqlobject.classregistry.ClassRegistry"> <em class="property">class </em><code class="descclassname">sqlobject.classregistry.</code><code class="descname">ClassRegistry</code><span class="sig-paren">(</span><em>name</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/sqlobject/classregistry.html#ClassRegistry"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#sqlobject.classregistry.ClassRegistry" title="Permalink to this definition">¶</a></dt> <dd><p>Bases: <code class="xref py py-class docutils literal notranslate"><span class="pre">object</span></code></p> <p>We’ll be dealing with classes that reference each other, so class C1 may reference C2 (in a join), while C2 references C1 right back. Since classes are created in an order, there will be a point when C1 exists but C2 doesn’t. So we deal with classes by name, and after each class is created we try to fix up any references by replacing the names with actual classes.</p> <p>Here we keep a dictionaries of class names to classes – note that the classes might be spread among different modules, so since we pile them together names need to be globally unique, to just module unique. Like needSet below, the container dictionary is keyed by the class registry.</p> <dl class="method"> <dt id="sqlobject.classregistry.ClassRegistry.addCallback"> <code class="descname">addCallback</code><span class="sig-paren">(</span><em>callback</em>, <em>*args</em>, <em>**kw</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/sqlobject/classregistry.html#ClassRegistry.addCallback"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#sqlobject.classregistry.ClassRegistry.addCallback" title="Permalink to this definition">¶</a></dt> <dd><p>This callback is called for all classes, not just specific ones (like addClassCallback).</p> </dd></dl> <dl class="method"> <dt id="sqlobject.classregistry.ClassRegistry.addClass"> <code class="descname">addClass</code><span class="sig-paren">(</span><em>cls</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/sqlobject/classregistry.html#ClassRegistry.addClass"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#sqlobject.classregistry.ClassRegistry.addClass" title="Permalink to this definition">¶</a></dt> <dd><p>Everytime a class is created, we add it to the registry, so that other classes can find it by name. We also call any callbacks that are waiting for the class.</p> </dd></dl> <dl class="method"> <dt id="sqlobject.classregistry.ClassRegistry.addClassCallback"> <code class="descname">addClassCallback</code><span class="sig-paren">(</span><em>className</em>, <em>callback</em>, <em>*args</em>, <em>**kw</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/sqlobject/classregistry.html#ClassRegistry.addClassCallback"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#sqlobject.classregistry.ClassRegistry.addClassCallback" title="Permalink to this definition">¶</a></dt> <dd><p>Whenever a name is substituted for the class, you can register a callback that will be called when the needed class is created. If it’s already been created, the callback will be called immediately.</p> </dd></dl> <dl class="method"> <dt id="sqlobject.classregistry.ClassRegistry.allClasses"> <code class="descname">allClasses</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="../_modules/sqlobject/classregistry.html#ClassRegistry.allClasses"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#sqlobject.classregistry.ClassRegistry.allClasses" title="Permalink to this definition">¶</a></dt> <dd></dd></dl> <dl class="method"> <dt id="sqlobject.classregistry.ClassRegistry.getClass"> <code class="descname">getClass</code><span class="sig-paren">(</span><em>className</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/sqlobject/classregistry.html#ClassRegistry.getClass"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#sqlobject.classregistry.ClassRegistry.getClass" title="Permalink to this definition">¶</a></dt> <dd></dd></dl> </dd></dl> <dl class="function"> <dt id="sqlobject.classregistry.findClass"> <code class="descclassname">sqlobject.classregistry.</code><code class="descname">findClass</code><span class="sig-paren">(</span><em>name</em>, <em>class_registry=None</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/sqlobject/classregistry.html#findClass"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#sqlobject.classregistry.findClass" title="Permalink to this definition">¶</a></dt> <dd></dd></dl> </div> </div> </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="nav-item nav-item-0"><a href="../index.html">SQLObject 3.7.0 documentation</a> »</li> </ul> </div> <div class="footer" role="contentinfo"> © Copyright 2004-2018, Ian Bicking and contributors. Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.7.4. </div> </body> </html>