@@ -759,7 +759,6 @@ def __init__(self, config_file, verbose=False, skip_log=False,
759759 self .default_page = None
760760 self .auth_logger_obj = None
761761 self .gdp_logger_obj = None
762- self ._context = None
763762
764763 configuration_options = copy .deepcopy (_CONFIGURATION_DEFAULTS )
765764
@@ -771,26 +770,6 @@ def __init__(self, config_file, verbose=False, skip_log=False,
771770 disable_auth_log = disable_auth_log ,
772771 _config_file = config_file )
773772
774- def context (self , namespace = None ):
775- """Retrieve the context or a previously registered namespace.
776- """
777-
778- if self ._context is None :
779- self ._context = {}
780- if namespace is None :
781- return self ._context
782- # allow the KeyError to escape if the registered namespace is missing
783- return self ._context [namespace ]
784-
785- def context_set (self , value , namespace = None ):
786- """Attach a value as named namespace within the active congifuration.
787- """
788- assert namespace is not None
789-
790- context = self .context ()
791- context [namespace ] = value
792- return value
793-
794773 def reload_config (self , verbose , skip_log = False , disable_auth_log = False ,
795774 _config_file = None ):
796775 """Re-read and parse configuration file. Optional skip_log arg
@@ -2872,6 +2851,47 @@ def parse_peers(self, peerfile):
28722851 return peers_dict
28732852
28742853
2854+ class RuntimeConfiguration (Configuration ):
2855+ """A more specific version of the Configuration which additionally supports
2856+ the notion of a context.
2857+
2858+ Contextual information that is relevant to the duration of a request is
2859+ required in certain cases e.g. to support templating. Given Configuration
2860+ objects are threaded into and throough almost all the necessary codepaths
2861+ to make this information available, they are an attractive place to put
2862+ this - but a Configuration is currently loaded from static per-site data.
2863+
2864+ Resolv this ambiguity with this subclass - a raw Confioguration will
2865+ continute to represent the static data while a specialised but entirely
2866+ compatible object is handed to request processing codepaths.
2867+ """
2868+
2869+ def __init__ (self , config_file , verbose = False , skip_log = False ,
2870+ disable_auth_log = False ):
2871+ super ().__init__ (config_file , verbose , skip_log , disable_auth_log )
2872+ self ._context = None
2873+
2874+ def context (self , namespace = None ):
2875+ """Retrieve the context or a previously registered namespace.
2876+ """
2877+
2878+ if self ._context is None :
2879+ self ._context = {}
2880+ if namespace is None :
2881+ return self ._context
2882+ # allow the KeyError to escape if the registered namespace is missing
2883+ return self ._context [namespace ]
2884+
2885+ def context_set (self , value , namespace = None ):
2886+ """Attach a value as named namespace within the active congifuration.
2887+ """
2888+ assert namespace is not None
2889+
2890+ context = self .context ()
2891+ context [namespace ] = value
2892+ return value
2893+
2894+
28752895if '__main__' == __name__ :
28762896 conf = Configuration (os .path .expanduser ('~/mig/server/MiGserver.conf' ),
28772897 True )
0 commit comments