<s> """<STR_LIT>""" <EOL> from zope . interface import implementer <EOL> from imaginary . idea import Proximity <EOL> from imaginary . iimaginary import IRetriever <EOL> from imaginary . iimaginary import ILitLink <EOL> from imaginary . idea import Path <EOL> from imaginary . iimaginary import IThing <EOL> from imaginary . idea import CanSee <EOL> from imaginary . idea import DelegatingRetriever <EOL> from imaginary . idea import ProviderOf <EOL> from imaginary . iimaginary import IVisible <EOL> @ implementer ( IRetriever ) <EOL> class _PathSatisfiesPredicate ( DelegatingRetriever ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , predicate , retriever ) : <EOL> """<STR_LIT>""" <EOL> self . predicate = predicate <EOL> super ( _PathSatisfiesPredicate , self ) . __init__ ( retriever ) <EOL> def retrieve ( self , path ) : <EOL> """<STR_LIT>""" <EOL> if self . predicate ( path ) : <EOL> return path <EOL> def visualizations ( viewingThing , predicate , withinDistance = <NUM_LIT> ) : <EOL> """<STR_LIT>""" <EOL> startPaths = viewingThing . obtainOrReportWhyNot ( <EOL> _PathSatisfiesPredicate ( <EOL> predicate , <EOL> Proximity ( withinDistance , <EOL> CanSee ( ProviderOf ( IVisible ) , <EOL> viewingThing ) <EOL> ) <EOL> ) <EOL> ) <EOL> choices = [ ] <EOL> for startPath in startPaths : <EOL> visualTargetIdea = startPath . links [ - <NUM_LIT:1> ] . target <EOL> visible = _lightingApplied ( startPath ) <EOL> if visible is not None : <EOL> subPaths = visualTargetIdea . obtain ( <EOL> _PathSatisfiesPredicate ( <EOL> lambda p : True , <EOL> Proximity ( withinDistance , ProviderOf ( IVisible ) ) <EOL> ) <EOL> ) <EOL> paths = [ <EOL> Path ( links = startPath . links + subPath . links ) <EOL> for subPath in subPaths <EOL> if not subPath . targetAs ( IThing ) is viewingThing <EOL> ] <EOL> paths . sort ( key = lambda x : len ( x . links ) ) <EOL> paths = list ( path for path in paths if _isIlluminated ( path ) ) <EOL> choices . append ( visible . visualizeWithContents ( paths ) ) <EOL> return choices <EOL> def _isIlluminated ( path ) : <EOL> """<STR_LIT>""" <EOL> litlinks = list ( path . of ( ILitLink ) ) <EOL> if not litlinks : <EOL> return True <EOL> for litlink in litlinks : <EOL> if litlink . isItLit ( path ) : <EOL> return True <EOL> else : <EOL> return False <EOL> def _lightingApplied ( path ) : <EOL> """<STR_LIT>""" <EOL> thing = path . targetAs ( IVisible ) <EOL> if not _isIlluminated ( path ) : <EOL> return None <EOL> litPath = list ( path . of ( ILitLink ) ) <EOL> if not litPath : <EOL> return thing <EOL> litThing = list ( path . eachTargetAs ( IVisible ) ) [ - <NUM_LIT:1> ] <EOL> thing = litPath [ - <NUM_LIT:1> ] . applyLighting ( litThing , thing , IVisible ) <EOL> return thing </s>
