[Twisted-Python] Naming of Names

Moshe Zadka m at moshez.org
Tue Sep 25 00:22:45 MDT 2001


Hi!
I've written the following cool module to help with unit testing
and other beasts. I really want to check it in, but I want to make
sure I don't offend anyone's sensibilities. For me, this name is both
natural and descriptive, but...
(it already found two bugs in the SMTP module, by the way) 

>--------------------------------------<
class MasturbatoryRelay:

    buffer = ''
    shouldLose = 0
    log = ''

    def __init__(self, target):
        self.target = target

    def write(self, data):
        print "writing", `data`
        self.buffer = self.buffer + data

    def clearBuffer(self):
        try:
            self.target.dataReceived(self.buffer)
        finally:
            self.buffer = ''
        if self.shouldLose:
            self.target.connectionLost()

    def loseConnection(self):
        self.shouldLose = 1

def masturbate(server, client):
    serverToClient = MasturbatoryRelay(client)
    clientToServer = MasturbatoryRelay(server)
    server.makeConnection(serverToClient)
    client.makeConnection(clientToServer)
    while 1:
        serverToClient.clearBuffer()
        clientToServer.clearBuffer()
        if serverToClient.shouldLose or clientToServer.shouldLose:
            break
    return clientToServer.log 
>--------------------------------------<

-- 
The Official Moshe Zadka FAQ: http://moshez.geek
The Official Moshe Zadka FAQ For Dummies: http://moshez.org
Read the FAQ





More information about the Twisted-Python mailing list