def main(self):
#        sys.stdout.write("Handle Connect Request Start\n")
        self.control_message = None
        self.had_response = False
        buff = Linebuffer()
        lines = []
        fail = False
        try:
            while True:
                for data in self.Inbox("inbox"):
                    buff.feed(data)
                while buff.chompable():
                    line = buff.chomp()
                    lines.append(line)
                    if line == "\r\n":
                        # We've now got the complete header.
                        # We're now expecting a body, but SHOULD handle it.
                        # For now, let's just handle the response line since it's all we really care about.
                        rest = lines[1:]
                        rline = lines[0]

                        p = rline.find(" ") 
                        if p == -1:
                            raise GeneralFail("HTTP Response Line Parse Failure: "+ repr(http_response_line))
                        http_version = rline[:p]
                        rline = rline[p+1:]

                        p = rline.find(" ") 
                        if p == -1:
                            raise GeneralFail("HTTP Response Line Parse Failure: "+ repr(rline))
                        http_status = rline[:p]
                        human_status = rline[p+1:]

                        if 0:
                            Print ("http_version,http_status,human_status",http_version,http_status,human_status)

                        if http_status != "200":
                            raise GeneralFail("HTTP Connect Failure : "+ repr(rline))

                    self.had_response = True

                self.checkControl()

                if not self.anyReady():
                    self.pause()
                yield 1
        except ShutdownNow:
            pass
        except GeneralFail:
            # Yes, we're masking an error. This is nasty.
            fail = True
        
        if not fail:
            self.send(status("success"), "signal")
        else:
            self.send(status("fail"), "signal")
        if self.control_message:
            self.send(self.control_message, "signal")
        else:
            self.send(Axon.Ipc.producerFinished(), "signal")
 def main(self):
     theMessage = "Some Message" * 85
     while self.packetsToSend:
         self.send(theMessage, "outbox")
         #while not self.dataReady("inbox"):
         self.pause()  # This means we wait for any message on any inbox
         yield status("ready")
         if self.dataReady("inbox"):  # If it isn't this, where is it?
             data = self.recv("inbox")
             if data == theMessage:
                 #print "GOOD"
                 self.packetsToSend -= 1
             else:
                 print "BAD"
                 return
     print "GOOD"
     return
 def main(self):
     theMessage = "Some Message" * 85
     while self.packetsToSend:
         self.send(theMessage, "outbox")
         # while not self.dataReady("inbox"):
         self.pause()  # This means we wait for any message on any inbox
         yield status("ready")
         if self.dataReady("inbox"):  # If it isn't this, where is it?
             data = self.recv("inbox")
             if data == theMessage:
                 # print "GOOD"
                 self.packetsToSend -= 1
             else:
                 print "BAD"
                 return
     print "GOOD"
     return
    def main(self):
        try:
            while True:
                for data in self.Inbox("inbox"):
                    sys.stdout.write( self.name )
                    sys.stdout.write( " : ")
                    sys.stdout.write( str( data) )
                    self.had_response = True
                
                self.checkControl()

                if not self.anyReady():
                    self.pause()
                yield 1
        except ShutdownNow:
            pass

        self.send(status("success"), "signal")
        if self.control_message:
            self.send(self.control_message, "signal")
        else:
            self.send(Axon.Ipc.producerFinished(), "signal")
    def main(self):
        try:
            while True:
                for data in self.Inbox("inbox"):
                    sys.stdout.write( self.name )
                    sys.stdout.write( " : ")
                    sys.stdout.write( str( data) )
                    self.had_response = True
                
                self.checkControl()

                if not self.anyReady():
                    self.pause()
                yield 1
        except ShutdownNow:
            pass

        self.send(status("success"), "signal")
        if self.control_message:
            self.send(self.control_message, "signal")
        else:
            self.send(Axon.Ipc.producerFinished(), "signal")
 def main(self):
     """Main loop"""
     self.send(self.msg,"outbox")
     yield 1
     self.send(status("Fail"),"signal")
class HandleConnectRequest(component):
    def checkControl(self):
        for message in self.Inbox("control"): # Cleanly clear the inbox
            self.control_message = message
        if isinstance(self.control_message,shutdownMicroprocess):
            raise ShutdownNow
        if self.control_message:
            if self.had_response:
                raise ShutdownNow

    def main(self):
#        sys.stdout.write("Handle Connect Request Start\n")
        self.control_message = None
        self.had_response = False
        buff = Linebuffer()
        lines = []
        fail = False
        try:
            while True:
                for data in self.Inbox("inbox"):
                    buff.feed(data)
                while buff.chompable():
                    line = buff.chomp()
                    lines.append(line)
                    if line == "\r\n":
                        # We've now got the complete header.
                        # We're now expecting a body, but SHOULD handle it.
                        # For now, let's just handle the response line since it's all we really care about.
                        rest = lines[1:]
                        rline = lines[0]

                        p = rline.find(" ") 
                        if p == -1:
                            raise GeneralFail("HTTP Response Line Parse Failure: "+ repr(http_response_line))
                        http_version = rline[:p]
                        rline = rline[p+1:]

                        p = rline.find(" ") 
                        if p == -1:
                            raise GeneralFail("HTTP Response Line Parse Failure: "+ repr(rline))
                        http_status = rline[:p]
                        human_status = rline[p+1:]

                        if 0:
                            Print ("http_version,http_status,human_status",http_version,http_status,human_status)

                        if http_status != "200":
                            raise GeneralFail("HTTP Connect Failure : "+ repr(rline))

                    self.had_response = True

                self.checkControl()

                if not self.anyReady():
                    self.pause()
                yield 1
        except ShutdownNow:
            pass
        except GeneralFail, e:
            # Yes, we're masking an error. This is nasty.
            fail = True
        
        if not fail:
            self.send(status("success"), "signal")
        else:
            self.send(status("fail"), "signal")
        if self.control_message:
            self.send(self.control_message, "signal")
        else:
            self.send(Axon.Ipc.producerFinished(), "signal")
 def main(self):
     """Main loop"""
     self.send(self.msg,"outbox")
     yield 1
     self.send(status("Fail"),"signal")