示例#1
0
def main (
    database=':memory:', host='127.0.0.2', port=3999,
    precision=1.0, inactive=3.0, local=512, private=1, public=1,
    log_buffer_size=4096, anetlog_host='', anetlog_port=3998
    ):
    import time
    started = time.time ()
    from allegra import netstring, loginfo, tcp_server, ansqlite
    if anetlog_host:
            from allegra import anetlog
            anetlog.stdoe ((anetlog_host, anetlog_port))
    loginfo.log (
        'ansqlite - Copyright 2007 Laurent Szyster | Copyleft GPL 2.0', 'info'
        )
    conn, Dispatcher = ansqlite.open (database)
    ansql = Dispatcher.ansql 
    loads = ansqlite.loads
    for data in netstring.netpipe ((
        lambda r=sys.stdin.read: r (log_buffer_size)
        )):
        ansql (*loads(data)).close ()
    del ansql, loads
    listen = tcp_server.decorate (tcp_server.Listen (
        Dispatcher, (host, port), precision, max=5
        ), inactive, local, private, public)
    async_loop.catch (listen.server_shutdown)
    def finalize (listen):
        anetlog.disconnect ()
        conn.close ()
        
    listen.finalization = finalize
    del listen
    loginfo.log ('loaded in %f seconds' % (time.time () - started), 'info')
示例#2
0
def main(database=':memory:',
         host='127.0.0.2',
         port=3999,
         precision=1.0,
         inactive=3.0,
         local=512,
         private=1,
         public=1,
         log_buffer_size=4096,
         anetlog_host='',
         anetlog_port=3998):
    import time
    started = time.time()
    from allegra import netstring, loginfo, tcp_server, ansqlite
    if anetlog_host:
        from allegra import anetlog
        anetlog.stdoe((anetlog_host, anetlog_port))
    loginfo.log('ansqlite - Copyright 2007 Laurent Szyster | Copyleft GPL 2.0',
                'info')
    conn, Dispatcher = ansqlite.open(database)
    ansql = Dispatcher.ansql
    loads = ansqlite.loads
    for data in netstring.netpipe(
        (lambda r=sys.stdin.read: r(log_buffer_size))):
        ansql(*loads(data)).close()
    del ansql, loads
    listen = tcp_server.decorate(
        tcp_server.Listen(Dispatcher, (host, port), precision, max=5),
        inactive, local, private, public)
    async_loop.catch(listen.server_shutdown)

    def finalize(listen):
        anetlog.disconnect()
        conn.close()

    listen.finalization = finalize
    del listen
    loginfo.log('loaded in %f seconds' % (time.time() - started), 'info')
 import sys, time
 from allegra import async_loop, finalization
 loginfo.log (
         'Allegra PNS/TCP Client'
         ' - Copyright 2005 Laurent A.V. Szyster | Copyleft GPL 2.0',
         'info'
         ) 
                 
 if len (sys.argv) > 1:
         if len (sys.argv) > 2:
                 addr = tuple (sys.argv[1:2])
         else:
                 addr = (sys.argv[1], 3534)
 else:
         addr = ('127.0.0.1', 3534)
 Pipe (addr, netstring.netpipe (lambda: sys.stdin.read (4096)))
 async_loop.loop ()
 assert None == finalization.collect ()
 #
 # Allegra PNS/TCP Client
 #
 # The reference implementation of a PNS/TCP pipe, it is one usefull
 # module to develop PNS user agents, but also a nice command line
 # tool to feed and query the peer.
 #
 # As a pipe it reads from STDIN a sequence of netstrings and pipes 
 # them to a PNS/TCP session, then writes relevant statements coming
 # back from the peer to STDOUT and drops the irrelevant statements
 # to STDERR. Example:
 #
 #    python pns_client.py < session.pns 1> signal 2> noise
