Skip to content

Commit

Permalink
Merge callater-finger-3375: Added the stopService and startService me…
Browse files Browse the repository at this point in the history
…thods to all finger example files.

Author: thijs
Reviewer: cyli
Fixes: #3375


git-svn-id: svn://svn.twistedmatrix.com/svn/Twisted/trunk@30555 bbbe8e31-12d6-0310-92fd-ac37d47ddeeb
  • Loading branch information
thijstriemstra committed Jan 22, 2011
1 parent 06d5440 commit 7492c8c
Show file tree
Hide file tree
Showing 13 changed files with 378 additions and 88 deletions.
67 changes: 52 additions & 15 deletions doc/core/howto/tutorial/listings/finger/finger/finger.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,28 @@
class IFingerService(Interface):

def getUser(user):
"""Return a deferred returning a string"""
"""
Return a deferred returning a string.
"""

def getUsers():
"""Return a deferred returning a list of strings"""
"""
Return a deferred returning a list of strings.
"""


class IFingerSetterService(Interface):

def setUser(user, status):
"""Set the user's status to something"""
"""
Set the user's status to something.
"""


def catchError(err):
return "Internal error in server"


class FingerProtocol(basic.LineReceiver):

def lineReceived(self, user):
Expand All @@ -42,10 +51,14 @@ def writeValue(value):
class IFingerFactory(Interface):

def getUser(user):
"""Return a deferred returning a string"""
"""
Return a deferred returning a string.
"""

def buildProtocol(addr):
"""Return a protocol returning a string"""
"""
Return a protocol returning a string.
"""


class FingerFactoryFromService(protocol.ServerFactory):
Expand All @@ -63,6 +76,7 @@ def getUser(self, user):
IFingerService,
IFingerFactory)


class FingerSetterProtocol(basic.LineReceiver):

def connectionMade(self):
Expand All @@ -79,10 +93,14 @@ def connectionLost(self, reason):
class IFingerSetterFactory(Interface):

def setUser(user, status):
"""Return a deferred returning a string"""
"""
Return a deferred returning a string.
"""

def buildProtocol(addr):
"""Return a protocol returning a string"""
"""
Return a protocol returning a string.
"""


class FingerSetterFactoryFromService(protocol.ServerFactory):
Expand All @@ -102,6 +120,7 @@ def setUser(self, user, status):
IFingerSetterService,
IFingerSetterFactory)


class IRCReplyBot(irc.IRCClient):

def connectionMade(self):
Expand All @@ -124,10 +143,14 @@ class IIRCClientFactory(Interface):
"""

def getUser(user):
"""Return a deferred returning a string"""
"""
Return a deferred returning a string.
"""

def buildProtocol(addr):
"""Return a protocol"""
"""
Return a protocol.
"""


class IRCClientFactoryFromService(protocol.ClientFactory):
Expand All @@ -147,6 +170,7 @@ def getUser(self, user):
IFingerService,
IIRCClientFactory)


class UserStatusTree(resource.Resource):

template = """<html><head><title>Users</title></head><body>
Expand Down Expand Up @@ -229,10 +253,15 @@ def xmlrpc_getUsers(self):
class IPerspectiveFinger(Interface):

def remote_getUser(username):
"""return a user's status"""
"""
Return a user's status.
"""

def remote_getUsers():
"""return a user's status"""
"""
Return a user's status.
"""


class PerspectiveFingerFromService(pb.Root):

Expand All @@ -258,7 +287,6 @@ class FingerService(service.Service):

def __init__(self, filename):
self.filename = filename
self._read()

def _read(self):
self.users = {}
Expand All @@ -275,22 +303,31 @@ def getUser(self, user):
def getUsers(self):
return defer.succeed(self.users.keys())

def startService(self):
self._read()
service.Service.startService(self)

def stopService(self):
service.Service.stopService(self)
self.call.cancel()


class ServerContextFactory:

def getContext(self):
"""Create an SSL context.
"""
Create an SSL context.
This is a sample implementation that loads a certificate from a file
called 'server.pem'."""
called 'server.pem'.
"""
ctx = SSL.Context(SSL.SSLv23_METHOD)
ctx.use_certificate_file('server.pem')
ctx.use_privatekey_file('server.pem')
return ctx




# Easy configuration

def makeService(config):
Expand Down
2 changes: 2 additions & 0 deletions doc/core/howto/tutorial/listings/finger/finger14.tac
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class FingerProtocol(basic.LineReceiver):
self.transport.loseConnection()
d.addCallback(writeResponse)


