Skip to content

Commit

Permalink
Add **options parameter to reader's getData
Browse files Browse the repository at this point in the history
  • Loading branch information
etingof committed Apr 14, 2019
1 parent 7158d47 commit a0ae433
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 17 deletions.
9 changes: 6 additions & 3 deletions pysmi/borrower/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ def setOptions(self, **kwargs):

return self

def getData(self, mibname, **kwargs):
if bool(kwargs.get('genTexts')) != self.genTexts:
def getData(self, mibname, **options):
if bool(options.get('genTexts')) != self.genTexts:
debug.logger & debug.flagBorrower and debug.logger(
'skipping incompatible borrower %s for file %s' % (self, mibname))
raise error.PySmiFileNotFoundError(mibname=mibname, reader=self._reader)
Expand All @@ -50,4 +50,7 @@ def getData(self, mibname, **kwargs):
debug.logger('trying to borrow file %s from %s' % (mibname, self._reader))
)

return self._reader.getData(mibname, exts=self.exts)
if 'exts' not in options:
options['exts'] = self.exts

return self._reader.getData(mibname, **options)
7 changes: 4 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, exts=None):
def getMibVariants(self, mibname, **options):
filenames = []

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

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

def getData(self, filename, exts=None):
def getData(self, filename, **options):
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, exts=None):
def getData(self, mibname, **options):
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, exts=None):
def getData(self, mibname, **options):
if self._ssl:
conn = ftplib.FTP_TLS()
else:
Expand All @@ -74,7 +74,7 @@ def getData(self, mibname, exts=None):

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

for mibalias, mibfile in self.getMibVariants(mibname, exts):
for mibalias, mibfile in self.getMibVariants(mibname, **options):
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, exts=None):
def getData(self, mibname, **options):
headers = {
'Accept': 'text/plain',
'User-Agent': self._user_agent
Expand All @@ -72,7 +72,7 @@ def getData(self, mibname, exts=None):

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

for mibalias, mibfile in self.getMibVariants(mibname, exts):
for mibalias, mibfile in self.getMibVariants(mibname, **options):
if self.MIB_MAGIC in self._url:
url = self._url.replace(self.MIB_MAGIC, mibfile)
else:
Expand Down
8 changes: 4 additions & 4 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, exts=None):
def getMibVariants(self, mibname, **options):
if self.useIndexFile:
if not self._indexLoaded:
self._mibIndex = self.loadIndex(
Expand All @@ -96,15 +96,15 @@ def getMibVariants(self, mibname, exts=None):
'found %s in MIB index: %s' % (mibname, self._mibIndex[mibname]))
return [(mibname, self._mibIndex[mibname])]

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

def getData(self, mibname):
def getData(self, mibname, **options):
debug.logger & debug.flagReader and debug.logger(
'%slooking for MIB %s' % (self._recursive and 'recursively ' or '', mibname))

for path in self.getSubdirs(self._path, self._recursive, self._ignoreErrors):

for mibalias, mibfile in self.getMibVariants(mibname):
for mibalias, mibfile in self.getMibVariants(mibname, **options):
f = os.path.join(decode(path), decode(mibfile))

debug.logger & debug.flagReader and debug.logger('trying MIB %s' % f)
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, exts=None, zipBlob=None):
def getData(self, mibname, **options):
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, exts=None, zipBlob=None):
if not self._members:
raise error.PySmiReaderFileNotFoundError('source MIB %s not found' % mibname, reader=self)

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

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

Expand Down

0 comments on commit a0ae433

Please sign in to comment.