<s> from ... datasources import Datasource <EOL> from ... errors import PageNotFound , RevisionNotFound , UserNotFound <EOL> from . util import REV_PROPS , USER_PROPS <EOL> class RevDocById ( Datasource ) : <EOL> def __init__ ( self , revision , extractor ) : <EOL> self . revision = revision <EOL> self . extractor = extractor <EOL> super ( ) . __init__ ( revision . _name + "<STR_LIT>" , self . process , <EOL> depends_on = [ revision . id , extractor . dependents ] ) <EOL> def process ( self , rev_id , dependents ) : <EOL> if rev_id == <NUM_LIT:0> : <EOL> return None <EOL> rvprop = set ( REV_PROPS ) <EOL> if self . revision . text in dependents : <EOL> rvprop . add ( '<STR_LIT:content>' ) <EOL> rev_doc_map = self . extractor . get_rev_doc_map ( [ rev_id ] , rvprop = rvprop ) <EOL> if rev_id not in rev_doc_map : <EOL> raise RevisionNotFound ( self . revision , rev_id = rev_id ) <EOL> else : <EOL> return rev_doc_map [ rev_id ] <EOL> class PageCreationRevDoc ( Datasource ) : <EOL> def __init__ ( self , page , extractor ) : <EOL> self . page = page <EOL> self . extractor = extractor <EOL> super ( ) . __init__ ( page . creation . _name + "<STR_LIT>" , self . process , <EOL> depends_on = [ page . id , extractor . dependents ] ) <EOL> def process ( self , page_id , dependents ) : <EOL> rvprop = set ( REV_PROPS ) <EOL> if self . page . creation . text in dependents : <EOL> rvprop . add ( '<STR_LIT:content>' ) <EOL> rev_doc = self . extractor . get_page_creation_doc ( page_id , rvprop = rvprop ) <EOL> if rev_doc is None : <EOL> raise PageNotFound ( self . page , page_id ) <EOL> else : <EOL> return rev_doc <EOL> class UserInfoDoc ( Datasource ) : <EOL> def __init__ ( self , user , extractor ) : <EOL> self . user = user <EOL> self . extractor = extractor <EOL> super ( ) . __init__ ( user . info . _name + "<STR_LIT>" , self . process , <EOL> depends_on = [ user . id , user . text ] ) <EOL> def process ( self , user_id , user_text ) : <EOL> if user_id == <NUM_LIT:0> : <EOL> return None <EOL> else : <EOL> user_doc_map = self . extractor . get_user_doc_map ( [ user_text ] , <EOL> usprop = USER_PROPS ) <EOL> if user_text not in user_doc_map : <EOL> raise UserNotFound ( self . user , user_text ) <EOL> else : <EOL> return user_doc_map [ user_text ] <EOL> class LastUserRevDoc ( Datasource ) : <EOL> def __init__ ( self , revision , extractor ) : <EOL> self . revision = revision <EOL> self . extractor = extractor <EOL> super ( ) . __init__ ( <EOL> revision . user . last_revision . _name + "<STR_LIT>" , self . process , <EOL> depends_on = [ revision . user . text , revision . timestamp , <EOL> extractor . dependents ] <EOL> ) <EOL> def process ( self , user_text , rev_timestamp , dependents ) : <EOL> ucprop = set ( REV_PROPS ) <EOL> if self . revision . user . last_revision . text in dependents : <EOL> ucprop . add ( '<STR_LIT:text>' ) <EOL> return self . extractor . get_last_user_revision ( user_text , rev_timestamp , <EOL> ucprop = ucprop ) </s>
