<s> import slumber <EOL> import jinja2 <EOL> from slumber import exceptions <EOL> from django . core . cache import cache <EOL> from django . utils . translation import ugettext as _ <EOL> from packages . utils import verlib <EOL> class ReleaseEvaluator ( object ) : <EOL> def evaluate ( self , types = None ) : <EOL> if types is None : <EOL> types = [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] <EOL> return [ getattr ( self , "<STR_LIT>" % t ) ( ) for t in types ] <EOL> def evaluate_pep386 ( self ) : <EOL> if not hasattr ( self , "<STR_LIT>" ) : <EOL> normalized = verlib . suggest_normalized_version ( self . version ) <EOL> evaluator = { <EOL> "<STR_LIT:title>" : _ ( "<STR_LIT>" ) , <EOL> "<STR_LIT:message>" : jinja2 . Markup ( _ ( "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) ) <EOL> } <EOL> if self . version == normalized : <EOL> self . _evaluate_pep386 = { <EOL> "<STR_LIT>" : "<STR_LIT:success>" , <EOL> "<STR_LIT:message>" : jinja2 . Markup ( _ ( '<STR_LIT>' ) ) , <EOL> "<STR_LIT>" : evaluator , <EOL> } <EOL> elif normalized is not None : <EOL> self . _evaluate_pep386 = { <EOL> "<STR_LIT>" : None , <EOL> "<STR_LIT:message>" : jinja2 . Markup ( _ ( '<STR_LIT>' ) ) , <EOL> "<STR_LIT>" : evaluator , <EOL> } <EOL> else : <EOL> self . _evaluate_pep386 = { <EOL> "<STR_LIT>" : "<STR_LIT:error>" , <EOL> "<STR_LIT:message>" : jinja2 . Markup ( _ ( '<STR_LIT>' ) ) , <EOL> "<STR_LIT>" : evaluator , <EOL> } <EOL> return self . _evaluate_pep386 <EOL> def evaluate_hosting ( self ) : <EOL> if not hasattr ( self , "<STR_LIT>" ) : <EOL> evaluator = { <EOL> "<STR_LIT:title>" : _ ( "<STR_LIT>" ) , <EOL> "<STR_LIT:message>" : jinja2 . Markup ( <EOL> _ ( "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> ) , <EOL> } <EOL> if self . files . all ( ) . exists ( ) : <EOL> self . _evaluate_hosting = { <EOL> "<STR_LIT>" : "<STR_LIT:success>" , <EOL> "<STR_LIT:message>" : _ ( "<STR_LIT>" ) , <EOL> "<STR_LIT>" : evaluator , <EOL> } <EOL> elif self . download_uri : <EOL> self . _evaluate_hosting = { <EOL> "<STR_LIT>" : "<STR_LIT:error>" , <EOL> "<STR_LIT:message>" : _ ( "<STR_LIT>" ) , <EOL> "<STR_LIT>" : evaluator , <EOL> } <EOL> else : <EOL> self . _evaluate_hosting = { <EOL> "<STR_LIT>" : "<STR_LIT:error>" , <EOL> "<STR_LIT:message>" : _ ( "<STR_LIT>" ) , <EOL> "<STR_LIT>" : evaluator , <EOL> } <EOL> return self . _evaluate_hosting <EOL> def evaluate_documentation ( self ) : <EOL> if not hasattr ( self , "<STR_LIT>" ) : <EOL> evaluator = { <EOL> "<STR_LIT:title>" : _ ( "<STR_LIT>" ) , <EOL> "<STR_LIT:message>" : jinja2 . Markup ( <EOL> _ ( "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> ) , <EOL> } <EOL> from packages . models import ReadTheDocsPackageSlug <EOL> qs = ReadTheDocsPackageSlug . objects . filter ( package = self . package ) <EOL> slug = qs [ <NUM_LIT:0> ] . slug if qs else self . package . name <EOL> key = "<STR_LIT>" % slug <EOL> if cache . get ( key , version = <NUM_LIT:4> ) is not None : <EOL> hosted_on_rtd , url = cache . get ( key , version = <NUM_LIT:4> ) <EOL> else : <EOL> try : <EOL> api = slumber . API ( base_url = "<STR_LIT>" ) <EOL> results = api . project . get ( slug__iexact = slug ) <EOL> except exceptions . SlumberHttpBaseException : <EOL> return { <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT:message>" : jinja2 . Markup ( _ ( '<STR_LIT>' ) ) , <EOL> "<STR_LIT>" : evaluator , <EOL> } <EOL> if results [ "<STR_LIT>" ] : <EOL> hosted_on_rtd = True <EOL> url = results [ "<STR_LIT>" ] [ <NUM_LIT:0> ] [ "<STR_LIT>" ] <EOL> else : <EOL> hosted_on_rtd = False <EOL> url = None <EOL> cache . set ( key , ( hosted_on_rtd , url ) , <NUM_LIT> * <NUM_LIT:30> , version = <NUM_LIT:4> ) <EOL> if hosted_on_rtd : <EOL> self . _evaluate_documentation = { <EOL> "<STR_LIT>" : "<STR_LIT:success>" , <EOL> "<STR_LIT:message>" : jinja2 . Markup ( _ ( '<STR_LIT>' ) % url ) , <EOL> "<STR_LIT>" : evaluator , <EOL> } <EOL> else : <EOL> self . _evaluate_documentation = { <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT:message>" : jinja2 . Markup ( _ ( '<STR_LIT>' ) ) , <EOL> "<STR_LIT>" : evaluator , <EOL> } <EOL> return self . _evaluate_documentation </s>
