Am 05.11.2013 um 13:25 schrieb Laufens Van Houtven <[email protected]>:

> You probably want to read this:
> 
> https://twistedmatrix.com/documents/current/core/howto/application.html
> 
> 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 :)


I try to write the plugin now:
…
from zope.interface import implements

from twisted.application.service import IServiceMaker
from twisted.application import internet
from twisted.plugin import IPlugin
from twisted.python import usage

from meteo import meteoFactory

class Options(usage.Options):
        optParameters = [       ['port', 'p', 80, 'The port number to listen 
on.'],
                                                ['ipv4_address', '4', None, 
'The IPv4 address to listen on.'],
                                                ['ipv6_address', '6', None, 
'The IPv6 address to listen on.']]

class MeteoServiceMaker(object):
        implements(IServiceMaker, IPlugin)
        tapname = 'meteo'
        description = 'A web application for the meteo package'
        options = Options

        def makeService(self, options):
                """
                Constructs a TCP server from a factory defined in meteo.py
                """
                return internet.TCPServer(      int(options['port'], 
                                                                        
interface=options['ipv4_address'],      ## how do it set the ip6 address?
                                                                        
meteoFactory())

serviceMaker = MeteoServiceMaker()
---
--- relevant part of metro.py:
resource = RootWeatherPage()
meteoFactory = Site(resource)
--- 
Currently, this gives following error:
---
[meteo] [www4:py-venv/meteo/meteo] root# twistd --help
Unhandled Error
Traceback (most recent call last):
  File 
"/usr/local/py-venv/meteo/lib/python2.7/site-packages/twisted/python/usage.py", 
line 450, in __str__
    return self.getSynopsis() + '\n' + self.getUsage(width=None)
  File 
"/usr/local/py-venv/meteo/lib/python2.7/site-packages/twisted/python/usage.py", 
line 486, in getUsage
    for (cmd, short, parser, desc) in self.subCommands:
  File 
"/usr/local/py-venv/meteo/lib/python2.7/site-packages/twisted/application/app.py",
 line 631, in subCommands
    for plug in sorted(plugins, key=attrgetter('tapname')):
  File 
"/usr/local/py-venv/meteo/lib/python2.7/site-packages/twisted/plugin.py", line 
209, in getPlugins
    allDropins = getCache(package)
--- <exception caught here> ---
  File 
"/usr/local/py-venv/meteo/lib/python2.7/site-packages/twisted/plugin.py", line 
167, in getCache
    provider = pluginModule.load()
  File 
"/usr/local/py-venv/meteo/lib/python2.7/site-packages/twisted/python/modules.py",
 line 383, in load
    return self.pathEntry.pythonPath.moduleLoader(self.name)
  File 
"/usr/local/py-venv/meteo/lib/python2.7/site-packages/twisted/python/_reflectpy3.py",
 line 266, in namedAny
    topLevelPackage = _importAndCheckStack(trialname)
  File 
"/usr/local/py-venv/meteo/lib/python2.7/site-packages/twisted/python/_reflectpy3.py",
 line 205, in _importAndCheckStack
    return __import__(importName)
exceptions.SyntaxError: invalid syntax (meteo_plugin.py, line 29)
---
Line 29 is
        serviceMaker = MeteoServiceMaker()
What is wrong there?

Thanks,
Axel
---
PGP-Key:29E99DD6  ☀ +49 151 2300 9283  ☀ computing @ chaos claudius

_______________________________________________
Twisted-web mailing list
[email protected]
http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-web

Reply via email to