本文整理汇总了Python中MoinMoin.wikiutil.importPlugin函数的典型用法代码示例。如果您正苦于以下问题:Python importPlugin函数的具体用法?Python importPlugin怎么用?Python importPlugin使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了importPlugin函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: contentfilter
def contentfilter(self, filename):
""" Get a filter for content of filename and return unicode content. """
import mimetypes
from MoinMoin import wikiutil
request = self.request
mimetype, encoding = mimetypes.guess_type(filename)
if mimetype is None:
mimetype = 'application/octet-stream'
def mt2mn(mt): # mimetype to modulename
return mt.replace("/", "_").replace("-","_").replace(".", "_")
try:
_filter = mt2mn(mimetype)
execute = wikiutil.importPlugin(request.cfg, 'filter', _filter)
except wikiutil.PluginMissingError:
try:
_filter = mt2mn(mimetype.split("/", 1)[0])
execute = wikiutil.importPlugin(request.cfg, 'filter', _filter)
except wikiutil.PluginMissingError:
try:
_filter = mt2mn('application/octet-stream')
execute = wikiutil.importPlugin(request.cfg, 'filter', _filter)
except wikiutil.PluginMissingError:
raise ImportError("Cannot load filter %s" % binaryfilter)
try:
data = execute(self, filename)
request.log("Filter %s returned %d characters for file %s" % (_filter, len(data), filename))
except (OSError, IOError), err:
data = ''
request.log("Filter %s threw error '%s' for file %s" % (_filter, str(err), filename))
示例2: setProcessor
def setProcessor(self, name):
""" Set processer to either processor or parser named 'name' """
cfg = self.request.cfg
try:
self.processor = wikiutil.importPlugin(cfg, "processor", name, "process")
self.processor_is_parser = 0
except wikiutil.PluginMissingError:
try:
self.processor = wikiutil.importPlugin(cfg, "parser", name, "Parser")
self.processor_is_parser = 1
except wikiutil.PluginMissingError:
self.processor = None
示例3: execute
def execute(self, macro_name, args):
""" Get and execute a macro
Try to get a plugin macro, or a builtin macro or a language
macro, or just raise ImportError.
"""
self.name = macro_name
try:
str(macro_name)
except UnicodeEncodeError:
_ = self._
return self.formatter.text(_("<<%(macro_name)s: invalid macro name>>") % {"macro_name": macro_name})
try:
call = wikiutil.importPlugin(self.cfg, "macro", macro_name, function="macro_%s" % macro_name)
execute = lambda _self, _args: wikiutil.invoke_extension_function(_self.request, call, _args, [_self])
except wikiutil.PluginAttributeError:
# fall back to old execute() method, no longer recommended
execute = wikiutil.importPlugin(self.cfg, "macro", macro_name)
except wikiutil.PluginMissingError:
try:
call = getattr(self, "macro_%s" % macro_name)
execute = lambda _self, _args: wikiutil.invoke_extension_function(_self.request, call, _args, [])
except AttributeError:
if macro_name in i18n.wikiLanguages():
execute = self.__class__._m_lang
else:
raise ImportError("Cannot load macro %s" % macro_name)
try:
return execute(self, args)
except Exception, err:
# we do not want that a faulty macro aborts rendering of the page
# and makes the wiki UI unusable (by emitting a Server Error),
# thus, in case of exceptions, we just log the problem and return
# some standard text.
try:
page_spec = " (page: '%s')" % self.formatter.page.page_name
except:
page_spec = ""
logging.exception("Macro %s%s raised an exception:" % (self.name, page_spec))
_ = self.request.getText
return self.formatter.text(
_("<<%(macro_name)s: execution failed [%(error_msg)s] (see also the log)>>")
% {
"macro_name": self.name,
"error_msg": err.args[0], # note: str(err) or unicode(err) does not work for py2.4/5/6
}
)
import traceback
logging.info("Stack:\n" + traceback.format_stack())
示例4: get_dependencies
def get_dependencies(self, macro_name):
if macro_name in self.Dependencies:
return self.Dependencies[macro_name]
try:
return wikiutil.importPlugin(self.request.cfg, "macro", macro_name, "Dependencies")
except wikiutil.PluginError:
return self.defaultDependency
示例5: _handle_submission
def _handle_submission(request):
""" Handle GET and POST requests of preferences forms.
Return error msg_class, msg tuple or None, None.
"""
_ = request.getText
sub = request.form.get('handler', [None])[0]
if sub in request.cfg.userprefs_disabled:
return None, None
try:
cls = wikiutil.importPlugin(request.cfg, 'userprefs', sub, 'Settings')
except wikiutil.PluginMissingError:
# we never show this plugin to click on so no need to
# give a message here
return None, None
obj = cls(request)
if not obj.allowed():
return None, None
res = obj.handle_form()
if isinstance(res, tuple):
return res
# backward compatibility for userprefs plugins,
# they just get 'dialog'-style messages.
return None, res
示例6: execute
def execute(pagename, request):
macro_action = wikiutil.importPlugin(request.cfg, "macro", pagename, "action_" + pagename)
result = macro_action(request)
request.write(result)
request.close()
示例7: execute
def execute(pagename, request):
# Strip non-ascii chars in header
pagename_header = '%s.csv' % (pagename)
pagename_header = pagename_header.encode('ascii', 'ignore')
request.content_type = 'text/csv; charset=UTF-8'
request.headers['Content-Disposition'] = \
'attachment; filename="%s"' % pagename_header
GetMeta = wikiutil.importPlugin(request.cfg, 'xmlrpc', 'GetMeta', 'do_action')
form = values_to_form(request.values)
try:
args = form['args'][0]
except (KeyError, IndexError):
args = u''
table = GetMeta(request, args, keysonly=False)
table = getmeta_to_table(table)
if 0:
print '--', table, '--'
print 'args', args
print 'pagename', pagename
writer = csv.writer(request, delimiter=';')
for row in table:
writer.writerow(map(encode_page, row))
示例8: execute
def execute(pagename, request):
enter_page(request, pagename, "Group Editor")
macro = wikiutil.importPlugin(request.cfg, "macro", "GroupEditor", "do_macro")
request.write(macro(request))
page = Page(request, pagename)
request.write(page.link_to(request, text=request.getText("back")))
exit_page(request, pagename)
示例9: send_page_content
def send_page_content(self, request, notparser, body, format_args='',
do_cache=0, **kw):
self.parser = importPlugin(request.cfg, "parser",
'link_collect', "Parser")
kw['format_args'] = format_args
kw['do_cache'] = 0
apply(Page.send_page_content, (self, request, self.parser, body), kw)
示例10: createParser
def createParser(self, format, text):
if format == "wiki":
format = "text_moin_wiki"
try:
Parser = wikiutil.importPlugin(self.request.cfg, "parser", format, "Parser")
except wikiutil.PluginMissingError:
from MoinMoin.parser.text import Parser
parser = Parser(text, self.request)
return parser
示例11: format
def format(self, formatter):
if len(self.args) <= 0:
from MoinMoin.wikiutil import importPlugin
sqlparser = importPlugin(self.request.cfg, 'parser', 'sql', 'Parser')
sqlparser(self.query, self.request).format(formatter)
else:
try:
self.validate()
self.__run_n_format(formatter)
except Exception as inst:
from MoinMoin.wikiutil import importPlugin
sqlparser = importPlugin(self.request.cfg, 'parser', 'sql', 'Parser')
sqlparser(self.query, self.request).format(formatter)
self.request.write(u'<pre>%s</pre>' % str(inst))
import traceback, sys
traceback.print_exc(file=sys.stdout)
示例12: get_dependencies
def get_dependencies(self, macro_name):
if self.Dependencies.has_key(macro_name):
return self.Dependencies[macro_name]
result = wikiutil.importPlugin(self.request.cfg, 'macro', macro_name,
'Dependencies')
if result != None:
return result
else:
return ["time"]
示例13: processor
def processor(self, processor_name, lines, is_parser=0):
""" processor_name MUST be valid!
writes out the result instead of returning it!
"""
if not is_parser:
processor = wikiutil.importPlugin(self.request.cfg, "processor",
processor_name, "process")
processor(self.request, self, lines)
else:
parser = wikiutil.importPlugin(self.request.cfg, "parser",
processor_name, "Parser")
args = self._get_bang_args(lines[0])
if args is not None:
lines = lines[1:]
p = parser('\n'.join(lines), self.request, format_args=args)
p.format(self)
del p
return ''
示例14: testSyntaxReferenceDomXml
def testSyntaxReferenceDomXml(self):
f_name = 'dom_xml'
try:
formatter = wikiutil.importPlugin(self.request.cfg, "formatter", f_name, "Formatter")
except wikiutil.PluginAttributeError:
pass
else:
print "Formatting using %r" % formatter
self.formatPage("SyntaxReference", formatter)
print "Done."
示例15: getHandler
def getHandler(request, action, identifier="execute"):
# check for excluded actions
if action in request.cfg.excluded_actions:
return None
handler = wikiutil.importPlugin(request.cfg, "action", action, identifier)
if handler is None:
handler = globals().get('do_' + action)
return handler