File: __init__.py

package info (click to toggle)
python-pysnmp4 4.1.6a-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 1,016 kB
  • ctags: 1,826
  • sloc: python: 9,809; sh: 60; makefile: 11
file content (28 lines) | stat: -rw-r--r-- 860 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
"""Various components of SNMP applications"""
import os
import sys
import string

def switchApiVersion(subPkg):
    pkg = os.path.split(__path__[0])[-1]
    newMod = __import__(subPkg, globals(), locals(), pkg)
    realPkg = '_real_' + pkg
    if sys.modules.has_key(realPkg):
        sys.modules[pkg] = sys.modules[realPkg]
    sys.modules[realPkg] = sys.modules[pkg]
    sys.modules[pkg] = newMod

def __isSubPackage(subDir):
    if subDir and subDir[0] == 'v' and subDir[1] in string.digits \
           and len(subDir) == 2:
        return 1

subDirs = filter(__isSubPackage, os.listdir(__path__[0]))
subDirs.sort(); subDirs.reverse()

if os.environ.has_key('PYSNMP_API_VERSION'):
    v = os.environ['PYSNMP_API_VERSION']
    if v:
        switchApiVersion(v)   # do not load any API
else:
    switchApiVersion(subDirs[-1])  # take the most recent version