<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><br><div><div>Am 05.11.2013 um 13:25 schrieb Laufens Van Houtven <_@lvh.io>:</div><div><br></div><blockquote type="cite"><div dir="ltr">You probably want to read this:<br><br><div><div class="gmail_extra"><a href="https://twistedmatrix.com/documents/current/core/howto/application.html">https://twistedmatrix.com/documents/current/core/howto/application.html</a><br>

<br></div><div class="gmail_extra">There's a number of ways you can use twistd web, for example with a tac file, but personally I always opt for using a Twisted plugin, so you instead do twistd mything :)<br></div></div></div></blockquote></div><div apple-content-edited="true"><div><br></div><div>I try to write the plugin now:</div><div>…</div><div><div>from zope.interface import implements</div><div><br></div><div>from twisted.application.service import IServiceMaker</div><div>from twisted.application import internet</div><div>from twisted.plugin import IPlugin</div><div>from twisted.python import usage</div><div><br></div><div>from meteo import meteoFactory</div><div><br></div><div>class Options(usage.Options):</div><div><span class="Apple-tab-span" style="white-space: pre; ">       </span>optParameters = [<span class="Apple-tab-span" style="white-space: pre; ">        </span>['port', 'p', 80, 'The port number to listen on.'],</div><div><span class="Apple-tab-span" style="white-space: pre; ">                                               </span>['ipv4_address', '4', None, 'The IPv4 address to listen on.'],</div><div><span class="Apple-tab-span" style="white-space: pre; ">                                            </span>['ipv6_address', '6', None, 'The IPv6 address to listen on.']]</div><div><br></div><div>class MeteoServiceMaker(object):</div><div><span class="Apple-tab-span" style="white-space: pre; ">    </span>implements(IServiceMaker, IPlugin)</div><div><span class="Apple-tab-span" style="white-space: pre; ">        </span>tapname = 'meteo'</div><div><span class="Apple-tab-span" style="white-space: pre; "> </span>description = 'A web application for the meteo package'</div><div><span class="Apple-tab-span" style="white-space: pre; ">   </span>options = Options</div><div><span class="Apple-tab-span" style="white-space: pre; "> </span></div><div><span class="Apple-tab-span" style="white-space: pre; ">  </span>def makeService(self, options):</div><div><span class="Apple-tab-span" style="white-space: pre; ">           </span>"""</div><div><span class="Apple-tab-span" style="white-space: pre; ">                </span>Constructs a TCP server from a factory defined in meteo.py</div><div><span class="Apple-tab-span" style="white-space: pre; ">                </span>"""</div><div><span class="Apple-tab-span" style="white-space: pre; ">                </span>return internet.TCPServer(<span class="Apple-tab-span" style="white-space: pre; ">       </span>int(options['port'], </div><div><span class="Apple-tab-span" style="white-space: pre; ">                                                                        </span>interface=options['ipv4_address'],<span class="Apple-tab-span" style="white-space: pre; ">       </span>## how do it set the ip6 address?</div><div><span class="Apple-tab-span" style="white-space: pre; ">                                                                 </span>meteoFactory())<span class="Apple-tab-span" style="white-space: pre; ">                          </span></div><div><br></div><div>serviceMaker = MeteoServiceMaker()</div><div>---</div><div>--- relevant part of metro.py:<span class="Apple-tab-span" style="white-space: pre; ">        </span></div><div>resource = RootWeatherPage()</div><div>meteoFactory = Site(resource)</div><div>--- </div></div><div>Currently, this gives following error:</div><div>---</div><div><div>[meteo] [www4:py-venv/meteo/meteo] root# twistd --help</div><div>Unhandled Error</div><div>Traceback (most recent call last):</div><div>  File "/usr/local/py-venv/meteo/lib/python2.7/site-packages/twisted/python/usage.py", line 450, in __str__</div><div>    return self.getSynopsis() + '\n' + self.getUsage(width=None)</div><div>  File "/usr/local/py-venv/meteo/lib/python2.7/site-packages/twisted/python/usage.py", line 486, in getUsage</div><div>    for (cmd, short, parser, desc) in self.subCommands:</div><div>  File "/usr/local/py-venv/meteo/lib/python2.7/site-packages/twisted/application/app.py", line 631, in subCommands</div><div>    for plug in sorted(plugins, key=attrgetter('tapname')):</div><div>  File "/usr/local/py-venv/meteo/lib/python2.7/site-packages/twisted/plugin.py", line 209, in getPlugins</div><div>    allDropins = getCache(package)</div><div>--- <exception caught here> ---</div><div>  File "/usr/local/py-venv/meteo/lib/python2.7/site-packages/twisted/plugin.py", line 167, in getCache</div><div>    provider = pluginModule.load()</div><div>  File "/usr/local/py-venv/meteo/lib/python2.7/site-packages/twisted/python/modules.py", line 383, in load</div><div>    return self.pathEntry.pythonPath.moduleLoader(self.name)</div><div>  File "/usr/local/py-venv/meteo/lib/python2.7/site-packages/twisted/python/_reflectpy3.py", line 266, in namedAny</div><div>    topLevelPackage = _importAndCheckStack(trialname)</div><div>  File "/usr/local/py-venv/meteo/lib/python2.7/site-packages/twisted/python/_reflectpy3.py", line 205, in _importAndCheckStack</div><div>    return __import__(importName)</div><div>exceptions.SyntaxError: invalid syntax (meteo_plugin.py, line 29)</div><div apple-content-edited="true">---<br>Line 29 is</div><div apple-content-edited="true"><span class="Apple-tab-span" style="white-space: pre; ">  </span>serviceMaker = MeteoServiceMaker()</div><div apple-content-edited="true">What is wrong there?</div><div apple-content-edited="true"><br></div><div apple-content-edited="true">Thanks,</div><div apple-content-edited="true">Axel</div></div><div>---<br>PGP-Key:29E99DD6  ☀ +49 151 2300 9283  ☀ computing @ chaos claudius</div>
</div>
<br></body></html>