Configuration parameters in Myghty are basically a big dictionary of data that is initially passed to the constructor for myghty.interp.Interpreter, which represents the entry point for running a Myghty template. Upon construction, the Interpreter instantiates all the other objects it needs, such as the Compiler, the Resolver, and a prototype Request object (a prototype is an object that is used as a template to make copies of itself), passing in the same hash of configuration parameters. Each object takes what it needs out of the dictionary.
If you are writing your own interface to Interpreter, such as a standalone or simple CGI client, you can pass one or more of these values programmatically to the constructor of the Interpreter. If running from mod python, values can be specified in the http.conf file using the format Myghty<Name>, where Name is the parameter name in InitialCaps format (i.e., data_dir becomes DataDir).
Note also that there are configuration parameters specific to the caching mechanism, listed in Cache Options, as well as session specific parameters listed in Session Options.
allow_globals (list of strings) |
for users: developers
default: None used by: Compiler |
A list of global variable names that will be compiled into Myghty templates, and will be expected to be provided upon template execution. The variable "r", representing the Apache Request, is delivered to templates via this parameter. To add your own variables, specify their names in this list, and also specify it as a key in the RequestImpl argument global_args to provide the values. See the section Make your Own Friends for details. |
|
attributes (dictionary) |
for users: all
default: None used by: Interpreter |
A dictionary of data that will be stored by the Interpreter used throughout a particular Myghty application. This is a way to set per-application global variables. The values are accessible via the interpreter.attributes dictionary. i = interp.Interpreter(attributes = {'param': 'value'}) # call interpreter off request, # and get an attribute p = m.interpreter.attributes['param'] # call interpreter off component, # and set an attribute self.interpreter.attributes['param'] = 'value' Interpreter attributes can be compared to component attributes, as well as request attributes. |
|
auto_flush (boolean) |
for users: developers
default: False used by: Request |
Whether or not m.write calls will be automatically flushed to the final output stream as they are called, or will be buffered until the end of the request. Autoflush being on makes things a little more tricky, as you can't do any kind of page redirects (neither external nor internal) once the content starts coming out. Error messages become messy as well since they are similar to an internal redirect. Autoflush can be set in a variety of ways and is described fully in the section The Autoflush Option. |
|
auto_handler_name (string) |
for users: administrators
default: autohandler used by: Interpreter |
The name of the file used as a global page wrapper, defaults to 'autohandler'. See the section autohandlers for information on autohandlers. |
|
cache_debug_file (file object) |
for users: optimizers
default: None used by: Cache since version: 0.94 |
If pointing to a Python file object, container operations performed by the caching system will be logged, allowing the viewing of how often data is being refreshed as well as how many concurrent threads and processes are hitting various containers. When running with ApacheHandler or CGIHandler, this parameter can be set to the standard Apache log via the parameter log_cache_operations. |
|
code_cache_size (integer) |
for users: optimizers
default: 16777216 used by: Interpreter |
Size of the cache used by Interpreter to cache loaded component objects, measured in bytes. The cache works on a "least recently used" scheme. This value has a great impact on performance, as too large a value can use up lots of memory for a very large site, and too small results in excessive "swapping" of components in and out of memory. Cache operations can be logged via debug_file. |
|
compiler (object) |
for users: hackers
default: myghty.compiler.Compiler used by: Interpreter |
An instance of myghty.compiler.Compiler used to generate object files. Not much reason to play with this unless you are seriously hacking your own engine. The default Compiler object will receive its optional parameters from the argument list sent to the constructor for Interpreter. |
|
component_root (string or list) |
for users: all
default: None used by: Resolver |
This parameter is almost always required; it is the filesystem location, or list of locations, with which to locate Myghty component files. The two formats of component_root are as follows: Single string component_root = "/web/sites/mysite/htdocs" List of hashes component_root = [ {'main':"/web/sites/mysite/htdocs"}, {'components':"/web/sites/mysite/components"}, {'alt':"/usr/local/lib/special-comp"} ] The single string specifies one root for all component calls, which will be assigned the identifying key "main". The list of hashes specifies the keys and paths for a collection of locations which will be searched in order for a component. This allows you to have one file tree that is web-server accessible files, and another file tree that contains files which can only be used as embedded components, and can't be accessed by themselves. The key names are used to uniquely identify a component by both its location and its name, such as "main:/docs/index.myt". For examples of component_root configuration, see the section Configuration. For advanced options on file-based resolution, see Advanced Resolver Configuration. |
|
data_dir (string) |
for users: all
default: None used by: Interpreter |
Directory to be used to store compiled object files (.py files and .pyc files), lock files used for synchronization, as well as container files which store data for the component caching system and the session object. A non-None value implies True for the "use_object_files" setting. Compiled object files are stored in the obj directory, and cache/session files are stored underneath container_XXX directories. |
|
debug_elements (list) |
for users: optimizers
default: [] used by: Interpreter since version: 0.97alpha3 |
A list of string names that refer to various elements that can send debug information to the Interpreter's debug output. An example with all allowed names: debug_elements = [ # all resolution of components 'resolution', # inspection of component objects and modules loaded into memory and later garbage-collected 'codecache', # inspection of the generation and compilation of components 'classloading', # cache operations, reloading of cached data 'cache', ] |
|
debug_file (file object) |
for users: optimizers
default: stderr used by: Interpreter since version: 0.93b |
References a Python file object; if non-None, the Interpreter will send debugging information to this file. Note that line breaks are not sent by default; use code such as myghty.buffer.LinePrinter(sys.stderr) to wrap the file in a line-based formatter. When running the Interpreter in an HTTP context, various implementations of HTTPHandler supply their own stream for debugging information, such as the ApacheHandler which supplies the Apache error log as a filehandle. As of version 0.97alpha3, to actually enable debug logging requires the debug_elements parameter to be set up. |
|
default_escape_flags (list) |
for users: developers
default: None used by: Compiler |
This is a list of escape flags that will be automatically applied to all substitution calls, i.e. <% string %>. See Escaping Content for more information on content escaping. |
|
dhandler_name (string) |
for users: administrators
default: dhandler used by: Request |
The name of the file used as a directory handler, defaults to 'dhandler'. See the section dhandlers for information on directory handlers. |
|
disable_unicode (boolean) |
for users: developers
default: False used by: Request, Compiler since version: 1.1 |
Disable the new unicode support features. If set, all strings are assumed to be strs in the system default encoding (usually ASCII). See the section on Unicode Support for further details. |
|
dont_auto_flush_filters (boolean) |
for users: developers
default: False used by: Request |
If auto_flush is turned on, this option will keep auto_flush turned off for components that use <%filter> sections. This is useful if you have filters that rely upon receiving the entire block of text at once. See the section <%filter> for more information on filters. |
|
encoding_errors (string) |
for users: developers
default: strict used by: Request since version: 1.1 |
Sets the initial value for the encoding_errors of requests, which, in turn, determines how character set encoding errors are handled. Some choices are:
See also the section on Unicode Support, and the Python codecs documentation. |
|
error_handler (function) |
for users: developers
default: None used by: RequestImpl |
A function object that will be passed all exceptions and given the chance to handle them before regular processing occurs. The format of the function is: def handle_error(e, m, **params): # custom error handling goes here # ... # return False to continue handling error, True to disregard return False Where 'e' is a myghty.exception.Error object and m is the request object. The global variable 'r' will also be passed if running in an HTTP context. The function should return True to stop all further error handling, or False to continue error handling as normal. The request object, while it is the same instance used to handle the request initially, no longer will have any buffered content and will also not have a current component instance. It is safe to call subrequests from it, allowing the construction of custom error pages. See also raise_error to simply raise an error outside the Request and bypass all internal and custom error handling. |
|
escapes (dict) |
for users: developers
default: {'h':html_escape, 'u':url_escape} used by: Interpreter |
Use this parameter to define your own custom escaping functions that are available within substitutions, as well as m.apply_escapes(). Within a dictionary key/value pair, the key is the identifying character, and the value is a reference to a single-argument function that will be called with the string with which to apply the text escape. The function should return the filtered text. Escaping is described fully at Escaping Content. |
|
generator (object) |
for users: hackers
default: myghty.objgen.PythonGenerator used by: Compiler |
An instance of myghty.objgen.ObjectGenerator that is used to generate object files. Again, for the brave hacker, you can write your own generator and output object files in whatever language you like. |
|
global_args (dictionary) |
for users: developers
default: None used by: RequestImpl |
A list of global argument names and values that will be available in all template calls. See the section Make your Own Friends for details. |
|
interpreter_name (string) |
for users: administrators
default: None used by: HTTPHandler |
Specifies the name of the Myghty interpreter that should be used. All HTTP handlers modules maintain a dictionary of HTTPHandler instances, each of which references a Myghty interpreter, keyed off of a name. When this name is explicitly specified, that particular handler will be created if it doesnt exist and then used. This option is currently most useful for use within multiple Apache directives, so that different sets of configuration parameters can be used for different directives, without requiring the use mod_python's multiple Python interpreters feature. See the example in Advanced mod_python Configuration - Multiple ApacheHandlers. |
|
lexer (object) |
for users: hackers
default: myghty.lexer.Lexer used by: Compiler |
An instance of myghty.request.Lexer, used to parse the text of template files. |
|
log_cache_operations (boolean) |
for users: optimizers
default: False used by: ApacheHandler or CGIHandler since version: 0.93b |
Deprecated; use debug_elements instead. |
|
log_component_loading (boolean) |
for users: optimizers
default: False used by: ApacheHandler or CGIHandler since version: 0.93b |
Deprecated; use debug_elements instead. |
|
log_errors (boolean) |
for users: administrators
default: False used by: HTTPHandler |
Specifies whether or not component errors should receive a full stack trace in the Apache error log, standard error output of CGIHandler, or other HTTP-specific logging system. If false, component errors still produce a single-line description of the error in the log. See also output_errors. If raise_error is set to true, no logging of errors occurs. |
|
max_recursion (integer) |
for users: optimizers
default: 32 used by: Request |
The highest level of component recursion that can occur, i.e. as in recursive calls to a subcomponent. |
|
module_components (array of hashes) |
for users: all
default: None used by: ResolveModule |
This parameter is used for resolving Module Components using regular expressions which are mapped to function, class or class instance objects. See module_components for examples. |
|
module_root (array of hashes) |
for users: all
default: None used by: ResolvePathModule |
This parameter is used for resolving Module Components using file paths which map to the locations of python files and the attributes within. See module_root for examples. |
|
module_root_adjust (callable) |
for users: all
default: None used by: ResolvePathModule since version: 0.99b |
This parameter is used in combination with module_root to specify a callable that will translate an incoming URI before being resolved to a path-based module. See module_root for more detail. |
|
out_buffer (object) |
for users: developers
default: None used by: DefaultRequestImpl |
A Python file object, or similar, with which to send component output. See the Configuration section for examples. |
|
output_encoding (string) |
for users: developers
default: sys.getdefaultencoding() used by: Request since version: 1.1 |
Sets the initial value for the output_encoding of requests. The default value is python's system default encoding (usually ASCII.) See the section on Unicode Support for further details. |
|
output_errors (boolean) |
for users: administrators
default: True used by: ApacheHandler or CGIHandler since version: 0.93b |
Specifies whether or not component errors with full stack trace should be reported to the client application. If false, component errors will produce a 500 Server Error. See also log_errors. If raise_error is set to True, this parameter is overridden and client will receive a 500 server error (unless the error is caught by an external handler). |
|
parent_request (object) |
for users: hackers
default: None used by: Request |
This parameter specifies the parent request when making subrequests, and is automatically provided. For more information see Programmatic Interface. |
|
path_moduletokens (list of strings) |
for users: all
default: ['index'] used by: ResolvePathModule since version: 0.99b |
Used by module_root to specify default path tokens that should be searched in module attribute paths. See Module Root Options for details. |
|
path_stringtokens (list of strings) |
for users: all
default: [] used by: ResolvePathModule since version: 0.99b |
Used by module_root to specify default path tokens that should be searched in file paths. See Module Root Options for details. |
|
path_translate (list of tuples, or a callable) |
for users: administrators
default: None used by: Resolver |
A list of regular-expression translations that will be performed on paths before they are used to locate a component and/or module component. This can be useful for complicated web server configurations where aliases point to component roots, or specifying a default document for path requests. It looks as follows: path_translate = [ # convert /store/* to /shop/* (r'^/store/(.*)', r'/shop/\1'), # convert /documents/* to /docs/* (r'^/documents/', '/docs/'), # convert /foo/bar/ to /foo/bar/index.myt (r'/$', '/index.myt'), ] As of revision 0.99b, the argument to path_translate can alternatively be specified as a callable, which converts its given URI to the translated value: def my_translate(uri): return "/doc/" + uri path_translate = my_translate Note that the request_path member of the request object will reference the original path before translation, whereas the path of the component served will contain the translated path (for file-based components). More detail about path translation can be found in Advanced Resolver Configuration. |
|
python_post_processor (function) |
for users: hackers
default: None used by: Compiler |
References a function that will be invoked with the full text of each individual unit of Python code created during component generation (i.e., creation of .py files). The returned string will be used as the Python code that is actually placed within the generated .py file. Also see text_post_processor. |
|
python_pre_processor (function) |
for users: hackers
default: None used by: Compiler |
References a function that will be invoked with the full text of a template's source file before it is parsed. The returned string will then be used as the source to be parsed. |
|
raise_error (boolean) |
for users: developers
default: False used by: Request since version: 0.97a |
Indicates if errors should be raised when they occur, or be handled by error handling functionality. If set to True, no error logging, friendly client response, or custom internal error handler function will happen. Instead, an external error handler can be used. This parameter overrides invalidates the functionality of log_errors, output_errors and error_handler. This parameter allows the entire interpreter.execute() or handler.handle() call to be wrapped in a try: / except: block, where the error can be handled externally to all Myghty functionality. |
|
request (object) |
for users: hackers
default: myghty.request.Request used by: Interpreter |
An instance of myghty.request.Request used as a prototype to generate new requests. Its context-specific behavior is supplied by a separate instance of myghty.request.RequestImpl, so there is not much reason to change this either. |
|
request_impl (object) |
for users: hackers
default: myghty.request.DefaultRequestImpl used by: Request |
An instance of myghty.request.RequestImpl that will be used either as a prototype to create new RequestImpls per request, or can be passed per individual interpreter execution. RequestImpl tells Request how it should interact with its environment. Take a look at ApacheHandler.ApacheRequestImpl, CGIHandler.CGIRequestImpl, and myghty.request.DefaultRequestImpl for examples. |
|
request_path (string) |
for users: developers
default: myghty.request.Request used by: Request |
Sets the initial request path for this request. In most cases, this is set automatically by simply calling a request with a string-based component name, or with a file-based component which can return its originating path. However, in the case of a request being called with a memory or module-based component, the path defaults to None and must be set by the calling function if it is to be referenced by components. |
|
require_publish (boolean) |
for users: all
default: False used by: ResolvePathModule since version: 0.99b |
Indicates that callables located via module_root resolution require an attribute named 'public' set to True attached to them, in order to allow access. See Module Root Options for details. |
|
resolver (object) |
for users: hackers
default: myghty.resolver.FileResolver used by: Interpreter |
An instance of myghty.resolver.Resolver that is used to locate component files. Both ApacheHandler and CGIHandler have their own instances of Resolver but don't yet do anything special. If you wanted some kind of special file resolution behavior, you can swap in your own subclass of Resolver. |
|
resolver_strategy (list) |
for users: developers
default: None used by: Resolver |
Allows configuration of the rules used in component resolution. See the section Advanced Resolver Configuration for details. |
|
source_cache_size (integer) |
for users: optimizers
default: 1000 used by: Interpreter |
Size of the cache used by Interpreter to cache the source of components. See use_static_source for a description of source caching, and see code_cache_size for a description of the LRU caching scheme. |
|
text_post_processor (function) |
for users: hackers
default: None used by: Compiler |
References a function that will be invoked with the full text of each individual unit of output text created during component generation (i.e., creation of .py files). The returned string will be used as the output text that is actually placed within the generated .py file. Also see python_post_processor. |
|
use_auto_handlers (boolean) |
for users: developers
default: True used by: Interpreter |
Whether or not to use autohandlers. See the section autohandlers for more information. |
|
use_dhandlers (boolean) |
for users: developers
default: True used by: Request |
Whether or not to use directory handlers. See the section dhandlers for more information. |
|
use_object_files (boolean) |
for users: optimizers
default: True if data_dir is not null used by: Interpreter |
Indicates whether or not components should be compiled into module files on the filesystem, or into strings held in memory. A value of None for the data_dir parameter will have the same effect. There is no advantage whatsoever to having components compiled in memory, and startup performance will be degraded for repeated calls to the same component. It might be useful if you are running the interpreter in a "one shot" fashion where there is no need to have compiled object files lying around. |
|
use_session (boolean) |
for users: developers
default: None used by: ApacheHandler |
The additional global variable s to reference the Myghty session, or alternatively the mod_python 3.1 session, is turned on when this option is set to True. See the section Session for details. |
|
use_source_line_numbers (boolean) |
for users: hackers
default: None used by: Compiler |
Whether or not to put source line numbers in compiled object files. This is used to generate friendly stack traces upon errors (when that feature is complete). |
|
use_static_source (boolean) |
for users: optimizers
default: False used by: Interpreter, Resolver |
This parameter, when set to True:
|