示例#4
0
if __name__ == '__main__':
    import sys, time
    from allegra import async_loop, finalization
    loginfo.log(
        'Allegra PNS/TCP Client'
        ' - Copyright 2005 Laurent A.V. Szyster | Copyleft GPL 2.0', 'info')

    if len(sys.argv) > 1:
        if len(sys.argv) > 2:
            addr = tuple(sys.argv[1:2])
        else:
            addr = (sys.argv[1], 3534)
    else:
        addr = ('127.0.0.1', 3534)
    Pipe(addr, netstring.netpipe(lambda: sys.stdin.read(4096)))
    async_loop.loop()
    assert None == finalization.collect()
    #
    # Allegra PNS/TCP Client
    #
    # The reference implementation of a PNS/TCP pipe, it is one usefull
    # module to develop PNS user agents, but also a nice command line
    # tool to feed and query the peer.
    #
    # As a pipe it reads from STDIN a sequence of netstrings and pipes
    # them to a PNS/TCP session, then writes relevant statements coming
    # back from the peer to STDOUT and drops the irrelevant statements
    # to STDERR. Example:
    #
    #    python pns_client.py < session.pns 1> signal 2> noise
示例#5
0
#
# You should have received a copy of the GNU General Public License
# along with this library; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

"http://laurentszyster.be/blog/ansqlite/"

import sys, time

from allegra import (netstring, loginfo, async_loop, finalization, ip_peer,
                     tcp_client, ansqlite)

loads = ansqlite.loads
dumps = ansqlite.dumps
try:
    statements = netstring.netpipe(lambda r=sys.stdin.read: r(4096))
    addr = ip_peer.addr(sys.argv[1], 3999)
    clients = int(sys.argv[2])
except:
    loginfo.traceback()
    sys.exit(1)


class Dispatcher(ansqlite.Client):

    statements_count = 0

    def callback(self, resultset):
        assert None == loginfo.log('%r' % resultset)
        try:
            stmt, param = loads(statements.next())
示例#6
0
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

"http://laurentszyster.be/blog/ansqlite/"

import sys, time

from allegra import (
        netstring, loginfo, async_loop, finalization, 
        ip_peer, tcp_client, ansqlite
        )

loads = ansqlite.loads
dumps = ansqlite.dumps
try:
        statements = netstring.netpipe (
                lambda r=sys.stdin.read: r (4096)
                )
        addr = ip_peer.addr (sys.argv[1], 3999)
        clients = int (sys.argv[2])
except:
        loginfo.traceback ()
        sys.exit (1)

class Dispatcher (ansqlite.Client):

        statements_count = 0

        def callback (self, resultset):
                assert None == loginfo.log ('%r' % resultset)
                try:
                        stmt, param = loads (statements.next ())
示例#7
0
         'Allegra PNS/TCP Articulator'
         ' - Copyright 2005 Laurent A.V. Szyster\n'
         )
         
 from allegra import async_loop
 
 # TODO: ... PNS_pipe
 
 ip = '127.0.0.1'
 port = 3534
 if len (sys.argv) > 1:
         if len (sys.argv) > 2:
                 port = int (sys.argv[2])
         ip = sys.argv[1]
 articulator = PNS_articulator ((ip, port))
 netpipe = netstring.netpipe (lambda: sys.stdin.read (4096))
 async_loop.dispatch ()
 assert None == finalization.collect ()
 #
 # Allegra PNS/TCP Articulator
 #
 # The reference implementation of a PNS/TCP articulator, it is one
 # usefull module to develop PNS articulators, but also a nice command
 # line tool feed a peer relevantly and "walk" its graph automatically.
 #
 # As a pipe it reads from STDIN a sequence of netstrings, 
 # first one as the session name and pipes the others to a PNS/TCP
 # session, then writes relevant statements coming back from the peer
 # to STDOUT and drops the irrelevant statements to STDERR. Example:
 #
 #    python pns_client.py < session.pns 1> signal 2> noise