class FingerService(service.Service):
def __init__(self, filename):
self.users = {}
Expand Down Expand Up @@ -46,6 +47,7 @@ class FingerService(service.Service):
f.getUser = self.getUser
return f


application = service.Application('finger', uid=1, gid=1)
f = FingerService('/etc/users')
finger = internet.TCPServer(79, f.getFingerFactory())
Expand Down
12 changes: 11 additions & 1 deletion doc/core/howto/tutorial/listings/finger/finger15.tac
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class FingerProtocol(basic.LineReceiver):
self.transport.loseConnection()
d.addCallback(writeResponse)


class FingerResource(resource.Resource):

def __init__(self, users):
Expand All @@ -39,11 +40,11 @@ class FingerResource(resource.Resource):
text = '<h1>%s</h1><p>No such user</p>' % username
return static.Data(text, 'text/html')


class FingerService(service.Service):
def __init__(self, filename):
self.filename = filename
self.users = {}
self._read()

def _read(self):
self.users.clear()
Expand All @@ -67,6 +68,15 @@ class FingerService(service.Service):
r = FingerResource(self.users)
return r

def startService(self):
self._read()
service.Service.startService(self)

def stopService(self):
service.Service.stopService(self)
self.call.cancel()


application = service.Application('finger', uid=1, gid=1)
f = FingerService('/etc/users')
serviceCollection = service.IServiceCollection(application)
Expand Down
11 changes: 10 additions & 1 deletion doc/core/howto/tutorial/listings/finger/finger16.tac
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ class IRCReplyBot(irc.IRCClient):
irc.IRCClient.msg(self, user, msg+': '+message)
d.addCallback(writeResponse)


class FingerService(service.Service):
def __init__(self, filename):
self.filename = filename
self.users = {}
self._read()

def _read(self):
self.users.clear()
Expand Down Expand Up @@ -80,6 +80,15 @@ class FingerService(service.Service):
f.getUser = self.getUser
return f

def startService(self):
self._read()
service.Service.startService(self)

def stopService(self):
service.Service.stopService(self)
self.call.cancel()


application = service.Application('finger', uid=1, gid=1)
f = FingerService('/etc/users')
serviceCollection = service.IServiceCollection(application)
Expand Down
12 changes: 11 additions & 1 deletion doc/core/howto/tutorial/listings/finger/finger17.tac
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class FingerProtocol(basic.LineReceiver):
self.transport.loseConnection()
d.addCallback(writeResponse)


class IRCReplyBot(irc.IRCClient):
def connectionMade(self):
self.nickname = self.factory.nickname
Expand All @@ -37,11 +38,11 @@ class IRCReplyBot(irc.IRCClient):
irc.IRCClient.msg(self, user, msg+': '+message)
d.addCallback(writeResponse)


class FingerService(service.Service):
def __init__(self, filename):
self.filename = filename
self.users = {}
self._read()

def _read(self):
self.users.clear()
Expand Down Expand Up @@ -80,6 +81,15 @@ class FingerService(service.Service):
f.getUser = self.getUser
return f

def startService(self):
self._read()
service.Service.startService(self)

def stopService(self):
service.Service.stopService(self)
self.call.cancel()


application = service.Application('finger', uid=1, gid=1)
f = FingerService('/etc/users')
serviceCollection = service.IServiceCollection(application)
Expand Down
11 changes: 10 additions & 1 deletion doc/core/howto/tutorial/listings/finger/finger18.tac
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import cgi
def catchError(err):
return "Internal error in server"


class FingerProtocol(basic.LineReceiver):

def lineReceived(self, user):
Expand Down Expand Up @@ -57,6 +58,7 @@ class UserStatusTree(resource.Resource):
else:
return UserStatus(path, self.service)


class UserStatus(resource.Resource):

def __init__(self, user, service):
Expand Down Expand Up @@ -89,7 +91,6 @@ class FingerService(service.Service):
def __init__(self, filename):
self.filename = filename
self.users = {}
self._read()

def _read(self):
self.users.clear()
Expand Down Expand Up @@ -125,6 +126,14 @@ class FingerService(service.Service):
f.getUser = self.getUser
return f

def startService(self):
self._read()
service.Service.startService(self)

def stopService(self):
service.Service.stopService(self)
self.call.cancel()


application = service.Application('finger', uid=1, gid=1)
f = FingerService('/etc/users')
Expand Down
Loading

0 comments on commit 7492c8c

Please sign in to comment.