<s> """<STR_LIT>""" <EOL> import os <EOL> import dectate <EOL> from . app import App <EOL> from . cachingreg import RegRegistry <EOL> from . authentication import Identity , NoIdentity , IdentityPolicyRegistry <EOL> from . view import render_view , render_json , render_html , ViewRegistry <EOL> from . traject import Path <EOL> from . converter import ConverterRegistry <EOL> from . tween import TweenRegistry <EOL> from . template import TemplateEngineRegistry <EOL> from . predicate import PredicateRegistry <EOL> from . path import PathRegistry <EOL> from . import generic <EOL> from . settings import SettingRegistry <EOL> def isbaseclass ( a , b ) : <EOL> return issubclass ( b , a ) <EOL> @ App . directive ( '<STR_LIT>' ) <EOL> class SettingAction ( dectate . Action ) : <EOL> config = { <EOL> '<STR_LIT>' : RegRegistry , <EOL> '<STR_LIT>' : SettingRegistry <EOL> } <EOL> def __init__ ( self , section , name ) : <EOL> """<STR_LIT>""" <EOL> self . section = section <EOL> self . name = name <EOL> def identifier ( self , reg_registry , setting_registry ) : <EOL> return self . section , self . name <EOL> def perform ( self , obj , reg_registry , setting_registry ) : <EOL> setting_registry . register_setting ( self . section , self . name , obj ) <EOL> @ staticmethod <EOL> def after ( reg_registry , setting_registry ) : <EOL> reg_registry . register_function ( generic . settings , <EOL> lambda : setting_registry ) <EOL> class SettingValue ( object ) : <EOL> def __init__ ( self , value ) : <EOL> self . value = value <EOL> def __call__ ( self ) : <EOL> return self . value <EOL> @ App . directive ( '<STR_LIT>' ) <EOL> class SettingSectionAction ( dectate . Composite ) : <EOL> query_classes = [ SettingAction ] <EOL> def __init__ ( self , section ) : <EOL> """<STR_LIT>""" <EOL> self . section = section <EOL> def actions ( self , obj ) : <EOL> section = obj ( ) <EOL> for name , value in section . items ( ) : <EOL> yield ( SettingAction ( section = self . section , name = name ) , <EOL> SettingValue ( value ) ) <EOL> @ App . directive ( '<STR_LIT>' ) <EOL> class PredicateFallbackAction ( dectate . Action ) : <EOL> config = { <EOL> '<STR_LIT>' : PredicateRegistry <EOL> } <EOL> depends = [ SettingAction ] <EOL> filter_convert = { <EOL> '<STR_LIT>' : dectate . convert_dotted_name , <EOL> '<STR_LIT>' : dectate . convert_dotted_name <EOL> } <EOL> def __init__ ( self , dispatch , func ) : <EOL> """<STR_LIT>""" <EOL> self . dispatch = dispatch <EOL> self . func = func <EOL> def identifier ( self , predicate_registry ) : <EOL> return self . dispatch . wrapped_func , self . func <EOL> def perform ( self , obj , predicate_registry ) : <EOL> predicate_registry . register_predicate_fallback ( <EOL> self . dispatch , self . func , obj ) <EOL> @ App . directive ( '<STR_LIT>' ) <EOL> class PredicateAction ( dectate . Action ) : <EOL> config = { <EOL> '<STR_LIT>' : PredicateRegistry <EOL> } <EOL> depends = [ SettingAction , PredicateFallbackAction ] <EOL> filter_convert = { <EOL> '<STR_LIT>' : dectate . convert_dotted_name , <EOL> '<STR_LIT:index>' : dectate . convert_dotted_name , <EOL> '<STR_LIT>' : dectate . convert_dotted_name , <EOL> '<STR_LIT>' : dectate . convert_dotted_name , <EOL> } <EOL> filter_name = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } <EOL> def __init__ ( self , dispatch , name , default , index , <EOL> before = None , after = None ) : <EOL> """<STR_LIT>""" <EOL> self . dispatch = dispatch <EOL> self . name = name <EOL> self . default = default <EOL> self . index = index <EOL> self . _before = before <EOL> self . _after = after <EOL> def identifier ( self , predicate_registry ) : <EOL> return self . dispatch . wrapped_func , self . _before , self . _after <EOL> def perform ( self , obj , predicate_registry ) : <EOL> if not self . dispatch . external_predicates : <EOL> raise dectate . DirectiveError ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" % self . dispatch ) <EOL> predicate_registry . register_predicate ( <EOL> obj , self . dispatch , <EOL> self . name , self . default , self . index , <EOL> self . _before , self . _after ) <EOL> @ staticmethod <EOL> def after ( predicate_registry ) : <EOL> predicate_registry . install_predicates ( ) <EOL> @ App . directive ( '<STR_LIT>' ) <EOL> class FunctionAction ( dectate . Action ) : <EOL> config = { <EOL> '<STR_LIT>' : RegRegistry , <EOL> '<STR_LIT>' : PredicateRegistry <EOL> } <EOL> depends = [ SettingAction , <EOL> PredicateAction , PredicateFallbackAction ] <EOL> def filter_get_value ( self , name ) : <EOL> return self . key_dict . get ( name , dectate . NOT_FOUND ) <EOL> filter_convert = { <EOL> '<STR_LIT>' : dectate . convert_dotted_name <EOL> } <EOL> def __init__ ( self , func , ** kw ) : <EOL> '''<STR_LIT>''' <EOL> self . func = func <EOL> self . key_dict = kw <EOL> def predicate_key ( self , reg_registry , predicate_registry ) : <EOL> if self . func . external_predicates : <EOL> if not predicate_registry . get_predicates ( self . func ) : <EOL> reg_registry . register_external_predicates ( self . func , [ ] ) <EOL> reg_registry . register_dispatch ( self . func ) <EOL> return reg_registry . key_dict_to_predicate_key ( <EOL> self . func . wrapped_func , self . key_dict ) <EOL> def identifier ( self , reg_registry , predicate_registry ) : <EOL> return ( self . func . wrapped_func , self . predicate_key ( <EOL> reg_registry , predicate_registry ) ) <EOL> def perform ( self , obj , reg_registry , predicate_registry ) : <EOL> reg_registry . register_function ( self . func , obj , ** self . key_dict ) <EOL> @ App . directive ( '<STR_LIT>' ) <EOL> class ConverterAction ( dectate . Action ) : <EOL> config = { <EOL> '<STR_LIT>' : ConverterRegistry <EOL> } <EOL> depends = [ SettingAction ] <EOL> filter_convert = { <EOL> '<STR_LIT:type>' : dectate . convert_dotted_name <EOL> } <EOL> def __init__ ( self , type ) : <EOL> """<STR_LIT>""" <EOL> self . type = type <EOL> def identifier ( self , converter_registry ) : <EOL> return ( '<STR_LIT>' , self . type ) <EOL> def perform ( self , obj , converter_registry ) : <EOL> converter_registry . register_converter ( self . type , obj ( ) ) <EOL> @ App . private_action_class <EOL> class PathAction ( dectate . Action ) : <EOL> config = { <EOL> '<STR_LIT>' : PathRegistry , <EOL> } <EOL> depends = [ SettingAction , ConverterAction ] <EOL> filter_compare = { <EOL> '<STR_LIT>' : isbaseclass , <EOL> '<STR_LIT:path>' : lambda a , b : Path ( a ) . discriminator ( ) == Path ( b ) . discriminator ( ) <EOL> } <EOL> def __init__ ( self , path , model = None , <EOL> variables = None , converters = None , required = None , <EOL> get_converters = None , absorb = False ) : <EOL> self . model = model <EOL> self . path = path <EOL> self . variables = variables <EOL> self . converters = converters <EOL> self . required = required <EOL> self . get_converters = get_converters <EOL> self . absorb = absorb <EOL> def identifier ( self , path_registry ) : <EOL> return ( '<STR_LIT:path>' , Path ( self . path ) . discriminator ( ) ) <EOL> def discriminators ( self , path_registry ) : <EOL> return [ ( '<STR_LIT>' , self . model ) ] <EOL> def perform ( self , obj , path_registry ) : <EOL> path_registry . register_path ( <EOL> self . model , self . path , <EOL> self . variables , self . converters , self . required , <EOL> self . get_converters , self . absorb , <EOL> obj ) <EOL> @ App . directive ( '<STR_LIT:path>' ) <EOL> class PathCompositeAction ( dectate . Composite ) : <EOL> filter_convert = { <EOL> '<STR_LIT>' : dectate . convert_dotted_name , <EOL> '<STR_LIT>' : dectate . convert_dotted_name , <EOL> '<STR_LIT>' : dectate . convert_dotted_name , <EOL> '<STR_LIT>' : dectate . convert_bool , <EOL> } <EOL> query_classes = [ PathAction ] <EOL> def __init__ ( self , path , model = None , <EOL> variables = None , converters = None , required = None , <EOL> get_converters = None , absorb = False ) : <EOL> """<STR_LIT>""" <EOL> self . model = model <EOL> self . path = path <EOL> self . variables = variables <EOL> self . converters = converters <EOL> self . required = required <EOL> self . get_converters = get_converters <EOL> self . absorb = absorb <EOL> def actions ( self , obj ) : <EOL> model = self . model <EOL> if isinstance ( obj , type ) : <EOL> if model is not None : <EOL> raise dectate . DirectiveError ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" % model ) <EOL> model = obj <EOL> if model is None : <EOL> raise dectate . DirectiveError ( <EOL> "<STR_LIT>" ) <EOL> yield PathAction ( self . path , model , self . variables , self . converters , <EOL> self . required , self . get_converters , self . absorb ) , obj <EOL> @ App . directive ( '<STR_LIT>' ) <EOL> class PermissionRuleAction ( dectate . Action ) : <EOL> config = { <EOL> '<STR_LIT>' : RegRegistry <EOL> } <EOL> filter_convert = { <EOL> '<STR_LIT>' : dectate . convert_dotted_name , <EOL> '<STR_LIT>' : dectate . convert_dotted_name , <EOL> '<STR_LIT>' : dectate . convert_dotted_name , <EOL> } <EOL> filter_compare = { <EOL> '<STR_LIT>' : isbaseclass , <EOL> '<STR_LIT>' : issubclass , <EOL> '<STR_LIT>' : issubclass <EOL> } <EOL> depends = [ SettingAction ] <EOL> def __init__ ( self , model , permission , identity = Identity ) : <EOL> """<STR_LIT>""" <EOL> self . model = model <EOL> self . permission = permission <EOL> if identity is None : <EOL> identity = NoIdentity <EOL> self . identity = identity <EOL> def identifier ( self , reg_registry ) : <EOL> return ( self . model , self . permission , self . identity ) <EOL> def perform ( self , obj , reg_registry ) : <EOL> reg_registry . register_function ( <EOL> generic . permits , obj , <EOL> identity = self . identity , <EOL> obj = self . model , <EOL> permission = self . permission ) <EOL> template_directory_id = <NUM_LIT:0> <EOL> @ App . directive ( '<STR_LIT>' ) <EOL> class TemplateDirectoryAction ( dectate . Action ) : <EOL> config = { <EOL> '<STR_LIT>' : TemplateEngineRegistry <EOL> } <EOL> depends = [ SettingAction ] <EOL> filter_name = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } <EOL> filter_convert = { <EOL> '<STR_LIT>' : dectate . convert_dotted_name , <EOL> '<STR_LIT>' : dectate . convert_dotted_name , <EOL> } <EOL> def __init__ ( self , after = None , before = None , name = None ) : <EOL> '''<STR_LIT>''' <EOL> global template_directory_id <EOL> self . _after = after <EOL> self . _before = before <EOL> if name is None : <EOL> name = u'<STR_LIT>' % template_directory_id <EOL> template_directory_id += <NUM_LIT:1> <EOL> self . name = name <EOL> def identifier ( self , template_engine_registry ) : <EOL> return self . name <EOL> def perform ( self , obj , template_engine_registry ) : <EOL> directory = obj ( ) <EOL> if not os . path . isabs ( directory ) : <EOL> directory = os . path . join ( os . path . dirname ( <EOL> self . code_info . path ) , directory ) <EOL> template_engine_registry . register_template_directory_info ( <EOL> obj , directory , self . _before , self . _after , <EOL> self . directive . configurable ) <EOL> @ App . directive ( '<STR_LIT>' ) <EOL> class TemplateLoaderAction ( dectate . Action ) : <EOL> config = { <EOL> '<STR_LIT>' : TemplateEngineRegistry <EOL> } <EOL> depends = [ TemplateDirectoryAction ] <EOL> def __init__ ( self , extension ) : <EOL> '''<STR_LIT>''' <EOL> self . extension = extension <EOL> def identifier ( self , template_engine_registry ) : <EOL> return self . extension <EOL> def perform ( self , obj , template_engine_registry ) : <EOL> template_engine_registry . initialize_template_loader ( <EOL> self . extension , obj ) <EOL> @ App . directive ( '<STR_LIT>' ) <EOL> class TemplateRenderAction ( dectate . Action ) : <EOL> config = { <EOL> '<STR_LIT>' : TemplateEngineRegistry <EOL> } <EOL> depends = [ SettingAction , TemplateLoaderAction ] <EOL> def __init__ ( self , extension ) : <EOL> '''<STR_LIT>''' <EOL> self . extension = extension <EOL> def identifier ( self , template_engine_registry ) : <EOL> return self . extension <EOL> def perform ( self , obj , template_engine_registry ) : <EOL> template_engine_registry . register_template_render ( self . extension , obj ) <EOL> def issubclass_or_none ( a , b ) : <EOL> if a is None or b is None : <EOL> return a == b <EOL> return issubclass ( a , b ) <EOL> def isbaseclass_notfound ( a , b ) : <EOL> if a is dectate . NOT_FOUND : <EOL> a = object <EOL> return isbaseclass ( a , b ) <EOL> @ App . directive ( '<STR_LIT>' ) <EOL> class ViewAction ( dectate . Action ) : <EOL> config = { <EOL> '<STR_LIT>' : ViewRegistry , <EOL> } <EOL> depends = [ SettingAction , PredicateAction , <EOL> TemplateRenderAction ] <EOL> filter_convert = { <EOL> '<STR_LIT>' : dectate . convert_dotted_name , <EOL> '<STR_LIT>' : dectate . convert_dotted_name , <EOL> '<STR_LIT>' : dectate . convert_dotted_name , <EOL> '<STR_LIT>' : dectate . convert_bool , <EOL> '<STR_LIT>' : dectate . convert_dotted_name , <EOL> } <EOL> def filter_get_value ( self , name ) : <EOL> return self . predicates . get ( name , dectate . NOT_FOUND ) <EOL> filter_compare = { <EOL> '<STR_LIT>' : isbaseclass , <EOL> '<STR_LIT>' : issubclass_or_none , <EOL> '<STR_LIT>' : isbaseclass_notfound , <EOL> } <EOL> def __init__ ( self , model , render = None , template = None , <EOL> permission = None , <EOL> internal = False , ** predicates ) : <EOL> '''<STR_LIT>''' <EOL> self . model = model <EOL> self . render = render or render_view <EOL> self . template = template <EOL> self . permission = permission <EOL> self . internal = internal <EOL> self . predicates = predicates <EOL> def key_dict ( self ) : <EOL> result = self . predicates . copy ( ) <EOL> result [ '<STR_LIT>' ] = self . model <EOL> return result <EOL> def identifier ( self , view_registry ) : <EOL> return view_registry . predicate_key ( self . key_dict ( ) ) <EOL> def perform ( self , obj , view_registry ) : <EOL> view_registry . register_view ( <EOL> self . key_dict ( ) , obj , <EOL> self . render , self . template , <EOL> self . permission , self . internal ) <EOL> @ App . directive ( '<STR_LIT>' ) <EOL> class JsonAction ( ViewAction ) : <EOL> group_class = ViewAction <EOL> def __init__ ( self , model , render = None , template = None , permission = None , <EOL> internal = False , ** predicates ) : <EOL> """<STR_LIT>""" <EOL> render = render or render_json <EOL> super ( JsonAction , self ) . __init__ ( model , render , template , <EOL> permission , internal , ** predicates ) <EOL> @ App . directive ( '<STR_LIT:html>' ) <EOL> class HtmlAction ( ViewAction ) : <EOL> group_class = ViewAction <EOL> def __init__ ( self , model , render = None , template = None , permission = None , <EOL> internal = False , ** predicates ) : <EOL> """<STR_LIT>""" <EOL> render = render or render_html <EOL> super ( HtmlAction , self ) . __init__ ( model , render , template , <EOL> permission , internal , ** predicates ) <EOL> class DummyModel ( object ) : <EOL> pass <EOL> @ App . directive ( '<STR_LIT>' ) <EOL> class MountAction ( PathAction ) : <EOL> group_class = PathAction <EOL> depends = [ SettingAction , ConverterAction ] <EOL> filter_convert = { <EOL> '<STR_LIT>' : dectate . convert_dotted_name <EOL> } <EOL> filter_convert . update ( PathCompositeAction . filter_convert ) <EOL> def __init__ ( self , path , app , variables = None , converters = None , <EOL> required = None , get_converters = None , name = None ) : <EOL> """<STR_LIT>""" <EOL> super ( MountAction , self ) . __init__ ( path , <EOL> model = DummyModel , <EOL> variables = variables , <EOL> converters = converters , <EOL> required = required , <EOL> get_converters = get_converters ) <EOL> self . name = name or path <EOL> self . app = app <EOL> def discriminators ( self , path_registry ) : <EOL> return [ ( '<STR_LIT>' , self . app ) ] <EOL> def perform ( self , obj , path_registry ) : <EOL> path_registry . register_mount ( <EOL> self . app , self . path , self . variables , <EOL> self . converters , self . required , <EOL> self . get_converters , self . name , obj ) <EOL> @ App . directive ( '<STR_LIT>' ) <EOL> class DeferLinksAction ( dectate . Action ) : <EOL> group_class = PathAction <EOL> depends = [ SettingAction , MountAction ] <EOL> filter_convert = PathCompositeAction . filter_convert <EOL> filter_compare = { <EOL> '<STR_LIT>' : isbaseclass <EOL> } <EOL> def __init__ ( self , model ) : <EOL> """<STR_LIT>""" <EOL> self . model = model <EOL> def identifier ( self , path_registry ) : <EOL> return ( '<STR_LIT>' , self . model ) <EOL> def discriminators ( self , path_registry ) : <EOL> return [ ( '<STR_LIT>' , self . model ) ] <EOL> def perform ( self , obj , path_registry ) : <EOL> path_registry . register_defer_links ( self . model , obj ) <EOL> @ App . directive ( '<STR_LIT>' ) <EOL> class DeferClassLinksAction ( dectate . Action ) : <EOL> group_class = PathAction <EOL> depends = [ SettingAction , MountAction ] <EOL> filter_convert = PathCompositeAction . filter_convert <EOL> filter_compare = { <EOL> '<STR_LIT>' : isbaseclass <EOL> } <EOL> def __init__ ( self , model , variables ) : <EOL> """<STR_LIT>""" <EOL> self . model = model <EOL> self . variables = variables <EOL> def identifier ( self , path_registry ) : <EOL> return ( '<STR_LIT>' , self . model ) <EOL> def discriminators ( self , path_registry ) : <EOL> return [ ( '<STR_LIT>' , self . model ) ] <EOL> def perform ( self , obj , path_registry ) : <EOL> path_registry . register_defer_class_links ( <EOL> self . model , self . variables , obj ) <EOL> tween_factory_id = <NUM_LIT:0> <EOL> @ App . directive ( '<STR_LIT>' ) <EOL> class TweenFactoryAction ( dectate . Action ) : <EOL> config = { <EOL> '<STR_LIT>' : TweenRegistry <EOL> } <EOL> depends = [ SettingAction ] <EOL> filter_convert = { <EOL> '<STR_LIT>' : dectate . convert_dotted_name , <EOL> '<STR_LIT>' : dectate . convert_dotted_name , <EOL> } <EOL> def __init__ ( self , under = None , over = None , name = None ) : <EOL> '''<STR_LIT>''' <EOL> global tween_factory_id <EOL> self . under = under <EOL> self . over = over <EOL> if name is None : <EOL> name = u'<STR_LIT>' % tween_factory_id <EOL> tween_factory_id += <NUM_LIT:1> <EOL> self . name = name <EOL> def identifier ( self , tween_registry ) : <EOL> return self . name <EOL> def perform ( self , obj , tween_registry ) : <EOL> tween_registry . register_tween_factory ( <EOL> obj , over = self . over , under = self . under ) <EOL> @ App . private_action_class <EOL> class IdentityPolicyFunctionAction ( dectate . Action ) : <EOL> """<STR_LIT>""" <EOL> config = { <EOL> '<STR_LIT>' : IdentityPolicyRegistry , <EOL> } <EOL> depends = [ SettingAction ] <EOL> def __init__ ( self , dispatch , name ) : <EOL> self . dispatch = dispatch <EOL> self . name = name <EOL> def identifier ( self , identity_policy_registry ) : <EOL> return ( self . dispatch , self . name ) <EOL> def perform ( self , obj , identity_policy_registry ) : <EOL> identity_policy_registry . register_identity_policy_function ( <EOL> obj , self . dispatch , self . name ) <EOL> @ App . directive ( '<STR_LIT>' ) <EOL> class IdentityPolicyAction ( dectate . Composite ) : <EOL> query_classes = [ IdentityPolicyFunctionAction ] <EOL> def __init__ ( self ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> def actions ( self , obj ) : <EOL> yield IdentityPolicyFunctionAction ( generic . identify , <EOL> '<STR_LIT>' ) , obj <EOL> yield IdentityPolicyFunctionAction ( generic . remember_identity , <EOL> '<STR_LIT>' ) , obj <EOL> yield IdentityPolicyFunctionAction ( generic . forget_identity , <EOL> '<STR_LIT>' ) , obj <EOL> @ App . directive ( '<STR_LIT>' ) <EOL> class VerifyIdentityAction ( dectate . Composite ) : <EOL> query_classes = [ FunctionAction ] <EOL> filter_convert = { <EOL> '<STR_LIT>' : dectate . convert_dotted_name , <EOL> } <EOL> def __init__ ( self , identity = object ) : <EOL> '''<STR_LIT>''' <EOL> self . identity = identity <EOL> def actions ( self , obj ) : <EOL> yield FunctionAction ( generic . verify_identity , <EOL> identity = self . identity ) , obj <EOL> @ App . directive ( '<STR_LIT>' ) <EOL> class DumpJsonAction ( dectate . Action ) : <EOL> config = { <EOL> '<STR_LIT>' : RegRegistry <EOL> } <EOL> filter_convert = { <EOL> '<STR_LIT>' : dectate . convert_dotted_name <EOL> } <EOL> filter_compare = { <EOL> '<STR_LIT>' : isbaseclass <EOL> } <EOL> def __init__ ( self , model = object ) : <EOL> '''<STR_LIT>''' <EOL> self . model = model <EOL> def identifier ( self , reg_registry ) : <EOL> return self . model <EOL> def perform ( self , obj , reg_registry ) : <EOL> def dump ( request , self ) : <EOL> return obj ( self , request ) <EOL> reg_registry . register_function ( generic . dump_json , dump , obj = self . model ) <EOL> @ App . directive ( '<STR_LIT>' ) <EOL> class LoadJsonAction ( dectate . Action ) : <EOL> config = { <EOL> '<STR_LIT>' : RegRegistry <EOL> } <EOL> def __init__ ( self ) : <EOL> '''<STR_LIT>''' <EOL> pass <EOL> def identifier ( self , reg_registry ) : <EOL> return ( ) <EOL> def perform ( self , obj , reg_registry ) : <EOL> def load ( request , json ) : <EOL> return obj ( json , request ) <EOL> reg_registry . register_function ( generic . load_json , load ) <EOL> @ App . directive ( '<STR_LIT>' ) <EOL> class LinkPrefixAction ( dectate . Action ) : <EOL> config = { <EOL> '<STR_LIT>' : RegRegistry <EOL> } <EOL> def __init__ ( self ) : <EOL> '''<STR_LIT>''' <EOL> pass <EOL> def identifier ( self , reg_registry ) : <EOL> return ( ) <EOL> def perform ( self , obj , reg_registry ) : <EOL> reg_registry . register_function ( generic . link_prefix , obj ) </s>
