wiki配置管理

# 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'
)
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值