<s> from inspect import getmembers , isclass , ismethod , isfunction <EOL> import six <EOL> from . util import _cfg , getargspec <EOL> __all__ = [ <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' <EOL> ] <EOL> def when_for ( controller ) : <EOL> def when ( method = None , ** kw ) : <EOL> def decorate ( f ) : <EOL> _cfg ( f ) [ '<STR_LIT>' ] = True <EOL> controller . _pecan [ '<STR_LIT>' ] [ method . upper ( ) ] = f <EOL> controller . _pecan [ '<STR_LIT>' ] . append ( method . upper ( ) ) <EOL> expose ( ** kw ) ( f ) <EOL> return f <EOL> return decorate <EOL> return when <EOL> def expose ( template = None , <EOL> generic = False , <EOL> route = None , <EOL> ** kw ) : <EOL> '''<STR_LIT>''' <EOL> content_type = kw . get ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> if template == '<STR_LIT>' : <EOL> content_type = '<STR_LIT:application/json>' <EOL> def decorate ( f ) : <EOL> f . exposed = True <EOL> cfg = _cfg ( f ) <EOL> cfg [ '<STR_LIT>' ] = '<STR_LIT>' in kw <EOL> if route : <EOL> from pecan import routing <EOL> if cfg . get ( '<STR_LIT>' ) : <EOL> raise ValueError ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> ) <EOL> routing . route ( route , f ) <EOL> cfg [ '<STR_LIT>' ] = content_type <EOL> cfg . setdefault ( '<STR_LIT>' , [ ] ) . append ( template ) <EOL> cfg . setdefault ( '<STR_LIT>' , { } ) [ content_type ] = template <EOL> if generic : <EOL> if f . __name__ in ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) : <EOL> raise ValueError ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' % f . __name__ <EOL> ) <EOL> cfg [ '<STR_LIT>' ] = True <EOL> cfg [ '<STR_LIT>' ] = dict ( DEFAULT = f ) <EOL> cfg [ '<STR_LIT>' ] = [ ] <EOL> f . when = when_for ( f ) <EOL> cfg [ '<STR_LIT>' ] = getargspec ( f ) <EOL> return f <EOL> return decorate <EOL> def transactional ( ignore_redirects = True ) : <EOL> '''<STR_LIT>''' <EOL> def deco ( f ) : <EOL> if isclass ( f ) : <EOL> for meth in [ <EOL> m [ <NUM_LIT:1> ] for m in getmembers ( f ) <EOL> if ( isfunction if six . PY3 else ismethod ) ( m [ <NUM_LIT:1> ] ) <EOL> ] : <EOL> if getattr ( meth , '<STR_LIT>' , False ) : <EOL> _cfg ( meth ) [ '<STR_LIT>' ] = True <EOL> _cfg ( meth ) [ '<STR_LIT>' ] = _cfg ( <EOL> meth <EOL> ) . get ( <EOL> '<STR_LIT>' , <EOL> ignore_redirects <EOL> ) <EOL> else : <EOL> _cfg ( f ) [ '<STR_LIT>' ] = True <EOL> _cfg ( f ) [ '<STR_LIT>' ] = ignore_redirects <EOL> return f <EOL> return deco <EOL> def after_action ( action_type , action ) : <EOL> '''<STR_LIT>''' <EOL> if action_type not in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> raise Exception ( '<STR_LIT>' % action_type ) <EOL> def deco ( func ) : <EOL> _cfg ( func ) . setdefault ( '<STR_LIT>' % action_type , [ ] ) . append ( action ) <EOL> return func <EOL> return deco <EOL> def after_commit ( action ) : <EOL> '''<STR_LIT>''' <EOL> return after_action ( '<STR_LIT>' , action ) <EOL> def after_rollback ( action ) : <EOL> '''<STR_LIT>''' <EOL> return after_action ( '<STR_LIT>' , action ) <EOL> def accept_noncanonical ( func ) : <EOL> '''<STR_LIT>''' <EOL> _cfg ( func ) [ '<STR_LIT>' ] = True <EOL> return func </s>
