[issue1636] Execfile unable to take arguments beyond 255!

2007-12-15 Thread Jack Atkinson

New submission from Jack Atkinson:

I found this problem while using PySNMP and trying to load a custom MIB
converted to python code.  Inside the PySNMP, it uses execfile() to load
the python MIBs, and I assume so it won't be put into a separate
namespace.  On one particular MIB, which I cannot modify because it's a
company product MIB, this error of unable to take in more than 255
arguments occurs.  The problem line is quite long, but surely in this
day and age of 32 bit to 64 bit machines this 255 constraint could be
done away with in the execfile function.  I'm assuming the 255
constraint has something to do with unsigned 8 bit number.

--
components: Interpreter Core
messages: 58668
nosy: jgatkinsn
severity: normal
status: open
title: Execfile unable to take arguments beyond 255!
type: rfe
versions: Python 2.5

__
Tracker <[EMAIL PROTECTED]>
<http://bugs.python.org/issue1636>
__
___
Python-bugs-list mailing list 
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue1636] Execfile unable to take arguments beyond 255!

2007-12-16 Thread Jack Atkinson

Jack Atkinson added the comment:

Error message from ipython console:
In [28]: mibBuilder2 = builder.MibBuilder().loadModules('ADTRAN-TC')
---
   Traceback (most recent call last)

C:\Documents and Settings\Jack Atkinson\ in ()

c:\python25\lib\site-packages\pysnmp\v4\smi\builder.py in
loadModules(self, *mod
Names)
 80 del self.__modPathsSeen[modPath]
 81 raise error.SmiError(
---> 82 'MIB module \"%s\" load error: %s' %
(modPath, why)
 83 )
 84

: MIB module
"c:\python25\lib\site-packages\p
ysnmp\v4\smi\mibs\ADTRAN-TC.py" load error: more than 255 arguments
(ADTRAN-TC.p
y, line 33)


Here's the code that loads it:
try:
execfile(modPath, g)
except StandardError,
why: del self.__modPathsSeen[modPath]
raise error.SmiError( 'MIB module \"%s\" load error: %s' % (modPath, why) )

Added file: http://bugs.python.org/file8968/builder.py

__
Tracker <[EMAIL PROTECTED]>
<http://bugs.python.org/issue1636>
__# MIB modules loader
import os
from pysnmp.smi import error
try:
import pysnmp_mibs
except ImportError:
pysnmp_mibs = None
from pysnmp import debug

class MibBuilder:
def __init__(self):
self.lastBuildId = self._autoName = 0L
paths = (
os.path.join(os.path.split(error.__file__)[0], 'mibs','instances'),
os.path.join(os.path.split(error.__file__)[0], 'mibs')
)
if os.environ.has_key('PYSNMP_MIB_DIR'):
paths = paths + (
os.path.join(os.path.split(os.environ['PYSNMP_MIB_DIR'])[0]),
)
if pysnmp_mibs:
paths = paths + (
os.path.join(os.path.split(pysnmp_mibs.__file__)[0]),
)
self.mibSymbols = {}
self.__modSeen = {}
self.__modPathsSeen = {}
apply(self.setMibPath, paths)

# MIB modules management

def setMibPath(self, *mibPaths):
self.__mibPaths = map(os.path.normpath, mibPaths)
debug.logger & debug.flagBld and debug.logger('setMibPath: new MIB path 
%s' % (self.__mibPaths,))

def getMibPath(self): return tuple(self.__mibPaths)

def loadModules(self, *modNames):
# Build a list of available modules
if not modNames:
modNames = {}
for mibPath in self.__mibPaths:
try:
for modName in os.listdir(mibPath):
if modName == '__init__.py' or modName[-3:] != '.py':
continue
modNames[modName[:-3]] = None
except OSError:
continue
modNames = modNames.keys()
if not modNames:
raise error.SmiError(
'No MIB module to load at %s' % (self,)
)
for modName in modNames:
for mibPath in self.__mibPaths:
modPath = os.path.join(
mibPath, modName + '.py'
)

debug.logger & debug.flagBld and debug.logger('loadModules: 
trying %s' % modPath)

try:
open(modPath).close()
except IOError, why:
debug.logger & debug.flagBld and debug.logger('loadModules: 
open() %s' % why)
continue

if self.__modPathsSeen.has_key(modPath):
debug.logger & debug.flagBld and debug.logger('loadModules: 
seen %s' % modPath)
continue
else:
self.__modPathsSeen[modPath] = 1

g = { 'mibBuilder': self }

try:
execfile(modPath, g)
except StandardError, why:
del self.__modPathsSeen[modPath]
raise error.SmiError(
'MIB module \"%s\" load error: %s' % (modPath, why)
)

self.__modSeen[modName] = modPath

debug.logger & debug.flagBld and debug.logger('loadModules: 
loaded %s' % modPath)

break

if not self.__modSeen.has_key(modName):
raise error.SmiError(
'MIB file \"%s.py\" not found in search path' % modName
)

return self

def unloadModules(self, *modNames):
if not modNames:
modNames = self.mibSymbols.keys()
for modName in modNames:
if not self