#NEWLINE# def _cmp_by_aspath( path1 , path2 ) : #NEWLINE# #INDENT# 'Calculated the best-paths by comparing as-path lengths.\n\n    Shortest as-path length is preferred. If both path have same lengths,\n    we return None.\n    ' #NEWLINE# as_path1 = path1 . get_pattr ( BGP_ATTR_TYPE_AS_PATH ) #NEWLINE# as_path2 = path2 . get_pattr ( BGP_ATTR_TYPE_AS_PATH ) #NEWLINE# assert ( as_path1 and as_path2 ) #NEWLINE# l1 = as_path1 . get_as_path_len ( ) #NEWLINE# l2 = as_path2 . get_as_path_len ( ) #NEWLINE# assert ( ( l1 is not None ) and ( l2 is not None ) ) #NEWLINE# if ( l1 > l2 ) : #NEWLINE# #INDENT# return path2 #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( l2 > path2 ) : #NEWLINE# #INDENT# return path1 #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# return None