Back to index

moin  1.9.0~rc2
Classes | Functions | Variables
MoinMoin.config.multiconfig Namespace Reference

Classes

class  CacheClass
class  ConfigFunctionality
class  DefaultConfig
class  DefaultExpression

Functions

def _importConfigModule
def _url_re_list
def _makeConfig
def _getConfigName
def getConfig
def _
def _default_password_checker
def _add_options_to_defconfig

Variables

tuple logging = log.getLogger(__name__)
 _url_re_cache = None
 _farmconfig_mtime = None
dictionary _config_cache = {}
dictionary options_no_group_name
dictionary options

Class Documentation

class MoinMoin::config::multiconfig::CacheClass
just a container for stuff we cache 

Definition at line 204 of file multiconfig.py.


Function Documentation

def MoinMoin.config.multiconfig._ (   text) [private]

Definition at line 200 of file multiconfig.py.

00200 
00201 def _(text):
00202     return text
00203 

def MoinMoin.config.multiconfig._add_options_to_defconfig (   opts,
  addgroup = True 
) [private]

Definition at line 1234 of file multiconfig.py.

01234 
01235 def _add_options_to_defconfig(opts, addgroup=True):
01236     for groupname in opts:
01237         group_short, group_doc, group_opts = opts[groupname]
01238         for name, default, doc in group_opts:
01239             if addgroup:
01240                 name = groupname + '_' + name
01241             if isinstance(default, DefaultExpression):
01242                 default = default.value
01243             setattr(DefaultConfig, name, default)
01244 
01245 _add_options_to_defconfig(options)
01246 _add_options_to_defconfig(options_no_group_name, False)
01247 
# remove the gettext pseudo function
def MoinMoin.config.multiconfig._default_password_checker (   cfg,
  request,
  username,
  password 
) [private]
Check if a password is secure enough.
    We use a built-in check to get rid of the worst passwords.

    We do NOT use cracklib / python-crack here any more because it is
    not thread-safe (we experienced segmentation faults when using it).

    If you don't want to check passwords, use password_checker = None.

    @return: None if there is no problem with the password,
             some unicode object with an error msg, if the password is problematic.

Definition at line 653 of file multiconfig.py.

00653 
00654 def _default_password_checker(cfg, request, username, password):
00655     """ Check if a password is secure enough.
00656         We use a built-in check to get rid of the worst passwords.
00657 
00658         We do NOT use cracklib / python-crack here any more because it is
00659         not thread-safe (we experienced segmentation faults when using it).
00660 
00661         If you don't want to check passwords, use password_checker = None.
00662 
00663         @return: None if there is no problem with the password,
00664                  some unicode object with an error msg, if the password is problematic.
00665     """
00666     _ = request.getText
00667     # in any case, do a very simple built-in check to avoid the worst passwords
00668     if len(password) < 6:
00669         return _("Password is too short.")
00670     if len(set(password)) < 4:
00671         return _("Password has not enough different characters.")
00672 
00673     username_lower = username.lower()
00674     password_lower = password.lower()
00675     if username in password or password in username or \
00676        username_lower in password_lower or password_lower in username_lower:
00677         return _("Password is too easy (password contains name or name contains password).")
00678 
00679     keyboards = (ur"`1234567890-=qwertyuiop[]\asdfghjkl;'zxcvbnm,./", # US kbd
00680                  ur"^1234567890ß´qwertzuiopü+asdfghjklöä#yxcvbnm,.-", # german kbd
00681                 ) # add more keyboards!
00682     for kbd in keyboards:
00683         rev_kbd = kbd[::-1]
00684         if password in kbd or password in rev_kbd or \
00685            password_lower in kbd or password_lower in rev_kbd:
00686             return _("Password is too easy (keyboard sequence).")
00687     return None
00688 

Here is the call graph for this function:

Return config name for url or raise 

Definition at line 169 of file multiconfig.py.

00169 
00170 def _getConfigName(url):
00171     """ Return config name for url or raise """
00172     for name, regex in _url_re_list():
00173         match = regex.match(url)
00174         if match:
00175             return name
00176     raise error.NoConfigMatchedError
00177 

Here is the call graph for this function:

Here is the caller graph for this function:

Import and return configuration module and its modification time

Handle all errors except ImportError, because missing file is not
always an error.

@param name: module name
@rtype: tuple
@return: module, modification time

Definition at line 37 of file multiconfig.py.

00037 
00038 def _importConfigModule(name):
00039     """ Import and return configuration module and its modification time
00040 
00041     Handle all errors except ImportError, because missing file is not
00042     always an error.
00043 
00044     @param name: module name
00045     @rtype: tuple
00046     @return: module, modification time
00047     """
00048     try:
00049         module = __import__(name, globals(), {})
00050         mtime = os.path.getmtime(module.__file__)
00051     except ImportError:
00052         raise
00053     except IndentationError, err:
00054         logging.exception('Your source code / config file is not correctly indented!')
00055         msg = """IndentationError: %(err)s
00056 
00057 The configuration files are Python modules. Therefore, whitespace is
00058 important. Make sure that you use only spaces, no tabs are allowed here!
00059 You have to use four spaces at the beginning of the line mostly.
00060 """ % {
00061     'err': err,
00062 }
00063         raise error.ConfigurationError(msg)
00064     except Exception, err:
00065         logging.exception('An exception happened.')
00066         msg = '%s: %s' % (err.__class__.__name__, str(err))
00067         raise error.ConfigurationError(msg)
00068     return module, mtime
00069 

Here is the caller graph for this function:

def MoinMoin.config.multiconfig._makeConfig (   name) [private]
Create and return a config instance

Timestamp config with either module mtime or farmconfig mtime. This
mtime can be used later to invalidate older caches.

