Skip to content

Commit

Permalink
Black tool related changes
Browse files Browse the repository at this point in the history
  • Loading branch information
rahkumar651991 committed Sep 28, 2020
1 parent 6b622d5 commit d11e2e0
Show file tree
Hide file tree
Showing 11 changed files with 62 additions and 52 deletions.
7 changes: 4 additions & 3 deletions lib/jnpr/junos/cfg/phyport/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@

class PhyPort(object):
def __new__(cls, dev, name=None):
supercls = {"CLASSIC": PhyPortClassic, "SWITCH": PhyPortSwitch,}.get(
dev.facts["ifd_style"]
)
supercls = {
"CLASSIC": PhyPortClassic,
"SWITCH": PhyPortSwitch,
}.get(dev.facts["ifd_style"])
newcls = type(cls.__name__, (supercls,), {})
return newcls(dev, name)
24 changes: 12 additions & 12 deletions lib/jnpr/junos/cfg/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -535,11 +535,11 @@ def __setattr__(self, name, value):

def __repr__(self):
"""
stringify for debug/printing
stringify for debug/printing
this will show the resource manager (class) name,
the resource (Junos) name, and the contents
of the :has: dict and the contents of the :should: dict
this will show the resource manager (class) name,
the resource (Junos) name, and the contents
of the :has: dict and the contents of the :should: dict
"""
mgr_name = self.__class__.__name__
return (
Expand Down Expand Up @@ -600,9 +600,9 @@ def _xml_at_res(self, xml):

def _xml_build_change(self):
"""
iterate through the :should: properties creating the
necessary configuration change structure. if there
are no changes, then return :None:
iterate through the :should: properties creating the
necessary configuration change structure. if there
are no changes, then return :None:
"""
edit_xml = self._xml_edit_at_res()

Expand Down Expand Up @@ -638,8 +638,8 @@ def _xml_build_change(self):

def _r_config_write_xml(self, xml):
"""
write the xml change to the Junos device,
trapping on exceptions.
write the xml change to the Junos device,
trapping on exceptions.
"""
top_xml = xml.getroottree().getroot()

Expand Down Expand Up @@ -757,8 +757,8 @@ def _xml_hook_on_new(self, xml):

def _r_when_new(self):
"""
called by :read(): when the resource is new; i.e.
there is no existing Junos configuration
called by :read(): when the resource is new; i.e.
there is no existing Junos configuration
"""
pass

Expand Down Expand Up @@ -786,7 +786,7 @@ def _r_has_init(self):
@classmethod
def _r_has_xml_status(klass, as_xml, as_py):
"""
set the 'exists' and 'active' :has: values
set the 'exists' and 'active' :has: values
"""
as_py[P_JUNOS_ACTIVE] = False if as_xml.attrib.get("inactive") else True
as_py[P_JUNOS_EXISTS] = True
Expand Down
20 changes: 10 additions & 10 deletions lib/jnpr/junos/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -422,15 +422,15 @@ def re_name(self, value):
raise RuntimeError("re_name is read-only!")

def _sshconf_lkup(self):
""" Controls the ssh connection:
If using ssh_private_key_file on MacOS Mojave or greater
(specifically > OpenSSH_7.4p1) ensure that the keys are generated
in PEM format or convert existing 'new' keys to the PEM format:
Check format: `head -n1 ~/.ssh/some_key`
Correct RSA fomat: -----BEGIN RSA PRIVATE KEY-----
Incorrect OPENSSH format: -----BEGIN OPENSSH PRIVATE KEY-----
Convert an OPENSSH key to an RSA key: `ssh-keygen -p -m PEM -f ~/.ssh/some_key`
"""
"""Controls the ssh connection:
If using ssh_private_key_file on MacOS Mojave or greater
(specifically > OpenSSH_7.4p1) ensure that the keys are generated
in PEM format or convert existing 'new' keys to the PEM format:
Check format: `head -n1 ~/.ssh/some_key`
Correct RSA fomat: -----BEGIN RSA PRIVATE KEY-----
Incorrect OPENSSH format: -----BEGIN OPENSSH PRIVATE KEY-----
Convert an OPENSSH key to an RSA key: `ssh-keygen -p -m PEM -f ~/.ssh/some_key`
"""
if self.__class__.__name__ == "Device" and self._sock_fd is not None:
return None
if self._ssh_config:
Expand Down Expand Up @@ -1116,7 +1116,7 @@ def __init__(self, *vargs, **kvargs):
:param str sock_fd:
**REQUIRED** file descriptor of an existing socket instead of providing a host.
Used for outbound ssh.
Used for outbound ssh.
:param str user:
*OPTIONAL* login user-name, uses $USER if not provided
Expand Down
14 changes: 7 additions & 7 deletions lib/jnpr/junos/exception.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ class RpcError(Exception):

def __init__(self, cmd=None, rsp=None, errs=None, dev=None, timeout=None, re=None):
"""
:cmd: is the rpc command
:rsp: is the rpc response (after <rpc-reply>)
:errs: is a list of dictionaries of extracted <rpc-error> elements.
:dev: is the device rpc was executed on
:timeout: is the timeout value of the device
:re: is the RE or member exception occured on
:cmd: is the rpc command
:rsp: is the rpc response (after <rpc-reply>)
:errs: is a list of dictionaries of extracted <rpc-error> elements.
:dev: is the device rpc was executed on
:timeout: is the timeout value of the device
:re: is the RE or member exception occured on
"""
self.cmd = cmd
self.rsp = rsp
Expand Down Expand Up @@ -71,7 +71,7 @@ def __init__(self, cmd=None, rsp=None, errs=None, dev=None, timeout=None, re=Non

def __repr__(self):
"""
pprints the response XML attribute
pprints the response XML attribute
"""
if self.rpc_error is not None:
return "{}(severity: {}, bad_element: {}, message: {})".format(
Expand Down
1 change: 1 addition & 0 deletions lib/jnpr/junos/factcache.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,4 +296,5 @@ def _refresh(

# Precede the class's documentation with the documentation on the specific
# facts from the jnpr.junos.facts package.
print(__doc__)
__doc__ = facts_doc + "Implementation details on the _FactCache class:" + __doc__
9 changes: 6 additions & 3 deletions lib/jnpr/junos/factory/cfgtable.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,12 @@ def _validate_value(self, field_name, value, opt):
"""

def _get_field_type(ftype):
ft = {"str": str, "int": int, "float": float, "bool": bool,}.get(
ftype, None
)
ft = {
"str": str,
"int": int,
"float": float,
"bool": bool,
}.get(ftype, None)

if ft is None:
raise TypeError("Unsupported type %s\n" % (ftype))
Expand Down
4 changes: 3 additions & 1 deletion lib/jnpr/junos/facts/current_re.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ def get_facts(device):
current_re.append(re_name[0].text)
else:
rsp = device.rpc.get_interface_information(
normalize=True, routing_instance="__juniper_private1__", terse=True,
normalize=True,
routing_instance="__juniper_private1__",
terse=True,
)

# Get the local IPv4 addresses from the response.
Expand Down
4 changes: 2 additions & 2 deletions lib/jnpr/junos/jxml.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,8 @@ def remove_namespaces_and_spaces(xml):

def rpc_error(rpc_xml):
"""
extract the various bits from an <rpc-error> element
into a dictionary
extract the various bits from an <rpc-error> element
into a dictionary
"""
remove_namespaces(rpc_xml)

Expand Down
24 changes: 12 additions & 12 deletions lib/jnpr/junos/rpcmeta.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ class _RpcMetaExec(object):

def __init__(self, junos):
"""
~PRIVATE CLASS~
creates an RPC meta-executor object bound to the provided
ez-netconf :junos: object
~PRIVATE CLASS~
creates an RPC meta-executor object bound to the provided
ez-netconf :junos: object
"""
self._junos = junos

Expand Down Expand Up @@ -303,12 +303,12 @@ def cli(self, command, format="text", normalize=False):

def __getattr__(self, rpc_cmd_name):
"""
metaprograms a function to execute the :rpc_cmd_name:
metaprograms a function to execute the :rpc_cmd_name:
the caller will be passing (*vargs, **kvargs) on
execution of the meta function; these are the specific
rpc command arguments(**kvargs) and options bound
as XML attributes (*vargs)
the caller will be passing (*vargs, **kvargs) on
execution of the meta function; these are the specific
rpc command arguments(**kvargs) and options bound
as XML attributes (*vargs)
"""

rpc_cmd = re.sub("_", "-", rpc_cmd_name)
Expand Down Expand Up @@ -378,10 +378,10 @@ def _exec_rpc(*vargs, **kvargs):

def __call__(self, rpc_cmd, **kvargs):
"""
callable will execute the provided :rpc_cmd: against the
attached :junos: object and return the RPC response per
:junos:execute()
callable will execute the provided :rpc_cmd: against the
attached :junos: object and return the RPC response per
:junos:execute()
kvargs is simply passed 'as-is' to :junos:execute()
kvargs is simply passed 'as-is' to :junos:execute()
"""
return self._junos.execute(rpc_cmd, **kvargs)
2 changes: 1 addition & 1 deletion lib/jnpr/junos/utils/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ def load(self, *vargs, **kvargs):
:param dict template_vars:
Used in conjunction with the other template options. This parameter
contains a dictionary of variables to render into the template.
:param ignore_warning: A boolean, string or list of string.
If the value is True, it will ignore all warnings regardless of the
warning message. If the value is a string, it will ignore
Expand Down
5 changes: 4 additions & 1 deletion tests/unit/utils/test_ftp.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,10 @@ def test_ftp_dnload_file(self, mock_ftpretr, mock_open):
@patch("ftplib.FTP.login")
@patch("ftplib.FTP.retrbinary")
def test_ftp_dnload_file_get_rf_filename_cb(
self, mock_ftp_connect, mock_ftp_login, mock_ftp_retrbinary,
self,
mock_ftp_connect,
mock_ftp_login,
mock_ftp_retrbinary,
):
def callback():
pass
Expand Down

0 comments on commit d11e2e0

Please sign in to comment.