Skip to content

Commit

Permalink
Fix Py file borrower to become functional
Browse files Browse the repository at this point in the history
Apparently, `PyFileBorrower` uses default `FileReader` which implies
using MIB files extensions rather than .py. This commit makes
`FileReader` objects using alternative extensions when being run
by `PyFileBorrower`.
  • Loading branch information
etingof committed Apr 14, 2019
1 parent 827a9a3 commit 7158d47
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 13 deletions.
1 change: 1 addition & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Revision 0.3.4, XX-01-2019
- Added `implied` key to JSON SNMP table index structure
- Rebased MIB importing code onto `importlib` because `imp` is long
deprecated
- Fixed Py file borrower to become functional

Revision 0.3.3, 29-12-2018
--------------------------
Expand Down
2 changes: 1 addition & 1 deletion pysmi/borrower/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,4 @@ def getData(self, mibname, **kwargs):
debug.logger('trying to borrow file %s from %s' % (mibname, self._reader))
)

return self._reader.getData(mibname)
return self._reader.getData(mibname, exts=self.exts)
6 changes: 3 additions & 3 deletions pysmi/reader/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def setOptions(self, **kwargs):
setattr(self, k, kwargs[k])
return self

def getMibVariants(self, mibname):
def getMibVariants(self, mibname, exts=None):
filenames = []

if self.originalMatching:
Expand All @@ -45,7 +45,7 @@ def getMibVariants(self, mibname):
filenames.append(suffixed.upper())
filenames.append(suffixed.lower())

return ((x, x + y) for x in filenames for y in self.exts)
return ((x, x + y) for x in filenames for y in exts or self.exts)

def getData(self, filename):
def getData(self, filename, exts=None):
raise NotImplementedError()
2 changes: 1 addition & 1 deletion pysmi/reader/callback.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def __init__(self, cbFun, cbCtx=None):
def __str__(self):
return '%s{"%s"}' % (self.__class__.__name__, self._cbFun)

def getData(self, mibname):
def getData(self, mibname, exts=None):
debug.logger & debug.flagReader and debug.logger('calling user callback %s for MIB %s' % (self._cbFun, mibname))

res = self._cbFun(mibname, self._cbCtx)
Expand Down
4 changes: 2 additions & 2 deletions pysmi/reader/ftpclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def __init__(self, host, locationTemplate, timeout=5, ssl=False, port=21,
def __str__(self):
return '%s{"ftp://%s%s"}' % (self.__class__.__name__, self._host, self._locationTemplate)

def getData(self, mibname):
def getData(self, mibname, exts=None):
if self._ssl:
conn = ftplib.FTP_TLS()
else:
Expand All @@ -74,7 +74,7 @@ def getData(self, mibname):

debug.logger & debug.flagReader and debug.logger('looking for MIB %s' % mibname)

for mibalias, mibfile in self.getMibVariants(mibname):
for mibalias, mibfile in self.getMibVariants(mibname, exts):
location = self._locationTemplate.replace('@mib@', mibfile)

mtime = time.time()
Expand Down
4 changes: 2 additions & 2 deletions pysmi/reader/httpclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def __init__(self, host, port, locationTemplate, timeout=5, ssl=False):
def __str__(self):
return self._url

def getData(self, mibname):
def getData(self, mibname, exts=None):
headers = {
'Accept': 'text/plain',
'User-Agent': self._user_agent
Expand All @@ -72,7 +72,7 @@ def getData(self, mibname):

debug.logger & debug.flagReader and debug.logger('looking for MIB %s' % mibname)

for mibalias, mibfile in self.getMibVariants(mibname):
for mibalias, mibfile in self.getMibVariants(mibname, exts):
if self.MIB_MAGIC in self._url:
url = self._url.replace(self.MIB_MAGIC, mibfile)
else:
Expand Down
4 changes: 2 additions & 2 deletions pysmi/reader/localfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def loadIndex(indexFile):

return mibIndex

def getMibVariants(self, mibname):
def getMibVariants(self, mibname, exts=None):
if self.useIndexFile:
if not self._indexLoaded:
self._mibIndex = self.loadIndex(
Expand All @@ -96,7 +96,7 @@ def getMibVariants(self, mibname):
'found %s in MIB index: %s' % (mibname, self._mibIndex[mibname]))
return [(mibname, self._mibIndex[mibname])]

return super(FileReader, self).getMibVariants(mibname)
return super(FileReader, self).getMibVariants(mibname, exts)

def getData(self, mibname):
debug.logger & debug.flagReader and debug.logger(
Expand Down
4 changes: 2 additions & 2 deletions pysmi/reader/zipreader.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ def _readZipFile(self, refs):
def __str__(self):
return '%s{"%s"}' % (self.__class__.__name__, self._name)

def getData(self, mibname, zipBlob=None):
def getData(self, mibname, exts=None, zipBlob=None):
debug.logger & debug.flagReader and debug.logger('looking for MIB %s at %s' % (mibname, self._name))

if self._pendingError:
Expand All @@ -165,7 +165,7 @@ def getData(self, mibname, zipBlob=None):
if not self._members:
raise error.PySmiReaderFileNotFoundError('source MIB %s not found' % mibname, reader=self)

for mibalias, mibfile in self.getMibVariants(mibname):
for mibalias, mibfile in self.getMibVariants(mibname, exts):

debug.logger & debug.flagReader and debug.logger('trying MIB %s' % mibfile)

Expand Down

0 comments on commit 7158d47

Please sign in to comment.