base.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 » base.py
"""Defines standard API to asyncore-based transport"""
try:
    from sys import version_info
except ImportError:
    version_info = ( 0, 0 )   # a really early version
import socket, sys
import asyncore
from pysnmp.carrier import error

class AbstractSocketTransport(asyncore.dispatcher):
    sockFamily = sockType = None
    retryCount = 0; retryInterval = 0
    def __init__(self, sock=None, sockMap=None):
        if sock is None:
            if self.sockFamily is None:
                raise error.CarrierError(
                    'Address family %s not supported' % self.__class__.__name__
                    )
            if self.sockType is None:
                raise error.CarrierError(
                    'Socket type %s not supported' % self.__class__.__name__
                    )
            try:
                sock = socket.socket(self.sockFamily, self.sockType)
            except socket.error, why:
                raise error.CarrierError('socket() failed: %s' % why)
        if sockMap is None:
            # The socket map is managed by the AsynsockDispatcher on
            # which this transport is registered, so this is a fake
            # socket map to avoid registering with deafult asyncore map.
            sockMap = {}
        # Old asyncore doesn't allow socket_map param in constructor
        if version_info < (2, 0):
            # Taken from dispatcher.__init__()
            self.socket = sock
            self.add_channel(sockMap)
            self.socket.setblocking(0)
            self.connected = 1
        else:
            asyncore.dispatcher.__init__(self, sock, sockMap)

    # Old asyncore doesn't allow socket_map param
    if version_info < (2, 0):
        def add_channel (self, sockMap=None):
            if sockMap is None:
                sockMap = asyncore.socket_map
            sockMap[self] = self

        def del_channel (self, sockMap=None):
            if sockMap is None:
                sockMap = asyncore.socket_map
            if sockMap.has_key(self):
                del sockMap[self]

    def registerSocket(self, sockMap=None):
        self.add_channel(sockMap)
        
    def unregisterSocket(self, sockMap=None):
        self.del_channel(sockMap)
        
    # Public API
    
    def openClientMode(self, iface=None):
        raise error.CarrierError('Method not implemented')

    def openServerMode(self, iface=None):
        raise error.CarrierError('Method not implemented')
        
    def sendMessage(self, outgoingMessage, transportAddress):
        raise error.CarrierError('Method not implemented')

    def registerCbFun(self, cbFun):
        self._cbFun = cbFun

    def unregisterCbFun(self):
        self._cbFun = None

    def closeTransport(self):
        self.unregisterCbFun()
        self.close()
        
    # asyncore API
    def handle_close(self): raise error.CarrierError(
        'Transport unexpectedly closed'
        )
    def handle_error(self): raise

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.