<s> from bigsuds import ServerError <EOL> import f5 . lb <EOL> import weakref <EOL> class CachedFactory ( object ) : <EOL> def __init__ ( self , Klass ) : <EOL> self . _Klass = Klass <EOL> self . _cache = weakref . WeakValueDictionary ( ) <EOL> def __repr__ ( self ) : <EOL> return '<STR_LIT>' % self . _Klass <EOL> def create ( self , names , lb = None , * args , ** kwargs ) : <EOL> objects = [ ] <EOL> for name in names : <EOL> key = str ( name ) <EOL> if lb is not None : <EOL> key = lb . host + key <EOL> key = hash ( key ) <EOL> if key in self . _cache : <EOL> objects . append ( self . _cache [ key ] ) <EOL> else : <EOL> obj = self . _Klass ( name , lb , * args , ** kwargs ) <EOL> self . _cache [ key ] = obj <EOL> objects . append ( obj ) <EOL> return objects <EOL> def put ( self , obj ) : <EOL> key = obj . name <EOL> if obj . lb is not None : <EOL> key = obj . lb . host + key <EOL> key = hash ( key ) <EOL> self . _cache [ key ] = obj <EOL> def delete ( self , obj ) : <EOL> key = obj . name <EOL> if obj . lb is not None : <EOL> key = obj . lb . host + key <EOL> key = hash ( key ) <EOL> if key in self . _cache : <EOL> del self . _cache [ key ] <EOL> def prune_f5_lists ( list1 , * lists ) : <EOL> for list in lists : <EOL> if len ( list ) != len ( list1 ) : <EOL> raise ValueError ( '<STR_LIT>' ) <EOL> idx_remove = [ ] <EOL> for idx , val in enumerate ( list1 ) : <EOL> if val == [ ] : <EOL> for list in lists : <EOL> list [ idx ] = None <EOL> for list in lists : <EOL> while None in list : <EOL> list . remove ( None ) <EOL> while [ ] in list1 : <EOL> list1 . remove ( [ ] ) <EOL> from functools import wraps <EOL> def multisetter ( func ) : <EOL> @ wraps ( func ) <EOL> def wrapper ( self , values ) : <EOL> if not isinstance ( values , list ) : <EOL> values = [ values ] * len ( self ) <EOL> else : <EOL> if len ( values ) is not len ( self ) : <EOL> raise ValueError ( '<STR_LIT>' ) <EOL> func ( self , values ) <EOL> return wrapper <EOL> def updatefactorycache ( func ) : <EOL> @ wraps ( func ) <EOL> def wrapper ( self , * args , ** kwargs ) : <EOL> self . factory . delete ( self ) <EOL> func_ret = func ( self , * args , ** kwargs ) <EOL> self . factory . put ( self ) <EOL> return func_ret <EOL> return wrapper <EOL> def lbtransaction ( func ) : <EOL> @ wraps ( func ) <EOL> @ lbwriter <EOL> def wrapper ( self , * args , ** kwargs ) : <EOL> our_transaction = not self . _lb . transaction <EOL> if our_transaction : <EOL> self . _lb . transaction = True <EOL> try : <EOL> func_ret = func ( self , * args , ** kwargs ) <EOL> except : <EOL> try : <EOL> if our_transaction : <EOL> self . _lb . transaction = False <EOL> except : <EOL> pass <EOL> raise <EOL> if our_transaction : <EOL> self . _lb . _submit_transaction ( ) <EOL> return wrapper <EOL> def restore_session_values ( func ) : <EOL> def wrapper ( self , * args , ** kwargs ) : <EOL> original_folder = self . lb . _active_folder <EOL> original_recursive_query = self . lb . _recursive_query <EOL> try : <EOL> func_ret = func ( self , * args , ** kwargs ) <EOL> except : <EOL> raise <EOL> finally : <EOL> if self . lb . _active_folder != original_folder : <EOL> self . lb . active_folder = original_folder <EOL> if self . lb . _recursive_query != original_recursive_query : <EOL> self . lb . recursive_query = original_recursive_query <EOL> return func_ret <EOL> return wrapper <EOL> def lbmethod ( func ) : <EOL> @ wraps ( func ) <EOL> def wrapper ( self , * args , ** kwargs ) : <EOL> if not isinstance ( self . _lb , f5 . Lb ) : <EOL> raise RuntimeError ( '<STR_LIT>' % ( type ( self . lb ) . __name__ ) ) <EOL> return func ( self , * args , ** kwargs ) <EOL> return wrapper <EOL> def lbwriter ( func ) : <EOL> @ wraps ( func ) <EOL> @ lbmethod <EOL> @ lbrestore_session_values <EOL> def wrapper ( self , * args , ** kwargs ) : <EOL> if self . _lb . _active_folder == '<STR_LIT:/>' : <EOL> self . _lb . active_folder = '<STR_LIT>' <EOL> return func ( self , * args , ** kwargs ) <EOL> return wrapper <EOL> def lbwriter2 ( func ) : <EOL> @ wraps ( func ) <EOL> @ lbrestore_session_values <EOL> def wrapper ( self , * args , ** kwargs ) : <EOL> if self . lb . _active_folder == '<STR_LIT:/>' : <EOL> self . lb . active_folder = '<STR_LIT>' <EOL> return func ( self , * args , ** kwargs ) <EOL> return wrapper <EOL> def lbrestore_session_values ( func ) : <EOL> def wrapper ( self , * args , ** kwargs ) : <EOL> original_folder = self . _lb . _active_folder <EOL> original_recursive_query = self . _lb . _recursive_query <EOL> func_ret = func ( self , * args , ** kwargs ) <EOL> if self . _lb . _active_folder != original_folder : <EOL> self . _lb . active_folder = original_folder <EOL> if self . _lb . _recursive_query != original_recursive_query : <EOL> self . _lb . recursive_query = original_recursive_query <EOL> return func_ret <EOL> return wrapper </s>
