Ticket #637: odd-filenaming-637.patch
| File odd-filenaming-637.patch, 2.9 KB (added by thijs, 5 years ago) |
|---|
-
doc/core/howto/tutorial/intro.xhtml
156 156 <p>After saving the next example (finger11.py) as <q>finger.tac</q>, 157 157 read on to find out how to run this code using the twistd utility.</p> 158 158 159 <a href="listings/finger/finger11.py" class="py-listing">finger11.py</a>160 161 162 163 159 <h2>twistd</h2> 164 160 165 161 <p>This is how to run <q>Twisted Applications</q> — files which define an … … 170 166 application developer can concentrate on writing his networking code. 171 167 </p> 172 168 169 <a href="listings/finger/finger11.tac" class="py-listing">finger11.tac</a> 170 173 171 <pre class="shell"> 174 root% twistd -ny finger .tac # just like before175 root% twistd -y finger .tac # daemonize, keep pid in twistd.pid176 root% twistd -y finger .tac --pidfile=finger.pid177 root% twistd -y finger .tac --rundir=/178 root% twistd -y finger .tac --chroot=/var179 root% twistd -y finger .tac -l /var/log/finger.log180 root% twistd -y finger .tac --syslog # just log to syslog181 root% twistd -y finger .tac --syslog --prefix=twistedfinger # use given prefix172 root% twistd -ny finger11.tac # just like before 173 root% twistd -y finger11.tac # daemonize, keep pid in twistd.pid 174 root% twistd -y finger11.tac --pidfile=finger.pid 175 root% twistd -y finger11.tac --rundir=/ 176 root% twistd -y finger11.tac --chroot=/var 177 root% twistd -y finger11.tac -l /var/log/finger.log 178 root% twistd -y finger11.tac --syslog # just log to syslog 179 root% twistd -y finger11.tac --syslog --prefix=twistedfinger # use given prefix 182 180 </pre> 183 181 184 182 </body> -
doc/core/howto/tutorial/listings/finger/finger11.py
1 # Read username, output from non-empty factory, drop connections2 # Use deferreds, to minimize synchronicity assumptions3 # Write application. Save in 'finger.tpy'4 from twisted.application import internet, service5 from twisted.internet import protocol, reactor, defer6 from twisted.protocols import basic7 class FingerProtocol(basic.LineReceiver):8 def lineReceived(self, user):9 self.factory.getUser(user10 ).addErrback(lambda _: "Internal error in server"11 ).addCallback(lambda m:12 (self.transport.write(m+"\r\n"),13 self.transport.loseConnection()))14 class FingerFactory(protocol.ServerFactory):15 protocol = FingerProtocol16 def __init__(self, **kwargs): self.users = kwargs17 def getUser(self, user):18 return defer.succeed(self.users.get(user, "No such user"))19 20 application = service.Application('finger', uid=1, gid=1)21 factory = FingerFactory(moshez='Happy and well')22 internet.TCPServer(79, factory).setServiceParent(23 service.IServiceCollection(application))
