File: __init__.py

package info (click to toggle)
python-pysnmp4 4.1.9a-2
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 1,068 kB
  • ctags: 1,969
  • sloc: python: 10,608; sh: 44; makefile: 10
file content (27 lines) | stat: -rw-r--r-- 844 bytes parent folder | download | duplicates (2)
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
"""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())
    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

if os.environ.has_key('PYSNMP_API_VERSION'):
    v = os.environ['PYSNMP_API_VERSION']
    if v:
        switchApiVersion(v)   # do not load any API
else:
    subDirs = filter(__isSubPackage, os.listdir(__path__[0]))
    subDirs.sort();
    switchApiVersion(subDirs[-1])  # take the most recent version