<s> """<STR_LIT>""" <EOL> from __future__ import division <EOL> from vistrails . core . system import get_elementtree_library <EOL> from vistrails . core . db . locator import FileLocator , DBLocator <EOL> ElementTree = get_elementtree_library ( ) <EOL> class RecentVistrailList ( object ) : <EOL> def __init__ ( self ) : <EOL> self . maxlocators = <NUM_LIT:0> <EOL> self . locators = [ ] <EOL> self . locators_map = { } <EOL> @ staticmethod <EOL> def unserialize ( text ) : <EOL> """<STR_LIT>""" <EOL> root = ElementTree . fromstring ( text ) <EOL> if root . tag != '<STR_LIT>' : <EOL> return None <EOL> vtlist = RecentVistrailList ( ) <EOL> for node in root . getchildren ( ) : <EOL> loc = FileLocator . from_xml ( node ) <EOL> if loc is None : <EOL> loc = DBLocator . from_xml ( node , include_name = True ) <EOL> if loc is not None : <EOL> vtlist . locators . append ( loc ) <EOL> vtlist . locators_map [ loc . name ] = loc <EOL> return vtlist <EOL> def serialize ( self , node = None ) : <EOL> """<STR_LIT>""" <EOL> if node is None : <EOL> node = ElementTree . Element ( '<STR_LIT>' ) <EOL> for loc in self . locators : <EOL> childNode = ElementTree . SubElement ( node , '<STR_LIT>' ) <EOL> if isinstance ( loc , DBLocator ) : <EOL> loc . to_xml ( childNode , include_name = True ) <EOL> else : <EOL> loc . to_xml ( childNode ) <EOL> return ElementTree . tostring ( node ) <EOL> def ensure_no_more_than_max ( self , max ) : <EOL> while len ( self . locators ) > max : <EOL> locator = self . locators . pop ( ) <EOL> del self . locators_map [ locator . name ] <EOL> self . maxlocators = max <EOL> def add_locator ( self , locator ) : <EOL> if locator in self . locators : <EOL> self . locators . remove ( locator ) <EOL> self . locators . insert ( <NUM_LIT:0> , locator ) <EOL> self . locators_map [ locator . name ] = locator <EOL> self . ensure_no_more_than_max ( self . maxlocators ) <EOL> def remove_locator ( self , locator ) : <EOL> if locator in self . locators : <EOL> self . locators . remove ( locator ) <EOL> del self . locators_map [ locator . name ] <EOL> def length ( self ) : <EOL> return len ( self . locators ) <EOL> def get_locator ( self , index ) : <EOL> try : <EOL> return self . locators [ index ] <EOL> except IndexError : <EOL> return None <EOL> def get_locator_by_name ( self , name ) : <EOL> try : <EOL> return self . locators_map [ name ] <EOL> except KeyError : <EOL> return None </s>
