# lazily load iwid(_full)
def make_iwid_property(attr):
def getter(self):
if getattr(self, attr, None) is None:
self.load_IWID()
return getattr(self, attr)
return property(getter)
iwid = make_iwid_property("_iwid")
iwid_full = make_iwid_property("_iwid_full")
# lazily create a list of event handlers
_event_handlers = None
def make_event_handlers_prop():
def getter(self):
if self._event_handlers is None:
self._event_handlers = events.get_handlers(self)
return self._event_handlers
def setter(self, new_handlers):
self._event_handlers = new_handlers
return property(getter, setter)
event_handlers = make_event_handlers_prop()
def load_IWID(self):
""" Loads the InterWikiID of this instance. It is used to identify the instance
globally.
The IWID is available as cfg.iwid
The full IWID containing the interwiki name is available as cfg.iwid_full
This method is called by the property.
"""
try:
iwid = self.meta_dict['IWID']
except KeyError:
iwid = util.random_string(16).encode("hex") + "-" + str(int(time.time()))
self.meta_dict['IWID'] = iwid
self.meta_dict.sync()
self._iwid = iwid
if self.interwikiname is not None:
self._iwid_full = packLine([iwid, self.interwikiname])
else:
self._iwid_full = packLine([iwid])
def _config_check(self):
""" Check namespace and warn about unknown names
Warn about names which are not used by DefaultConfig, except
modules, classes, _private or __magic__ names.
This check is disabled by default, when enabled, it will show an
error message with unknown names.
"""
unknown = ['"%s"' % name for name in dir(self)
if not name.startswith('_') and
name not in DefaultConfig.__dict__ and
not isinstance(getattr(self, name), (type(sys), type(DefaultConfig)))]
if unknown:
msg = """
Unknown configuration options: %s.
For more information, visit HelpOnConfiguration. Please check your
configuration for typos before requesting support or reporting a bug.
""" % ', '.join(unknown)
raise error.ConfigurationError(msg)
def _decode(self):
""" Try to decode certain names, ignore unicode values
Try to decode str using utf-8. If the decode fail, raise FatalError.
Certain config variables should contain unicode values, and
should be defined with u'text' syntax. Python decode these if
the file have a 'coding' line.
This will allow utf-8 users to use simple strings using, without
using u'string'. Other users will have to use u'string' for
these names, because we don't know what is the charset of the
config files.
"""
charset = 'utf-8'
message = u"""
"%(name)s" configuration variable is a string, but should be
unicode. Use %(name)s = u"value" syntax for unicode variables.
Also check your "-*- coding -*-" line at the top of your configuration
file. It should match the actual charset of the configuration file.
"""
decode_names = (
'sitename', 'interwikiname', 'user_homewiki', 'logo_string', 'navi_bar',
'page_front_page', 'page_category_regex', 'page_dict_regex',
'page_group_regex', 'page_template_regex', 'page_license_page',
'page_local_spelling_words', 'acl_rights_default',
'acl_rights_before', 'acl_rights_after', 'mail_from'
)
def make_iwid_property(attr):
def getter(self):
if getattr(self, attr, None) is None:
self.load_IWID()
return getattr(self, attr)
return property(getter)
iwid = make_iwid_property("_iwid")
iwid_full = make_iwid_property("_iwid_full")
# lazily create a list of event handlers
_event_handlers = None
def make_event_handlers_prop():
def getter(self):
if self._event_handlers is None:
self._event_handlers = events.get_handlers(self)
return self._event_handlers
def setter(self, new_handlers):
self._event_handlers = new_handlers
return property(getter, setter)
event_handlers = make_event_handlers_prop()
def load_IWID(self):
""" Loads the InterWikiID of this instance. It is used to identify the instance
globally.
The IWID is available as cfg.iwid
The full IWID containing the interwiki name is available as cfg.iwid_full
This method is called by the property.
"""
try:
iwid = self.meta_dict['IWID']
except KeyError:
iwid = util.random_string(16).encode("hex") + "-" + str(int(time.time()))
self.meta_dict['IWID'] = iwid
self.meta_dict.sync()
self._iwid = iwid
if self.interwikiname is not None:
self._iwid_full = packLine([iwid, self.interwikiname])
else:
self._iwid_full = packLine([iwid])
def _config_check(self):
""" Check namespace and warn about unknown names
Warn about names which are not used by DefaultConfig, except
modules, classes, _private or __magic__ names.
This check is disabled by default, when enabled, it will show an
error message with unknown names.
"""
unknown = ['"%s"' % name for name in dir(self)
if not name.startswith('_') and
name not in DefaultConfig.__dict__ and
not isinstance(getattr(self, name), (type(sys), type(DefaultConfig)))]
if unknown:
msg = """
Unknown configuration options: %s.
For more information, visit HelpOnConfiguration. Please check your
configuration for typos before requesting support or reporting a bug.
""" % ', '.join(unknown)
raise error.ConfigurationError(msg)
def _decode(self):
""" Try to decode certain names, ignore unicode values
Try to decode str using utf-8. If the decode fail, raise FatalError.
Certain config variables should contain unicode values, and
should be defined with u'text' syntax. Python decode these if
the file have a 'coding' line.
This will allow utf-8 users to use simple strings using, without
using u'string'. Other users will have to use u'string' for
these names, because we don't know what is the charset of the
config files.
"""
charset = 'utf-8'
message = u"""
"%(name)s" configuration variable is a string, but should be
unicode. Use %(name)s = u"value" syntax for unicode variables.
Also check your "-*- coding -*-" line at the top of your configuration
file. It should match the actual charset of the configuration file.
"""
decode_names = (
'sitename', 'interwikiname', 'user_homewiki', 'logo_string', 'navi_bar',
'page_front_page', 'page_category_regex', 'page_dict_regex',
'page_group_regex', 'page_template_regex', 'page_license_page',
'page_local_spelling_words', 'acl_rights_default',
'acl_rights_before', 'acl_rights_after', 'mail_from'
)