/usr/lib/python2.7/dist-packages/jnpr/junos/factory/viewfields.py is in python-junos-eznc 2.0.1-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 | class ViewFields(object):
"""
Used to dynamically create a field dictionary used with the
RunstatView class
"""
def __init__(self):
self._fields = dict()
def _prockvargs(self, field, name, **kvargs):
if not len(kvargs):
return
field[name].update(kvargs)
@property
def end(self):
return self._fields
def str(self, name, xpath=None, **kvargs):
""" field is a string """
if xpath is None:
xpath = name
field = {name: {'xpath': xpath}}
self._prockvargs(field, name, **kvargs)
self._fields.update(field)
return self
def astype(self, name, xpath=None, astype=int, **kvargs):
"""
field string value will be passed to function :astype:
This is typically used to do simple type conversions,
but also works really well if you set :astype: to
a function that does a basic converstion like look
at the value and change it to a True/False. For
example:
astype=lambda x: True if x == 'enabled' else False
"""
if xpath is None:
xpath = name
field = {
name: {'xpath': xpath, 'astype': astype}
}
self._prockvargs(field, name, **kvargs)
self._fields.update(field)
return self
def int(self, name, xpath=None, **kvargs):
""" field is an integer """
return self.astype(name, xpath, int, **kvargs)
def flag(self, name, xpath=None, **kvargs):
"""
field is a flag, results in True/False if the xpath element exists or
not. Model this as a boolean type <bool>
"""
return self.astype(name, xpath, bool, **kvargs)
def group(self, name, xpath=None, **kvargs):
"""
field is an apply group, results in value of group attr if the xpath
element has the associated group attribute.
"""
xpath = './{0}/@group'.format(xpath)
return self.astype(name, xpath, str, **kvargs)
def table(self, name, table):
""" field is a RunstatTable """
self._fields.update({
name: {'table': table}
})
return self
|