<s> """<STR_LIT>""" <EOL> import sys <EOL> import select <EOL> from exabgp . dep . cmd2 import cmd <EOL> from exabgp . version import version <EOL> class Completed ( cmd . Cmd ) : <EOL> ruler = '<STR_LIT:->' <EOL> completion = { } <EOL> def __init__ ( self , intro = '<STR_LIT>' ) : <EOL> self . prompt = '<STR_LIT>' % intro <EOL> cmd . Cmd . __init__ ( self ) <EOL> def completedefault ( self , text , line , begidx , endidx ) : <EOL> commands = line . split ( ) <EOL> local = self . completion <EOL> for command in commands : <EOL> if command in local : <EOL> local = local [ command ] <EOL> continue <EOL> break <EOL> return [ _ for _ in local . keys ( ) if _ . startswith ( text ) ] <EOL> def default ( self , line ) : <EOL> print '<STR_LIT>' , line <EOL> def do_EOF ( self ) : <EOL> return True <EOL> class SubMenu ( Completed ) : <EOL> def do_exit ( self , _ ) : <EOL> return True <EOL> do_x = do_exit <EOL> class Attribute ( SubMenu ) : <EOL> chars = '<STR_LIT>' . join ( chr ( _ ) for _ in range ( ord ( '<STR_LIT:a>' ) , ord ( '<STR_LIT:z>' ) + <NUM_LIT:1> ) + range ( ord ( '<STR_LIT:0>' ) , ord ( '<STR_LIT>' ) + <NUM_LIT:1> ) + [ ord ( '<STR_LIT:->' ) ] ) <EOL> attribute = None <EOL> completion = { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : { <EOL> } , <EOL> '<STR_LIT>' : { <EOL> } , <EOL> '<STR_LIT>' : { <EOL> } , <EOL> } , <EOL> } <EOL> def __init__ ( self , name ) : <EOL> self . name = name <EOL> SubMenu . __init__ ( self , '<STR_LIT>' % name ) <EOL> def do_origin ( self , line ) : <EOL> if line in ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) : <EOL> self . attribute [ '<STR_LIT>' ] = line <EOL> else : <EOL> print '<STR_LIT>' <EOL> def do_as_path ( self , line ) : <EOL> pass <EOL> def do_med ( self , line ) : <EOL> if not line . isdigit ( ) : <EOL> print '<STR_LIT>' % line <EOL> return <EOL> med = int ( line ) <EOL> if <NUM_LIT:0> > med < <NUM_LIT> : <EOL> print '<STR_LIT>' % line <EOL> self . attribute [ '<STR_LIT>' ] = line <EOL> def do_show ( self , _ ) : <EOL> print '<STR_LIT>' % self . name + '<STR_LIT:U+0020>' . join ( '<STR_LIT>' % ( key , value ) for key , value in self . attribute . iteritems ( ) ) <EOL> class Syntax ( Completed ) : <EOL> completion = { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : { <EOL> } , <EOL> '<STR_LIT>' : { <EOL> } , <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : { <EOL> } , <EOL> '<STR_LIT>' : { <EOL> } , <EOL> '<STR_LIT>' : { <EOL> } , <EOL> '<STR_LIT:list>' : { <EOL> } , <EOL> } , <EOL> '<STR_LIT>' : { <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : { <EOL> } , <EOL> '<STR_LIT>' : { <EOL> } , <EOL> } , <EOL> } , <EOL> '<STR_LIT>' : { <EOL> } , <EOL> '<STR_LIT>' : { <EOL> } , <EOL> } <EOL> def _update_prompt ( self ) : <EOL> if self . _neighbors : <EOL> self . prompt = '<STR_LIT>' + '<STR_LIT:U+002CU+0020>' . join ( self . _neighbors ) + '<STR_LIT>' <EOL> else : <EOL> self . prompt = '<STR_LIT>' <EOL> _neighbors = set ( ) <EOL> def do_neighbor ( self , line ) : <EOL> try : <EOL> action , ip = line . split ( ) <EOL> except ValueError : <EOL> if line == '<STR_LIT>' : <EOL> print '<STR_LIT>' , '<STR_LIT:U+002CU+0020>' . join ( self . _neighbors ) <EOL> self . _neighbors = set ( ) <EOL> self . _update_prompt ( ) <EOL> else : <EOL> print '<STR_LIT>' <EOL> self . help_neighbor ( ) <EOL> return <EOL> if action == '<STR_LIT>' : <EOL> self . _neighbors . add ( ip ) <EOL> self . _update_prompt ( ) <EOL> elif action == '<STR_LIT>' : <EOL> if ip in self . _neighbors : <EOL> self . _neighbors . remove ( ip ) <EOL> print '<STR_LIT>' <EOL> self . _update_prompt ( ) <EOL> else : <EOL> print '<STR_LIT>' <EOL> elif action == '<STR_LIT:list>' : <EOL> print '<STR_LIT>' , '<STR_LIT:U+002CU+0020>' . join ( self . _neighbors ) <EOL> else : <EOL> print '<STR_LIT>' <EOL> self . help_neighbor ( ) <EOL> def help_neighbor ( self ) : <EOL> print "<STR_LIT>" <EOL> print "<STR_LIT>" <EOL> print "<STR_LIT>" <EOL> _attribute = { } <EOL> def do_attribute ( self , name ) : <EOL> if not name : <EOL> self . help_attribute ( ) <EOL> return <EOL> invalid = '<STR_LIT>' . join ( [ _ for _ in name if _ not in Attribute . chars ] ) <EOL> if invalid : <EOL> print '<STR_LIT>' % invalid <EOL> return <EOL> cli = Attribute ( name ) <EOL> cli . attribute = self . _attribute . get ( name , { } ) <EOL> cli . cmdloop ( ) <EOL> def help_attribute ( self ) : <EOL> print '<STR_LIT>' <EOL> def do_quit ( self , _ ) : <EOL> return True <EOL> do_q = do_quit <EOL> class Connection ( object ) : <EOL> def __init__ ( self , name ) : <EOL> self . read = open ( name , '<STR_LIT>' ) <EOL> self . write = open ( name , '<STR_LIT>' ) <EOL> def request ( self , command ) : <EOL> self . write . write ( command + '<STR_LIT:\n>' ) <EOL> def report ( self ) : <EOL> while select . select ( [ self . read ] , [ ] , [ ] , <NUM_LIT:5> ) : <EOL> print self . read . readline ( ) <EOL> def close ( self ) : <EOL> self . read . close ( ) <EOL> self . write . close ( ) <EOL> class ExaBGP ( Connection , Syntax ) : <EOL> def __init__ ( self , name = '<STR_LIT>' ) : <EOL> Connection . __init__ ( self , name ) <EOL> Syntax . __init__ ( self , '<STR_LIT>' ) <EOL> def do_show ( self , line ) : <EOL> self . request ( '<STR_LIT>' ) <EOL> self . report ( ) <EOL> def main ( ) : <EOL> if len ( sys . argv ) > <NUM_LIT:1> : <EOL> ExaBGP ( ) . onecmd ( '<STR_LIT:U+0020>' . join ( sys . argv [ <NUM_LIT:1> : ] ) ) <EOL> else : <EOL> print "<STR_LIT>" % version <EOL> ExaBGP ( '<STR_LIT>' ) . cmdloop ( ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> main ( ) </s>
