<s> from pkg_resources import EntryPoint <EOL> from repoze . who . _compat import STRING_TYPES <EOL> def authenticated_predicate ( ) : <EOL> def _predicate ( environ ) : <EOL> return '<STR_LIT>' in environ or '<STR_LIT>' in environ <EOL> return _predicate <EOL> class PredicateRestriction : <EOL> def __init__ ( self , app , predicate , enabled = True , ** kw ) : <EOL> self . app = app <EOL> self . enabled = enabled <EOL> options = kw . copy ( ) <EOL> self . predicate = predicate ( ** options ) <EOL> def __call__ ( self , environ , start_response ) : <EOL> if self . enabled : <EOL> if not self . predicate ( environ ) : <EOL> start_response ( '<STR_LIT>' , [ ] ) <EOL> return [ ] <EOL> return self . app ( environ , start_response ) <EOL> def make_authenticated_restriction ( app , global_config , enabled = True ) : <EOL> return PredicateRestriction ( app , authenticated_predicate , enabled ) <EOL> def make_predicate_restriction ( app , global_config , <EOL> predicate , enabled = True , ** kw ) : <EOL> if isinstance ( predicate , STRING_TYPES ) : <EOL> predicate = EntryPoint . parse ( '<STR_LIT>' % predicate ) . load ( False ) <EOL> return PredicateRestriction ( app , predicate , enabled , ** kw ) </s>
