Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pyeapi/api/ipinterfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ def set_address(self, name, value=None, default=False, disable=False):
default=default, disable=disable))
return self.configure(commands)

@_interpolate_docstr( 'IP_MTU_MIN', 'IP_MTU_MAX', __name__ )
@_interpolate_docstr( 'IP_MTU_MIN', 'IP_MTU_MAX' )
def set_mtu(self, name, value=None, default=False, disable=False):
""" Configures the interface IP MTU

Expand Down
10 changes: 3 additions & 7 deletions pyeapi/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,33 +255,29 @@ def __init__(self, *cli):
str) and isinstance(v, Iterable) else [v] for v in cli ]



def _interpolate_docstr( *tkns ):
"""Docstring decorator.
SYNOPSIS:

MIN_MTU=68
MAX_MTU=65535

@_interpolate_docstr( 'MIN_MTU', 'MAX_MTU', __name__ )
@_interpolate_docstr( 'MIN_MTU', 'MAX_MTU' )
def mtu_check( val ):
"check mtu against its min value (MIN_MTU) and max value (MAX_MTU)"
...

print( mtu_check.__doc__ )
check mtu against its min value (68) and max value (65535)

Note: `__name__` must be provided as the last argument, b/c the decorator
could be imported, thus the current (importing) module needs to be resolved
"""
def docstr_decorator( user_fn ):
"""update user_fn_wrapper doc string with the interpolated user_fn's
"""
def user_fn_wrapper( *args, **kwargs ):
return user_fn( *args, **kwargs )
module = sys.modules[ tkns[-1] ]
module = sys.modules[ user_fn.__module__ ]
docstr = user_fn.__doc__
for tkn in tkns[:-1]:
for tkn in tkns:
sval = str( getattr(module, tkn) )
docstr = docstr.replace( tkn, sval )
user_fn_wrapper.__doc__ = docstr
Expand Down