From 0f76bf59ccc330216ba04727fbebe8f67db23869 Mon Sep 17 00:00:00 2001 From: rahkumar651991 Date: Tue, 28 Jul 2020 22:19:49 +0530 Subject: [PATCH] Code changes to upgrade code having deprecation warning in latest python --- .travis.yml | 2 - INSTALL-FEDORA-CENTOS.md | 15 -------- INSTALL-FREEBSD.md | 6 --- lib/jnpr/junos/_version.py | 13 +++---- lib/jnpr/junos/cfg/user_ssh_key.py | 2 +- lib/jnpr/junos/device.py | 10 ++--- lib/jnpr/junos/exception.py | 6 +-- lib/jnpr/junos/factcache.py | 4 +- lib/jnpr/junos/factory/cfgtable.py | 2 +- lib/jnpr/junos/factory/cmdtable.py | 10 ++--- lib/jnpr/junos/factory/cmdview.py | 2 +- lib/jnpr/junos/factory/optable.py | 2 +- lib/jnpr/junos/factory/state_machine.py | 47 ++++++++++++------------ lib/jnpr/junos/factory/table.py | 4 +- lib/jnpr/junos/factory/to_json.py | 2 +- lib/jnpr/junos/factory/view.py | 2 +- lib/jnpr/junos/facts/__init__.py | 2 +- lib/jnpr/junos/facts/personality.py | 4 +- lib/jnpr/junos/facts/swver.py | 2 +- lib/jnpr/junos/ofacts/personality.py | 6 +-- lib/jnpr/junos/ofacts/routing_engines.py | 2 +- lib/jnpr/junos/rpcmeta.py | 2 +- lib/jnpr/junos/transport/tty.py | 14 +++---- lib/jnpr/junos/transport/tty_ssh.py | 2 +- lib/jnpr/junos/transport/tty_telnet.py | 2 +- lib/jnpr/junos/utils/config.py | 2 +- lib/jnpr/junos/utils/fs.py | 18 ++++----- lib/jnpr/junos/utils/ftp.py | 2 +- lib/jnpr/junos/utils/scp.py | 2 +- lib/jnpr/junos/utils/start_shell.py | 4 +- lib/jnpr/junos/utils/sw.py | 22 +++++++---- lib/jnpr/junos/utils/util.py | 4 +- setup.py | 4 +- 33 files changed, 103 insertions(+), 120 deletions(-) diff --git a/.travis.yml b/.travis.yml index 0b55b6119..2e43bdf24 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,8 +1,6 @@ language: python matrix: include: - - python: 2.7 - dist: trusty - python: 3.5 dist: trusty - python: 3.6 diff --git a/INSTALL-FEDORA-CENTOS.md b/INSTALL-FEDORA-CENTOS.md index eaf4fc2d8..8c7e86169 100644 --- a/INSTALL-FEDORA-CENTOS.md +++ b/INSTALL-FEDORA-CENTOS.md @@ -13,13 +13,6 @@ Operating Systems #### Step 1: Install Python and PIP -##### For Python 2.x: -###### For Fedora: - sudo yum install python-pip python-devel -###### For CentOS: - sudo yum install python-devel - wget https://bootstrap.pypa.io/get-pip.py -O - | sudo python - ##### For Python 3.x: ###### For Fedora: sudo yum install python3-devel @@ -32,9 +25,6 @@ Operating Systems #### Step 2: Install Junos PyEZ -##### For Python 2.x: - sudo pip install junos-eznc - ##### For Python 3.x: sudo pip3 install junos-eznc @@ -57,11 +47,6 @@ Development code can be installed directly from GitHub based on any branch, comm #### Step 4b: Install Junos PyEZ from GitHub -##### For Python 2.x: - sudo pip install git+https://github.com/Juniper/py-junos-eznc.git - or - sudo pip install git+https://github.com/Juniper/py-junos-eznc.git@ - ##### For Python 3.x: sudo pip3 install git+https://github.com/Juniper/py-junos-eznc.git or diff --git a/INSTALL-FREEBSD.md b/INSTALL-FREEBSD.md index 038b47291..8ec6b4131 100644 --- a/INSTALL-FREEBSD.md +++ b/INSTALL-FREEBSD.md @@ -11,17 +11,11 @@ FreeBSD contains py-junos-eznc in its official repositories. It could be install ## Installing from binary packages. -##### For Python 2.7 -sudo pkg install py27-junos-eznc - ##### For Python 3.6 sudo pkg install py36-junos-eznc ## Installing from ports collection -#### For Python 2.7 -sudo make -C /usr/ports/net-mgmt/py-junos-eznc install clean FLAVOR=py27 - #### For Python 3.6 sudo make -C /usr/ports/net-mgmt/py-junos-eznc install clean FLAVOR=py36 diff --git a/lib/jnpr/junos/_version.py b/lib/jnpr/junos/_version.py index 180cba836..70a64b0a7 100644 --- a/lib/jnpr/junos/_version.py +++ b/lib/jnpr/junos/_version.py @@ -94,7 +94,7 @@ def run_command(commands, args, cwd=None, verbose=False, hide_stderr=False, env= return None, None else: if verbose: - print("unable to find command, tried %s" % (commands,)) + print("unable to find command, tried {}".format(commands)) return None, None stdout = p.communicate()[0].strip() if sys.version_info[0] >= 3: @@ -186,11 +186,11 @@ def git_versions_from_keywords(keywords, tag_prefix, verbose): if verbose: print("keywords are unexpanded, not using") raise NotThisMethod("unexpanded keywords, not a git-archive tarball") - refs = set([r.strip() for r in refnames.strip("()").split(",")]) + refs = {r.strip() for r in refnames.strip("()").split(",")} # starting in git-1.8.3, tags are listed as "tag: foo-1.0" instead of # just "foo-1.0". If we see a "tag: " prefix, prefer those. TAG = "tag: " - tags = set([r[len(TAG) :] for r in refs if r.startswith(TAG)]) + tags = {r[len(TAG) :] for r in refs if r.startswith(TAG)} if not tags: # Either we're using git < 1.8.3, or there really are no tags. We use # a heuristic: assume all version tags have a digit. The old git %d @@ -199,7 +199,7 @@ def git_versions_from_keywords(keywords, tag_prefix, verbose): # between branches and tags. By ignoring refnames without digits, we # filter out many common branch names like "release" and # "stabilization", as well as "HEAD" and "master". - tags = set([r for r in refs if re.search(r"\d", r)]) + tags = {r for r in refs if re.search(r"\d", r)} if verbose: print("discarding '%s', no digits" % ",".join(refs - tags)) if verbose: @@ -302,9 +302,8 @@ def git_pieces_from_vcs(tag_prefix, root, verbose, run_command=run_command): if verbose: fmt = "tag '%s' doesn't start with prefix '%s'" print(fmt % (full_tag, tag_prefix)) - pieces["error"] = "tag '%s' doesn't start with prefix '%s'" % ( - full_tag, - tag_prefix, + pieces["error"] = "tag '{}' doesn't start with prefix '{}'".format( + full_tag, tag_prefix, ) return pieces pieces["closest-tag"] = full_tag[len(tag_prefix) :] diff --git a/lib/jnpr/junos/cfg/user_ssh_key.py b/lib/jnpr/junos/cfg/user_ssh_key.py index bb3208c7c..a9183fb85 100644 --- a/lib/jnpr/junos/cfg/user_ssh_key.py +++ b/lib/jnpr/junos/cfg/user_ssh_key.py @@ -97,4 +97,4 @@ def _r_list(self): def _r_catalog(self): # no catalog but the keys - self._rcatalog = dict((k, None) for k in self.list) + self._rcatalog = {k: None for k in self.list} diff --git a/lib/jnpr/junos/device.py b/lib/jnpr/junos/device.py index 6799ee8cb..32bf2ee37 100644 --- a/lib/jnpr/junos/device.py +++ b/lib/jnpr/junos/device.py @@ -409,7 +409,7 @@ def re_name(self): if re_name is None: # Still haven't figured it out. Is this a bsys? for re_state in self.facts["current_re"]: - match = re.search("^re\d+$", re_state) + match = re.search(r"^re\d+$", re_state) if match: re_string = "bsys-" + match.group(0) if re_string in self.facts["hostname_info"].keys(): @@ -650,7 +650,7 @@ def cli_to_rpc_string(self, command): value = "'" + child.text + "'" else: value = "True" - arguments.append("%s=%s" % (key, value)) + arguments.append("{}={}".format(key, value)) if arguments: rpc_string += ", ".join(arguments) rpc_string += ")" @@ -858,7 +858,7 @@ def execute(self, rpc_cmd, ignore_warning=False, **kvargs): except ValueError as ex: # when data is {}{.*} types if str(ex).startswith("Extra data"): - return json.loads(re.sub("\s?{\s?}\s?", "", rpc_rsp_e.text)) + return json.loads(re.sub(r"\s?{\s?}\s?", "", rpc_rsp_e.text)) else: raise JSONLoadError(ex, rpc_rsp_e.text) else: @@ -885,7 +885,7 @@ def execute(self, rpc_cmd, ignore_warning=False, **kvargs): # protocol: operation-failed # error: device asdf not found # - if rpc_rsp_e.text is not None and rpc_rsp_e.text.strip() is not "": + if rpc_rsp_e.text is not None and rpc_rsp_e.text.strip() != "": return rpc_rsp_e # no children, so assume it means we are OK return True @@ -1306,7 +1306,7 @@ def open(self, *vargs, **kvargs): """ auto_probe = kvargs.get("auto_probe", self._auto_probe) - if auto_probe is not 0: + if auto_probe != 0: if not self.probe(auto_probe): raise EzErrors.ProbeError(self) diff --git a/lib/jnpr/junos/exception.py b/lib/jnpr/junos/exception.py index 63724e20a..92e06e78b 100644 --- a/lib/jnpr/junos/exception.py +++ b/lib/jnpr/junos/exception.py @@ -54,7 +54,7 @@ def __init__(self, cmd=None, rsp=None, errs=None, dev=None, timeout=None, re=Non self.message = ( "\n".join( [ - "%s: %s" % (err["severity"].strip(), err["message"].strip()) + "{}: {}".format(err["severity"].strip(), err["message"].strip()) for err in errs if err["message"] is not None and err["severity"] is not None ] @@ -329,12 +329,12 @@ def __init__(self, exception, rpc_content): self.ex_msg = str(exception) self.rpc_content = rpc_content self.offending_line = "" - obj = re.search("line (\d+)", self.ex_msg) + obj = re.search(r"line (\d+)", self.ex_msg) if obj: line_no = int(obj.group(1)) rpc_lines = rpc_content.splitlines() for line in range(line_no - 3, line_no + 2): - self.offending_line += "%s: %s\n" % (line + 1, rpc_lines[line]) + self.offending_line += "{}: {}\n".format(line + 1, rpc_lines[line]) def __repr__(self): if self.offending_line: diff --git a/lib/jnpr/junos/factcache.py b/lib/jnpr/junos/factcache.py index 2f1c24bac..15e472ada 100644 --- a/lib/jnpr/junos/factcache.py +++ b/lib/jnpr/junos/factcache.py @@ -72,7 +72,7 @@ def __getitem__(self, key): if key not in self._callbacks: # Not a fact that we know how to provide. raise KeyError( - "%s: There is no function to gather the %s fact" % (key, key) + "{}: There is no function to gather the {} fact".format(key, key) ) if key not in self._cache: # A known fact, but not yet cached. Go get it and cache it. @@ -211,7 +211,7 @@ def __str__(self): string = "" for key in sorted(self): if not key.startswith("_"): - current = "'%s': %s" % (key, repr(self.get(key))) + current = "'{}': {}".format(key, repr(self.get(key))) if string: string = ", ".join([string, current]) else: diff --git a/lib/jnpr/junos/factory/cfgtable.py b/lib/jnpr/junos/factory/cfgtable.py index 4aa95574e..5d8cdb45d 100644 --- a/lib/jnpr/junos/factory/cfgtable.py +++ b/lib/jnpr/junos/factory/cfgtable.py @@ -247,7 +247,7 @@ def _validate_min_max_value(field_name, value, opt): # pass elif isinstance(value, (list, tuple, dict, set)): - raise ValueError("%s value is invalid %s\n" % (field_name, value)) + raise ValueError("{} value is invalid {}\n".format(field_name, value)) else: if "type" in opt: _validate_type(field_name, value, opt) diff --git a/lib/jnpr/junos/factory/cmdtable.py b/lib/jnpr/junos/factory/cmdtable.py index 576a8a7f7..bc42fd377 100644 --- a/lib/jnpr/junos/factory/cmdtable.py +++ b/lib/jnpr/junos/factory/cmdtable.py @@ -47,7 +47,7 @@ def __init__(self, dev=None, raw=None, path=None, template_dir=None): # ------------------------------------------------------------------------- def get(self, *vargs, **kvargs): - """ + r""" Retrieve the XML (string blob under tag of table data from the Device instance and returns back the Table instance - for call-chaining purposes. @@ -144,7 +144,7 @@ def get(self, *vargs, **kvargs): except RpcError: with StartShell(self.D) as ss: ret = ss.run( - 'cprod -A %s -c "%s"' % (self.TARGET, self.GET_CMD) + 'cprod -A {} -c "{}"'.format(self.TARGET, self.GET_CMD) ) if ret[0]: self.data = ret[1] @@ -277,10 +277,10 @@ def __repr__(self): source = self.D.hostname if self.D is not None else self._path if self.data is None: - return "%s:%s - Table empty" % (cls_name, source) + return "{}:{} - Table empty".format(cls_name, source) else: n_items = len(self.keys()) - return "%s:%s: %s items" % (cls_name, source, n_items) + return "{}:{}: {} items".format(cls_name, source, n_items) def __len__(self): self._assert_data() @@ -354,7 +354,7 @@ def _parse_textfsm(self, platform=None, command=None, raw=None): cli_table.ParseCmd(raw, attrs, template) except ntc_parse.clitable.CliTableError as ex: logger.error( - 'Unable to parse command "%s" on platform %s' % (command, platform) + 'Unable to parse command "{}" on platform {}'.format(command, platform) ) raise ex return self._filter_output(cli_table) diff --git a/lib/jnpr/junos/factory/cmdview.py b/lib/jnpr/junos/factory/cmdview.py index 245c4fd95..dd2ae75b3 100644 --- a/lib/jnpr/junos/factory/cmdview.py +++ b/lib/jnpr/junos/factory/cmdview.py @@ -61,7 +61,7 @@ def asview(self, view_cls): def __repr__(self): """ returns the name of the View with the associate item name """ - return "%s:%s" % (self.__class__.__name__, self.name) + return "{}:{}".format(self.__class__.__name__, self.name) def __getitem__(self, name): """ diff --git a/lib/jnpr/junos/factory/optable.py b/lib/jnpr/junos/factory/optable.py index 4cc99b565..5cefd7c3e 100644 --- a/lib/jnpr/junos/factory/optable.py +++ b/lib/jnpr/junos/factory/optable.py @@ -21,7 +21,7 @@ class OpTable(Table): @checkSAXParserDecorator def get(self, *vargs, **kvargs): - """ + r""" Retrieve the XML table data from the Device instance and returns back the Table instance - for call-chaining purposes. diff --git a/lib/jnpr/junos/factory/state_machine.py b/lib/jnpr/junos/factory/state_machine.py index 372115dfe..d1440c59e 100644 --- a/lib/jnpr/junos/factory/state_machine.py +++ b/lib/jnpr/junos/factory/state_machine.py @@ -247,7 +247,9 @@ def _eval_in_full_data(self): try: val = eval(expression) except Exception as ex: - logger.error("eval expression for '%s' failed due to %s" % (name, ex)) + logger.error( + "eval expression for '{}' failed due to {}".format(name, ex) + ) self._data[name] = None else: self._data[name] = val @@ -297,11 +299,11 @@ def _parse_item_iter(self, lines): self._data[master_key][key] = StateMachine(tbl).parse(lines) else: self._table.TITLE = lines[0] - delimiter = self._table.DELIMITER or "\s\s+" + delimiter = self._table.DELIMITER or r"\s\s+" temp_dict = {} pre_space_delimit = self._get_pre_space_delimiter(lines[1]) for line in lines[1:]: - if re.match(pre_space_delimit + "\s+", line): + if re.match(pre_space_delimit + r"\s+", line): break if line.startswith(pre_space_delimit): try: @@ -311,9 +313,9 @@ def _parse_item_iter(self, lines): temp_dict[key] = value except ValueError: regex = ( - "(\d+)\s(.*)" + r"(\d+)\s(.*)" if item_types[0] == int - else "(" ".*)\s(\d+)" + else "(" r".*)\s(\d+)" ) obj = re.search(regex, line) if obj: @@ -455,14 +457,14 @@ def parse_raw_columns(self, event): user_defined_columns.pop(x) break key = self._get_key(event.kwargs.get("key", self._table.KEY)) - items = re.split("\s\s+", self._lines[1].strip()) + items = re.split(r"\s\s+", self._lines[1].strip()) post_integer_data_types = event.kwargs.get("check", list(map(data_type, items))) index = event.kwargs.get("index", 1) # col_len = len(col_order) columns_list = list(col_order.values()) for index, line in enumerate(self._lines[index:], start=index): - items = re.split("\s\s+", line.strip()) + items = re.split(r"\s\s+", line.strip()) if len(items) >= len(columns_list): if len(items) > len(columns_list): if ( @@ -550,12 +552,9 @@ def _get_key(self, key): """ if isinstance(key, list): - if set( - [ - i in self._view.COLUMNS or i in self._view.COLUMNS.values() - for i in key - ] - ): + if { + i in self._view.COLUMNS or i in self._view.COLUMNS.values() for i in key + }: key_temp = [] for i in key: if i not in self._view.COLUMNS and i in self._view.COLUMNS.values(): @@ -587,7 +586,7 @@ def prev_next_row_same_type(self, event): index = event.kwargs.get("index") post_integer_data_types = event.kwargs.get("check") line = self._lines[index] - items = re.split("\s\s+", line.strip()) + items = re.split(r"\s\s+", line.strip()) post_integer_data_types, pre_integer_data_types = ( list(map(data_type, items)), post_integer_data_types, @@ -620,7 +619,7 @@ def _get_pre_space_delimiter(self, line): TX Packets 512-1023 Octets 526513 """ pre_space_delimit = "" - obj = re.search("(\s+).*", line) + obj = re.search(r"(\s+).*", line) if obj: pre_space_delimit = obj.group(1) return pre_space_delimit @@ -705,10 +704,10 @@ def parse_title_data(self, event): and not self._view.REGEX ): return - delimiter = self._table.DELIMITER or "\s\s+" + delimiter = self._table.DELIMITER or r"\s\s+" pre_space_delimit = self._get_pre_space_delimiter(self._lines[1]) for line in self._lines[1:]: - if re.match(pre_space_delimit + "\s+", line): + if re.match(pre_space_delimit + r"\s+", line): break if line.startswith(pre_space_delimit): try: @@ -722,7 +721,9 @@ def parse_title_data(self, event): elif key in self._table.KEY_ITEMS: self._data[self._view.FIELDS.get(key, key)] = value except ValueError: - regex = "(\d+)\s(.*)" if item_types[0] == int else "(" ".*)\s(\d+)" + regex = ( + r"(\d+)\s(.*)" if item_types[0] == int else "(" r".*)\s(\d+)" + ) obj = re.search(regex, line) if obj: items = obj.groups() @@ -734,7 +735,7 @@ def parse_title_data(self, event): return self._data def parse_using_regex(self, event): - """ + r""" All the regex should add up to match a line Args: @@ -819,7 +820,7 @@ def parse_using_regex(self, event): ) def parse_using_item_and_regex(self, event): - """ + r""" when multiple map is provided for regex, they gets added to search each line. But when item is '*' each regex item is used to search given value regular expression in whole string blob. @@ -922,7 +923,7 @@ def parse_using_delimiter(self, event): 'PTP': 0} """ - delimiter = self._table.DELIMITER or "\s\s+" + delimiter = self._table.DELIMITER or r"\s\s+" pre_space_delimit = "" if self._table.TITLE is None: for line in self._lines[1:]: @@ -930,7 +931,7 @@ def parse_using_delimiter(self, event): self._lines = self._lines[self._lines.index(line) + 1 :] break else: - obj = re.search("^(\s+).*", self._lines[1]) + obj = re.search(r"^(\s+).*", self._lines[1]) if obj: pre_space_delimit = obj.group(1) for index, line in enumerate(self._lines[1:]): @@ -981,7 +982,7 @@ def parse_exists(self, event): self._data[key] = re.search(search, self._raw, re.I | re.M) is not None def _insert_eval_data(self, tmp_dict): - """ + r""" Args: tmp_dict: dictionary of key value from a iteration of view diff --git a/lib/jnpr/junos/factory/table.py b/lib/jnpr/junos/factory/table.py index 1c3dd4edb..6ee1e7398 100644 --- a/lib/jnpr/junos/factory/table.py +++ b/lib/jnpr/junos/factory/table.py @@ -264,10 +264,10 @@ def __repr__(self): source = self.D.hostname if self.D is not None else self._path if self.xml is None: - return "%s:%s - Table empty" % (cls_name, source) + return "{}:{} - Table empty".format(cls_name, source) else: n_items = len(self.keys()) - return "%s:%s: %s items" % (cls_name, source, n_items) + return "{}:{}: {} items".format(cls_name, source, n_items) def __len__(self): self._assert_data() diff --git a/lib/jnpr/junos/factory/to_json.py b/lib/jnpr/junos/factory/to_json.py index 604589f30..e97ada189 100644 --- a/lib/jnpr/junos/factory/to_json.py +++ b/lib/jnpr/junos/factory/to_json.py @@ -44,7 +44,7 @@ def default(self, obj): if isinstance(obj, View): obj = {str(obj.name): dict(obj.items())} elif isinstance(obj, Table): - obj = dict((str(item.name), dict(item.items())) for item in obj) + obj = {str(item.name): dict(item.items()) for item in obj} else: obj = super(TableViewJSONEncoder, self).default(obj) return obj diff --git a/lib/jnpr/junos/factory/view.py b/lib/jnpr/junos/factory/view.py index b0b4fae2d..a1a8beb64 100644 --- a/lib/jnpr/junos/factory/view.py +++ b/lib/jnpr/junos/factory/view.py @@ -246,7 +246,7 @@ def to_json(self): def __repr__(self): """ returns the name of the View with the associate item name """ - return "%s:%s" % (self.__class__.__name__, self.name) + return "{}:{}".format(self.__class__.__name__, self.name) def __getattr__(self, name): """ diff --git a/lib/jnpr/junos/facts/__init__.py b/lib/jnpr/junos/facts/__init__.py index d72583993..b51ca6213 100644 --- a/lib/jnpr/junos/facts/__init__.py +++ b/lib/jnpr/junos/facts/__init__.py @@ -88,4 +88,4 @@ def _build_fact_callbacks_and_doc_strings(): # Append the doc string (__doc__) with the documentation for each fact. for key in sorted(_doc_strings, key=lambda s: s.lower()): - __doc__ += ":%s:\n %s\n" % (key, _doc_strings[key]) + __doc__ += ":{}:\n {}\n".format(key, _doc_strings[key]) diff --git a/lib/jnpr/junos/facts/personality.py b/lib/jnpr/junos/facts/personality.py index 09aaaa21b..08d9a736a 100644 --- a/lib/jnpr/junos/facts/personality.py +++ b/lib/jnpr/junos/facts/personality.py @@ -65,14 +65,14 @@ def get_facts(device): virtual = True else: virtual = False - elif re.match("SRX\s?(\d){4}", model): + elif re.match(r"SRX\s?(\d){4}", model): srx_model = int(model[-4:]) if srx_model > 5000: personality = "SRX_HIGHEND" else: personality = "SRX_MIDRANGE" virtual = False - elif re.match("SRX\s?(\d){3}", model): + elif re.match(r"SRX\s?(\d){3}", model): personality = "SRX_BRANCH" virtual = False elif re.search("firefly", model, re.IGNORECASE): diff --git a/lib/jnpr/junos/facts/swver.py b/lib/jnpr/junos/facts/swver.py index a4cef1037..9bdacff00 100644 --- a/lib/jnpr/junos/facts/swver.py +++ b/lib/jnpr/junos/facts/swver.py @@ -13,7 +13,7 @@ def __init__(self, verstr): if "X" == self.type: # assumes form similar to "45-D10", so extract the bits from this - xm = re.match("(\d+)-(\w)(\d+)", self.minor) + xm = re.match(r"(\d+)-(\w)(\d+)", self.minor) if xm is not None: self.minor = tuple([int(xm.group(1)), xm.group(2), int(xm.group(3))]) if len(after_type) < 2: diff --git a/lib/jnpr/junos/ofacts/personality.py b/lib/jnpr/junos/ofacts/personality.py index 46bdfdc07..37ab9bd00 100644 --- a/lib/jnpr/junos/ofacts/personality.py +++ b/lib/jnpr/junos/ofacts/personality.py @@ -9,7 +9,7 @@ def facts_personality(junos, facts): examine = model else: for fact in facts: - if re.match("^RE\d", fact): + if re.match(r"^RE\d", fact): examine = facts[fact]["model"] break @@ -34,9 +34,9 @@ def facts_personality(junos, facts): persona = "T" elif examine.startswith("PTX"): persona = "PTX" - elif re.match("SRX\s?(\d){4}", examine): + elif re.match(r"SRX\s?(\d){4}", examine): persona = "SRX_HIGHEND" - elif re.match("SRX\s?(\d){3}", examine): + elif re.match(r"SRX\s?(\d){3}", examine): persona = "SRX_BRANCH" elif re.search("firefly", examine, re.IGNORECASE): facts["virtual"] = True diff --git a/lib/jnpr/junos/ofacts/routing_engines.py b/lib/jnpr/junos/ofacts/routing_engines.py index b105d29e1..ac89ec982 100644 --- a/lib/jnpr/junos/ofacts/routing_engines.py +++ b/lib/jnpr/junos/ofacts/routing_engines.py @@ -65,7 +65,7 @@ def facts_routing_engines(junos, facts): re_name = re_name + slot_id else: # multi-instance routing platform - m = RE.search("(\d)", x_re_name[0].text) + m = RE.search(r"(\d)", x_re_name[0].text) if vc_info is not None: # => RE0-RE0 | RE0-RE1 re_name = "RE{}-RE{}".format(m.group(0), re.find("slot").text) diff --git a/lib/jnpr/junos/rpcmeta.py b/lib/jnpr/junos/rpcmeta.py index d5664bff2..fcc32678e 100644 --- a/lib/jnpr/junos/rpcmeta.py +++ b/lib/jnpr/junos/rpcmeta.py @@ -154,7 +154,7 @@ def get_config( self._junos.transform = transform # in case of model provided top level should be data # return response - if model and filter_xml is None and options.get("format") is not "json": + if model and filter_xml is None and options.get("format") != "json": response = response.getparent() response.tag = "data" return response diff --git a/lib/jnpr/junos/transport/tty.py b/lib/jnpr/junos/transport/tty.py index 6663d4039..1923e4a30 100644 --- a/lib/jnpr/junos/transport/tty.py +++ b/lib/jnpr/junos/transport/tty.py @@ -44,17 +44,17 @@ class Terminal(object): _ST_TTY_OPTION = 7 _ST_TTY_HOTKEY = 8 - _re_pat_login = "(?Pogin:\s*$)" + _re_pat_login = r"(?Pogin:\s*$)" _RE_PAT = [ - "(?Poader>\s*$)", + r"(?Poader>\s*$)", _re_pat_login, - "(?Password:\s*$)", + r"(?Password:\s*$)", "(?Pogin incorrect)", - "(?P\s*)", - "(?P%|#|(~\$)\s*$)", - '(?P[^\\-"]>\s*$)', - "(?P