コード例 #1
0
 def resolve (request):
         if not request.dns_resources:
                 return 
         
         dispatcher.mx_records = request.dns_resources[:] # copy!
         tcp_client.connect (
                 dispatcher, (dispatcher.mx_records.pop (0), 25)
                 )
コード例 #2
0
def main(count=0, host='127.0.0.2', port=14000, timeout=3.0, precision=1.0):
    # server
    async_loop.catch(
        tcp_server.Listen(ZHUB, (host, port), precision, 5).server_shutdown)
    # client
    tags = []
    zhub = async_chat.Trempoline()
    zhub.protocol = zhub_list(tags, count)

    def finalize(dispatcher):
        if dispatcher.closing:
            dispatcher.log(tags, 'ok')
        else:
            dispatcher.log('failed to connect', 'error')

    zhub.finalization = finalize
    tcp_client.connect(zhub, (host, port), timeout)
    del zhub
コード例 #3
0
ファイル: root.py プロジェクト: BackupTheBerlios/allegra-svn
 def new_password (self, about): 
         mailto = smtp_client.Pipeline()
         if tcp_client.connect (mailto, self.smtp_relay):
                 def pipeline_close (smtp):
                         smtp.output_fifo.append ('QUIT\r\n')
                 mailto (
                         '*****@*****.**', 
                         ['*****@*****.**'],
                         http.uri + '?root=%s' % self.root_password
                         ).finalization = pipeline_close
コード例 #4
0
    def __init__(authorized, username, password, host, port=110, timeout=3.0):
        pipeline = Pipeline()
        if not tcp_client.connect(pipeline, (host, port), timeout):
            return

        self.pipeline = pipeline
        self.pop_uidl = {}  # {'uid': N, ...}
        self.pop_list = []  # [top]
        self.pop_update()
        pipeline.pop_capable(any_capabilities)
        pipeline.pop_authorize(username, password, self.pop3_update)
コード例 #5
0
ファイル: root.py プロジェクト: BackupTheBerlios/allegra-svn
    def new_password(self, about):
        mailto = smtp_client.Pipeline()
        if tcp_client.connect(mailto, self.smtp_relay):

            def pipeline_close(smtp):
                smtp.output_fifo.append('QUIT\r\n')

            mailto(
                '*****@*****.**', ['*****@*****.**'],
                http.uri +
                '?root=%s' % self.root_password).finalization = pipeline_close
コード例 #6
0
def main (
    count=0, host='127.0.0.2', port=14000, timeout=3.0, precision=1.0
    ):
    # server
    async_loop.catch (tcp_server.Listen (
        ZHUB, (host, port), precision, 5
        ).server_shutdown)
    # client
    tags = []
    zhub = async_chat.Trempoline ()
    zhub.protocol = zhub_list (tags, count)
    
    def finalize (dispatcher):
        if dispatcher.closing:
            dispatcher.log (tags, 'ok')
        else:
            dispatcher.log ('failed to connect', 'error')

    zhub.finalization = finalize
    tcp_client.connect (zhub, (host, port), timeout)
    del zhub
コード例 #7
0
 def __init__ (
         authorized, username, password, host, port=110, timeout=3.0
         ):
         pipeline = Pipeline ()
         if not tcp_client.connect (pipeline, (host, port), timeout):
                 return
         
         self.pipeline = pipeline
         self.pop_uidl = {} # {'uid': N, ...}
         self.pop_list = [] # [top]
         self.pop_update ()
         pipeline.pop_capable (any_capabilities)
         pipeline.pop_authorize (
                 username, password, self.pop3_update
                 )
コード例 #8
0
def try_next_mx(dispatcher):
    if not (dispatcher.connected or dispatcher.closing):
        if tcp_client.connect(dispatcher, (dispatcher.mx_records.pop(0), 25)):
            dispatcher.finalization = try_next_mx(d)
