From 7b2c7cb41408415aa8b9a0c3db6b4f13a8b3bbf8 Mon Sep 17 00:00:00 2001
From: Jeffrey Phillips Freeman <jeffrey.freeman@syncleus.com>
Date: Thu, 29 Sep 2016 10:57:45 -0400
Subject: [PATCH] Created is_hop_consumed method and moved out functionality to
 this method.

---
 src/apex/plugins/apexparadigm/__init__.py | 8 ++++----
 src/apex/routing/__init__.py              | 1 +
 src/apex/routing/route.py                 | 7 +++++++
 3 files changed, 12 insertions(+), 4 deletions(-)

diff --git a/src/apex/plugins/apexparadigm/__init__.py b/src/apex/plugins/apexparadigm/__init__.py
index b9fe91b..5cc6a94 100644
--- a/src/apex/plugins/apexparadigm/__init__.py
+++ b/src/apex/plugins/apexparadigm/__init__.py
@@ -51,7 +51,7 @@ class ApexParadigmPlugin(object):
 
         for hop_index in range(0, len(frame['path'])):
             hop = frame['path'][hop_index]
-            if hop[-1] is not '*':
+            if not apex.routing.is_hop_consumed(hop):
                 split_hop = hop.split('-')
                 node = split_hop[0].upper()
                 if len(split_hop) >= 2 and split_hop[1]:
@@ -134,7 +134,7 @@ class ApexParadigmPlugin(object):
         for hop_index in reversed(range(0, len(frame['path']))):
             hop = frame['path'][hop_index]
             # If this is the last node before a spent node, or a spent node itself, we are done
-            if hop[-1] == '*' or frame['path'][hop_index-1][-1] == '*':
+            if apex.routing.is_hop_consumed(hop) or apex.routing.is_hop_consumed(frame['path'][hop_index-1]):
                 break
             split_hop = hop.split('-')
             node = split_hop[0].upper()
@@ -198,7 +198,7 @@ class ApexParadigmPlugin(object):
         for hop_index in reversed(range(0, len(frame['path']))):
             hop = frame['path'][hop_index]
             # If this is the last node before a spent node, or a spent node itself, we are done
-            if hop[-1] == '*' or frame['path'][hop_index-1][-1] == '*':
+            if apex.routing.is_hop_consumed(hop) or apex.routing.is_hop_consumed(frame['path'][hop_index-1]):
                 break
             elif selected_hop and selected_hop['index'] <= hop_index:
                 break
@@ -225,7 +225,7 @@ class ApexParadigmPlugin(object):
         new_path = []
         for hop_index in range(0, len(frame['path'])):
             hop = frame['path'][hop_index]
-            if hop[-1] != '*':
+            if not apex.routing.is_hop_consumed(hop):
                 if hop_index == selected_hop['index']:
                     if selected_hop['band_path'] is None:
                         new_path += [hop + '*']
diff --git a/src/apex/routing/__init__.py b/src/apex/routing/__init__.py
index 44ff0f1..f10884d 100644
--- a/src/apex/routing/__init__.py
+++ b/src/apex/routing/__init__.py
@@ -7,6 +7,7 @@ from __future__ import division
 from __future__ import print_function
 
 from .route import has_seen  # noqa: F401
+from .route import is_hop_consumed  # noqa: F401
 
 __author__ = 'Jeffrey Phillips Freeman (WI2ARD)'
 __maintainer__ = 'Jeffrey Phillips Freeman (WI2ARD)'
diff --git a/src/apex/routing/route.py b/src/apex/routing/route.py
index 9a8fa28..d2bd779 100644
--- a/src/apex/routing/route.py
+++ b/src/apex/routing/route.py
@@ -27,3 +27,10 @@ def has_seen(port_map, frame):
                 return True
 
     return False
+
+
+def is_hop_consumed(hop):
+    if hop.trim()[-1] is '*':
+        return True
+    else:
+        return False
-- 
GitLab