def main_mail(instate, outstate): def interactive(): import socket source = raw_input("Please enter a source: ") targets = raw_input("Please enter a list of targets [',' separated]: ") message = [raw_input("Please enter text to send [CRTL+C to STOP]: ")] while True: try: message.append(raw_input()) except KeyboardInterrupt: break return dict( #auth = ('user', 'pass'), localname = socket.getfqdn(), source = source, targets = targets.split(','), message = '\n'.join(message), ) import logging logging.basicConfig(level=logging.INFO) options, args = parse_input() from core import ConnectionFactory node = ConnectionFactory( instate=instate, outstate=outstate ) if options.server: node.listen(options.host, options.port) else: kwargs = interactive() node.send( options.host, options.port, *args, **kwargs ) main_loop()
try: return State.get_push(push=self._data.pop(0)+'\n') except IndexError: return State.get_final(push='\n') class EchoIncomingAutomaton(Automaton): def initial(self, data): return State.get_push(terminator='\n') def operative(self, data): if data: return State.get_push(push=data+'\n') else: return State.get_final() if __name__ == '__main__': import logging logging.basicConfig(level=logging.INFO) from opt import parse_input, main_loop OPTIONS, ARGS = parse_input() NODE = ConnectionFactory( instate=EchoIncomingAutomaton, outstate=EchoOutcomingAutomaton ) if OPTIONS.server: NODE.listen(OPTIONS.host, OPTIONS.port) else: NODE.send(OPTIONS.host, OPTIONS.port, *ARGS) main_loop()
return State.get_push(terminator=CRLF * 2) def operative(self, data): if data: return State.get_final(close=True) push = ' '.join([self._method, self._path, HTTP]) for k, v in self._headers.iteritems(): push += CRLF + k + ': ' + v push += CRLF * 2 return State.get_push(push=push) if __name__ == '__main__': import logging logging.basicConfig(level=logging.INFO) options, args = parse_input() from core import ConnectionFactory node = ConnectionFactory(instate=None, outstate=HTTPOutcomingAutomaton) if options.server: node.listen(options.host, options.port) else: kwargs = { 'path': '/api/1.0/', 'hostname': options.host, 'headers': { 'Accept': 'application/xml' } } node.send(options.host, options.port, *args, **kwargs) main_loop()
if data: return State.get_final(close=True) push = ' '.join([self._method, self._path, HTTP]) for k,v in self._headers.iteritems(): push += CRLF + k + ': ' + v push += CRLF*2 return State.get_push(push=push) if __name__ == '__main__': import logging logging.basicConfig(level=logging.INFO) options, args = parse_input() from core import ConnectionFactory node = ConnectionFactory( instate=None, outstate=HTTPOutcomingAutomaton ) if options.server: node.listen(options.host, options.port) else: kwargs = { 'path':'/api/1.0/', 'hostname': options.host, 'headers': { 'Accept': 'application/xml' } } node.send( options.host, options.port, *args, **kwargs ) main_loop()
def operative(self, data): try: return State.get_push(push=self._data.pop(0) + '\n') except IndexError: return State.get_final(push='\n') class EchoIncomingAutomaton(Automaton): def initial(self, data): return State.get_push(terminator='\n') def operative(self, data): if data: return State.get_push(push=data + '\n') else: return State.get_final() if __name__ == '__main__': import logging logging.basicConfig(level=logging.INFO) from opt import parse_input, main_loop OPTIONS, ARGS = parse_input() NODE = ConnectionFactory(instate=EchoIncomingAutomaton, outstate=EchoOutcomingAutomaton) if OPTIONS.server: NODE.listen(OPTIONS.host, OPTIONS.port) else: NODE.send(OPTIONS.host, OPTIONS.port, *ARGS) main_loop()