<s> """<STR_LIT>""" <EOL> from collections import Callable , Mapping <EOL> from pyeapi . eapilib import CommandError , ConnectionError <EOL> from pyeapi . utils import make_iterable <EOL> class BaseEntity ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , node ) : <EOL> self . node = node <EOL> @ property <EOL> def config ( self ) : <EOL> return self . node . running_config <EOL> @ property <EOL> def error ( self ) : <EOL> return self . node . connection . error <EOL> def get_block ( self , parent , config = '<STR_LIT>' ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> parent = r'<STR_LIT>' % parent <EOL> return self . node . section ( parent , config = config ) <EOL> except TypeError : <EOL> return None <EOL> def configure ( self , commands ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> self . node . config ( commands ) <EOL> return True <EOL> except ( CommandError , ConnectionError ) : <EOL> return False <EOL> def command_builder ( self , string , value = None , default = None , disable = None ) : <EOL> """<STR_LIT>""" <EOL> if default : <EOL> return '<STR_LIT>' % string <EOL> elif disable : <EOL> return '<STR_LIT>' % string <EOL> elif value is True : <EOL> return string <EOL> elif value : <EOL> return '<STR_LIT>' % ( string , value ) <EOL> else : <EOL> return '<STR_LIT>' % string <EOL> def configure_interface ( self , name , commands ) : <EOL> """<STR_LIT>""" <EOL> commands = make_iterable ( commands ) <EOL> commands . insert ( <NUM_LIT:0> , '<STR_LIT>' % name ) <EOL> return self . configure ( commands ) <EOL> class Entity ( BaseEntity , Callable ) : <EOL> """<STR_LIT>""" <EOL> def __call__ ( self ) : <EOL> return self . get ( ) <EOL> def get ( self ) : <EOL> raise NotImplementedError <EOL> class EntityCollection ( BaseEntity , Mapping ) : <EOL> """<STR_LIT>""" <EOL> def __call__ ( self ) : <EOL> return self . getall ( ) <EOL> def __getitem__ ( self , value ) : <EOL> return self . get ( value ) <EOL> def __len__ ( self ) : <EOL> return len ( self . getall ( ) ) <EOL> def __iter__ ( self ) : <EOL> return iter ( self . getall ( ) ) <EOL> def getall ( self ) : <EOL> raise NotImplementedError <EOL> def get ( self , name , default = None ) : <EOL> raise NotImplementedError </s>
