dispatch.py :  » Network » Python-SNMP » pysnmp-4.1.13a » pysnmp » carrier » asynsock » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » Network » Python SNMP 
Python SNMP » pysnmp 4.1.13a » pysnmp » carrier » asynsock » dispatch.py
try:
    from sys import version_info
except ImportError:
    version_info = ( 0, 0 )   # a really early version
from time import time
from select import select
from asyncore import socket_map
from pysnmp.carrier.base import AbstractTransportDispatcher

# Old asyncore doesn't allow socket_map param at poll
if version_info < (2, 0):
    def poll(timeout, socket_map):
        if not socket_map:
            return
        sockets = socket_map.keys()
        r = filter(lambda x: x.readable(), sockets)
        w = filter(lambda x: x.writable(), sockets)

        (r,w,e) = select(r, w, [], timeout)

        for x in r:
            try:
                x.handle_read_event()
            except:
                x.handle_error()
        for x in w:
            try:
                x.handle_write_event()
            except:
                x.handle_error()
else:
    from asyncore import poll

class AsynsockDispatcher(AbstractTransportDispatcher):
    """Implements I/O over asynchronous sockets"""
    def __init__(self):
        self.__sockMap = {} # use own map for MT safety
        self.timeout = 1.0
        AbstractTransportDispatcher.__init__(self)

    def getSocketMap(self): return self.__sockMap
    def setSocketMap(self, sockMap=socket_map): self.__sockMap = sockMap
    
    def registerTransport(self, tDomain, t):
        AbstractTransportDispatcher.registerTransport(self, tDomain, t)
        t.registerSocket(self.__sockMap)

    def unregisterTransport(self, tDomain):
        self.getTransport(tDomain).unregisterSocket(self.__sockMap)
        AbstractTransportDispatcher.unregisterTransport(self, tDomain)

    def transportsAreWorking(self):
        for transport in self.__sockMap.values():
            if transport.writable():
                return 1
        return 0
    
    def runDispatcher(self, timeout=0.0):
        while self.jobsArePending() or self.transportsAreWorking():
            poll(self.timeout, self.__sockMap)
            self.handleTimerTick(time())
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.