示例#1
0
文件: opt.py 项目: danse/asynode
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()
示例#2
0
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()
示例#3
0
文件: echo.py 项目: danse/asynode
        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()
示例#4
0
        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()
示例#5
0
文件: http.py 项目: pti-infra/asynode
        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()
示例#6
0
文件: echo.py 项目: z4r/asynode
    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()