@param name: module name
@rtype: DefaultConfig sub class instance
@return: new configuration instance

Definition at line 111 of file multiconfig.py.

00111 
00112 def _makeConfig(name):
00113     """ Create and return a config instance
00114 
00115     Timestamp config with either module mtime or farmconfig mtime. This
00116     mtime can be used later to invalidate older caches.
00117 
00118     @param name: module name
00119     @rtype: DefaultConfig sub class instance
00120     @return: new configuration instance
00121     """
00122     global _farmconfig_mtime
00123     try:
00124         module, mtime = _importConfigModule(name)
00125         configClass = getattr(module, 'Config')
00126         cfg = configClass(name)
00127         cfg.cfg_mtime = max(mtime, _farmconfig_mtime)
00128         logging.info("using wiki config: %s" % os.path.abspath(module.__file__))
00129     except ImportError, err:
00130         logging.exception('Could not import.')
00131         msg = """ImportError: %(err)s
00132 
00133 Check that the file is in the same directory as the server script. If
00134 it is not, you must add the path of the directory where the file is
00135 located to the python path in the server script. See the comments at
00136 the top of the server script.
00137 
00138 Check that the configuration file name is either "wikiconfig.py" or the
00139 module name specified in the wikis list in farmconfig.py. Note that the
00140 module name does not include the ".py" suffix.
00141 """ % {
00142     'err': err,
00143 }
00144         raise error.ConfigurationError(msg)
00145     except AttributeError, err:
00146         logging.exception('An exception occured.')
00147         msg = """AttributeError: %(err)s
00148 
00149 Could not find required "Config" class in "%(name)s.py".
00150 
00151 This might happen if you are trying to use a pre 1.3 configuration file, or
00152 made a syntax or spelling error.
00153 
00154 Another reason for this could be a name clash. It is not possible to have
00155 config names like e.g. stats.py - because that collides with MoinMoin/stats/ -
00156 have a look into your MoinMoin code directory what other names are NOT
00157 possible.
00158 
00159 Please check your configuration file. As an example for correct syntax,
00160 use the wikiconfig.py file from the distribution.
00161 """ % {
00162     'name': name,
00163     'err': err,
00164 }
00165         raise error.ConfigurationError(msg)
00166 
00167     return cfg
00168 

Here is the call graph for this function:

Here is the caller graph for this function:

Return url matching regular expression

Import wikis list from farmconfig on the first call and compile the
regexes. Later just return the cached regex list.

@rtype: list of tuples of (name, compiled re object)
@return: url to wiki config name matching list

Definition at line 70 of file multiconfig.py.

00070 
00071 def _url_re_list():
00072     """ Return url matching regular expression
00073 
00074     Import wikis list from farmconfig on the first call and compile the
00075     regexes. Later just return the cached regex list.
00076 
00077     @rtype: list of tuples of (name, compiled re object)
00078     @return: url to wiki config name matching list
00079     """
00080     global _url_re_cache, _farmconfig_mtime
00081     if _url_re_cache is None:
00082         try:
00083             farmconfig, _farmconfig_mtime = _importConfigModule('farmconfig')
00084         except ImportError, err:
00085             if 'farmconfig' in str(err):
00086                 # we failed importing farmconfig
00087                 logging.debug("could not import farmconfig, mapping all URLs to wikiconfig")
00088                 _farmconfig_mtime = 0
00089                 _url_re_cache = [('wikiconfig', re.compile(r'.')), ] # matches everything
00090             else:
00091                 # maybe there was a failing import statement inside farmconfig
00092                 raise
00093         else:
00094             logging.info("using farm config: %s" % os.path.abspath(farmconfig.__file__))
00095             try:
00096                 cache = []
00097                 for name, regex in farmconfig.wikis:
00098                     cache.append((name, re.compile(regex)))
00099                 _url_re_cache = cache
00100             except AttributeError:
00101                 logging.error("required 'wikis' list missing in farmconfig")
00102                 msg = """
00103 Missing required 'wikis' list in 'farmconfig.py'.
00104 
00105 If you run a single wiki you do not need farmconfig.py. Delete it and
00106 use wikiconfig.py.
00107 """
00108                 raise error.ConfigurationError(msg)
00109     return _url_re_cache
00110 

Here is the call graph for this function:

Here is the caller graph for this function:

Return cached config instance for url or create new one

If called by many threads in the same time multiple config
instances might be created. The first created item will be
returned, using dict.setdefault.

@param url: the url from request, possibly matching specific wiki
@rtype: DefaultConfig subclass instance
@return: config object for specific wiki

Definition at line 178 of file multiconfig.py.

00178 
00179 def getConfig(url):
00180     """ Return cached config instance for url or create new one
00181 
00182     If called by many threads in the same time multiple config
00183     instances might be created. The first created item will be
00184     returned, using dict.setdefault.
00185 
00186     @param url: the url from request, possibly matching specific wiki
00187     @rtype: DefaultConfig subclass instance
00188     @return: config object for specific wiki
00189     """
00190     cfgName = _getConfigName(url)
00191     try:
00192         cfg = _config_cache[cfgName]
00193     except KeyError:
00194         cfg = _makeConfig(cfgName)
00195         cfg = _config_cache.setdefault(cfgName, cfg)
00196     return cfg
00197 
00198 
00199 # This is a way to mark some text for the gettext tools so that they don't
# get orphaned. See http://www.python.org/doc/current/lib/node278.html.

Here is the call graph for this function:


Variable Documentation

Definition at line 34 of file multiconfig.py.

Definition at line 33 of file multiconfig.py.

Definition at line 32 of file multiconfig.py.

Definition at line 17 of file multiconfig.py.

Definition at line 1090 of file multiconfig.py.

Definition at line 700 of file multiconfig.py.