コード例 #9
0
    def resolve(request):
        if not request.dns_resources:
            return

        dispatcher.mx_records = request.dns_resources[:]  # copy!
        tcp_client.connect(dispatcher, (dispatcher.mx_records.pop(0), 25))
コード例 #10
0
def connect(host, port=80, version='1.1', timeout=3.0):
    dispatcher = pipeline(host, port, version)
    tcp_client.connect(dispatcher, (host, port), timeout)
    return dispatcher
コード例 #11
0
def connect (host, port=80, version='1.1', timeout=3.0):
        dispatcher = pipeline (host, port, version)
        tcp_client.connect (dispatcher, (host, port), timeout)
        return dispatcher
コード例 #12
0
def try_next_mx (dispatcher):
        if not (dispatcher.connected or dispatcher.closing):
                if tcp_client.connect (
                        dispatcher, (dispatcher.mx_records.pop (0), 25)
                        ):
                        dispatcher.finalization = try_next_mx (d)
コード例 #13
0
from allegra import (loginfo, async_loop, async_chat, collector, tcp_client)

dispatcher = async_chat.Dispatcher()
if tcp_client.connect(dispatcher, ("planetpython.org", 80), 3.0):
    dispatcher.async_chat_push('GET /rss20.xml HTTP/1.0\r\n'
                               'Host: planetpython.org\r\n'
                               'Accept: text/xml; charset=UTF-8\r\n'
                               '\r\n')
    collector.bind(dispatcher, collector.DEVNULL)
del dispatcher
async_loop.dispatch()


#
# a convenience to ...
#
def getXMLUTF8(dispatcher, host, path, version="1.0", connection="Keep-Alive"):
    dispatcher.async_chat_push('GET %s HTTP/%s\r\n'
                               'Host: %s\r\n'
                               'Accept: text/xml; charset=UTF-8\r\n'
                               'Connection: %s\r\n'
                               '\r\n' % (path, version, host, connection))
    return dispatcher


#
# ... use Connections and HTTP/1.0
#
connections = tcp_client.Connections(0.3, 0.1)
for host, path in [
    ("planetpython.org", "/rss20.xml"),
コード例 #14
0
    def callback(self, resultset):
        assert None == loginfo.log('%r' % resultset)
        try:
            stmt, param = loads(statements.next())
        except StopIteration:
            self.handle_close()
        except:
            self.loginfo_traceback()
        else:
            Dispatcher.statements_count += 1
            self(self.callback, stmt, param)


try:
    for ansql in (Dispatcher() for i in xrange(clients)):
        if tcp_client.connect(ansql, addr):
            stmt, param = loads(statements.next())
            Dispatcher.stmt_count += 1
            if Dispatcher.stmt_count < Dispatcher.stmt_limit:
                sql(sql.test_callback, stmt, param)
except:
    loginfo.traceback()
    sys.exit(2)

started = time.time()
async_loop.dispatch()
finalization.collect()
loginfo.log(
    '%d statements in %f seconds' %
    (Dispatcher.stmt_count, time.time() - started), 'info')
sys.exit(0)
コード例 #15
0
        def callback (self, resultset):
                assert None == loginfo.log ('%r' % resultset)
                try:
                        stmt, param = loads (statements.next ())
                except StopIteration:
                        self.handle_close ()
                except:
                        self.loginfo_traceback ()
                else:
                        Dispatcher.statements_count += 1
                        self (self.callback, stmt, param)
        
try:
        for ansql in (Dispatcher () for i in xrange (clients)):
                if tcp_client.connect (ansql, addr):
                        stmt, param = loads (statements.next ())
                        Dispatcher.stmt_count += 1
                        if Dispatcher.stmt_count < Dispatcher.stmt_limit:
                                sql (sql.test_callback, stmt, param)
except:
        loginfo.traceback ()
        sys.exit (2)
        
started = time.time ()
async_loop.dispatch ()
finalization.collect ()
loginfo.log ('%d statements in %f seconds' % (
        Dispatcher.stmt_count, time.time () - started
        ), 'info')
sys.exit (0)