This repository was archived by the owner on Dec 15, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathpython.py
64 lines (59 loc) · 2.39 KB
/
python.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# Console Jabber Client
# Copyright (C) 2004-2010 Jacek Konieczny
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 as published
# by the Free Software Foundation
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
import os
from cjc.plugin import PluginBase
from cjc import ui
class Plugin(PluginBase):
def __init__(self,app,name):
PluginBase.__init__(self,app,name)
ui.activate_cmdtable("python",self)
def cmd_python(self,args):
code=args.all()
if not code or not code.strip():
self.error("Python code must be given")
return
vars={"app":self.cjc,"cjc":self.cjc,
"debug":self.debug,
"info":self.info,
"warning":self.warning,
"error":self.error}
try:
try:
r=eval(code,vars,vars)
except SyntaxError:
r=None
exec code in vars
except:
self.logger.exception("Exception caught in /python code")
return
if r is not None:
self.info(repr(r))
ui.CommandTable("python",50,(
ui.Command("python",Plugin.cmd_python,
"/python code|expression",
"Executes given python code or expression.\n"
"In the code's namespace following names are defined:\n"
" cjc -- CJC Application object.\n"
" debug(str,args) -- Passes str%args to debug output.\n"
" info(str,args) -- Prints str%args as an info message to the status window.\n"
" warning(str,args) -- Prints str%args as a warning message to the status window.\n"
" error(str,args) -- Prints str%args as an error message to the status window.\n"
"If expression is given and evaluates to not None then"
" it's result will be printed."
" '/python expression' is equivalent to '/python info(expression)'",
("opaque",)),
)).install()
# vi: sts=4 et sw=4