<s> from fake_switches . command_processing . base_command_processor import BaseCommandProcessor <EOL> from fake_switches . switch_configuration import split_port_name , VlanPort <EOL> class ConfigVlanCommandProcessor ( BaseCommandProcessor ) : <EOL> def __init__ ( self , switch_configuration , terminal_controller , logger , piping_processor , vlan ) : <EOL> BaseCommandProcessor . __init__ ( self , switch_configuration , terminal_controller , logger , piping_processor ) <EOL> self . vlan = vlan <EOL> def get_prompt ( self ) : <EOL> return "<STR_LIT>" % ( self . switch_configuration . name , self . vlan . number ) <EOL> def do_untagged ( self , * args ) : <EOL> port = self . switch_configuration . get_port_by_partial_name ( "<STR_LIT:U+0020>" . join ( args ) ) <EOL> if port is not None : <EOL> if port . trunk_vlans is None : <EOL> port . access_vlan = self . vlan . number <EOL> else : <EOL> port . trunk_native_vlan = self . vlan . number <EOL> else : <EOL> self . write_line ( "<STR_LIT>" % "<STR_LIT:U+0020>" . join ( args [ <NUM_LIT:1> : ] ) ) <EOL> self . write_line ( "<STR_LIT>" ) <EOL> def do_no_untagged ( self , * args ) : <EOL> port = self . switch_configuration . get_port_by_partial_name ( "<STR_LIT:U+0020>" . join ( args ) ) <EOL> if port is not None : <EOL> if port . access_vlan != self . vlan . number and port . trunk_native_vlan != self . vlan . number : <EOL> self . write_line ( "<STR_LIT>" . format ( args [ <NUM_LIT:1> ] , self . vlan . number ) ) <EOL> return <EOL> if port . trunk_vlans is None : <EOL> port . access_vlan = None <EOL> else : <EOL> port . trunk_native_vlan = None <EOL> else : <EOL> self . write_line ( "<STR_LIT>" % "<STR_LIT:U+0020>" . join ( args [ <NUM_LIT:1> : ] ) ) <EOL> self . write_line ( "<STR_LIT>" ) <EOL> def do_tagged ( self , * args ) : <EOL> port = self . switch_configuration . get_port_by_partial_name ( "<STR_LIT:U+0020>" . join ( args ) ) <EOL> if port is not None : <EOL> if port . trunk_vlans is None : <EOL> port . trunk_vlans = [ ] <EOL> port . trunk_native_vlan = port . access_vlan or <NUM_LIT:1> <EOL> port . access_vlan = None <EOL> if self . vlan . number not in port . trunk_vlans : <EOL> port . trunk_vlans . append ( self . vlan . number ) <EOL> else : <EOL> self . write_line ( "<STR_LIT>" % "<STR_LIT:U+0020>" . join ( args [ <NUM_LIT:1> : ] ) ) <EOL> self . write_line ( "<STR_LIT>" ) <EOL> def do_no_tagged ( self , * args ) : <EOL> port = self . switch_configuration . get_port_by_partial_name ( "<STR_LIT:U+0020>" . join ( args ) ) <EOL> if port is not None : <EOL> if port . trunk_vlans is None or self . vlan . number not in port . trunk_vlans : <EOL> self . write_line ( "<STR_LIT>" . format ( args [ <NUM_LIT:1> ] , self . vlan . number ) ) <EOL> return <EOL> port . trunk_vlans . remove ( self . vlan . number ) <EOL> if len ( port . trunk_vlans ) == <NUM_LIT:0> : <EOL> port . trunk_vlans = None <EOL> if port . trunk_native_vlan and port . trunk_native_vlan != <NUM_LIT:1> : <EOL> port . access_vlan = port . trunk_native_vlan <EOL> port . trunk_native_vlan = None <EOL> else : <EOL> self . write_line ( "<STR_LIT>" % "<STR_LIT:U+0020>" . join ( args [ <NUM_LIT:1> : ] ) ) <EOL> self . write_line ( "<STR_LIT>" ) <EOL> def do_router_interface ( self , * args ) : <EOL> if len ( args ) != <NUM_LIT:2> or args [ <NUM_LIT:0> ] != "<STR_LIT>" : <EOL> self . write_line ( "<STR_LIT>" . format ( "<STR_LIT:U+0020>" . join ( args ) ) ) <EOL> self . write_line ( "<STR_LIT>" ) <EOL> else : <EOL> actual_ve = next ( <EOL> ( p for p in self . switch_configuration . ports if isinstance ( p , VlanPort ) and p . vlan_id == self . vlan . number ) , <EOL> False ) <EOL> if not actual_ve : <EOL> name = "<STR_LIT>" . format ( args [ <NUM_LIT:1> ] ) <EOL> self . switch_configuration . add_port ( self . switch_configuration . new ( "<STR_LIT>" , self . vlan . number , <EOL> name ) ) <EOL> else : <EOL> self . write_line ( "<STR_LIT>" % ( <EOL> self . vlan . number , split_port_name ( actual_ve . name ) [ <NUM_LIT:1> ] ) ) <EOL> def do_no_router_interface ( self , * _ ) : <EOL> self . switch_configuration . remove_port ( next ( <EOL> p for p in self . switch_configuration . ports if isinstance ( p , VlanPort ) and p . vlan_id == self . vlan . number ) ) <EOL> def do_exit ( self ) : <EOL> self . is_done = True </s>
