_DEFAULT_MASTER()
click to toggle source
def self._DEFAULT_MASTER
if @flag
@flag = nil
@@DEFAULT_MASTER
else
nil
end
end
_IP_TABLE()
click to toggle source
def self._IP_TABLE; @@IP_TABLE; end
_TK_TABLE_LIST()
click to toggle source
def self._TK_TABLE_LIST; @@TK_TABLE_LIST; end
__getip()
click to toggle source
def self.__getip
current = Thread.current
if current.kind_of?(@@CALLBACK_SUBTHREAD)
return current[:callback_ip]
end
if TclTkLib.mainloop_thread? != false && current[:callback_ip]
return current[:callback_ip]
end
if current.group == ThreadGroup::Default
@@DEFAULT_MASTER
else
ip = @@IP_TABLE[current.group]
unless ip
fail SecurityError,
"cannot call Tk methods on #{Thread.current.inspect}"
end
ip
end
end
__init_ip_env__(table, script)
click to toggle source
def self.__init_ip_env__(table, script)
ret = []
mtx = (Thread.current[:MultiTk_ip_Mutex] ||= Mutex.new)
cond = (Thread.current[:MultiTk_ip_CondVar] ||= ConditionVariable.new)
mtx.synchronize{
@init_ip_env_queue.enq([mtx, cond, ret, table, script])
cond.wait(mtx)
}
if ret[0].kind_of?(Exception)
raise ret[0]
else
ret[0]
end
end
__pseudo_toplevel()
click to toggle source
def self.__pseudo_toplevel
Thread.current.group == ThreadGroup::Default &&
MultiTkIp.__getip == @@DEFAULT_MASTER &&
self.__pseudo_toplevel_evaluable? && @pseudo_toplevel[1]
end
__pseudo_toplevel=(m)
click to toggle source
def self.__pseudo_toplevel=(m)
unless (Thread.current.group == ThreadGroup::Default &&
MultiTkIp.__getip == @@DEFAULT_MASTER)
fail SecurityError, "no permission to manipulate"
end
if m.respond_to?(:pseudo_toplevel_evaluable?)
@pseudo_toplevel[0] = true
@pseudo_toplevel[1] = m
else
fail ArgumentError, 'fail to set pseudo-toplevel'
end
self
end
__pseudo_toplevel_evaluable=(mode)
click to toggle source
def self.__pseudo_toplevel_evaluable=(mode)
unless (Thread.current.group == ThreadGroup::Default &&
MultiTkIp.__getip == @@DEFAULT_MASTER)
fail SecurityError, "no permission to manipulate"
end
@pseudo_toplevel[0] = (mode)? true: false
end
__pseudo_toplevel_evaluable?()
click to toggle source
def self.__pseudo_toplevel_evaluable?
begin
@pseudo_toplevel[0] && @pseudo_toplevel[1].pseudo_toplevel_evaluable?
rescue Exception
false
end
end
_conv_listelement(arg)
click to toggle source
def _conv_listelement(arg)
__getip._conv_listelement(arg)
end
_create_console()
click to toggle source
def _create_console
__getip._create_console
end
_eval(str)
click to toggle source
def _eval(str)
__getip._eval(str)
end
_eval_with_enc(str)
click to toggle source
def _eval_with_enc(str)
__getip._eval_with_enc(str)
end
_eval_without_enc(str)
click to toggle source
def _eval_without_enc(str)
__getip._eval_without_enc(str)
end
_fromUTF8(str, encoding=nil)
click to toggle source
def _fromUTF8(str, encoding=nil)
__getip._fromUTF8(str, encoding)
end
_get_global_var(var)
click to toggle source
def _get_global_var(var)
__getip._get_global_var(var)
end
_get_global_var2(var, idx)
click to toggle source
def _get_global_var2(var, idx)
__getip._get_global_var2(var, idx)
end
_get_variable(var, flag)
click to toggle source
def _get_variable(var, flag)
__getip._get_variable(var, flag)
end
_get_variable2(var, idx, flag)
click to toggle source
def _get_variable2(var, idx, flag)
__getip._get_variable2(var, idx, flag)
end
_invoke(*args)
click to toggle source
def _invoke(*args)
__getip._invoke(*args)
end
_invoke_with_enc(*args)
click to toggle source
def _invoke_with_enc(*args)
__getip._invoke_with_enc(*args)
end
_invoke_without_enc(*args)
click to toggle source
def _invoke_without_enc(*args)
__getip._invoke_without_enc(*args)
end
_ip_id_()
click to toggle source
def self._ip_id_
__getip._ip_id_
end
_merge_tklist(*args)
click to toggle source
def _merge_tklist(*args)
__getip._merge_tklist(*args)
end
_proc_on_current_safelevel(cmd=nil, &blk)
click to toggle source
def MultiTkIp._proc_on_current_safelevel(cmd=nil, &blk)
MultiTkIp.__getip._proc_on_current_safelevel(cmd, &blk)
end
_proc_on_safelevel(cmd=nil, &blk)
click to toggle source
def MultiTkIp._proc_on_safelevel(cmd=nil, &blk)
MultiTkIp.__getip._proc_on_safelevel(cmd, &blk)
end
_return_value()
click to toggle source
def _return_value
__getip._return_value
end
_set_global_var(var, value)
click to toggle source
def _set_global_var(var, value)
__getip._set_global_var(var, value)
end
_set_global_var2(var, idx, value)
click to toggle source
def _set_global_var2(var, idx, value)
__getip._set_global_var2(var, idx, value)
end
_set_variable(var, value, flag)
click to toggle source
def _set_variable(var, value, flag)
__getip._set_variable(var, value, flag)
end
_set_variable2(var, idx, value, flag)
click to toggle source
def _set_variable2(var, idx, value, flag)
__getip._set_variable2(var, idx, value, flag)
end
_split_tklist(str)
click to toggle source
def _split_tklist(str)
__getip._split_tklist(str)
end
_thread_tkwait(mode, target)
click to toggle source
def _thread_tkwait(mode, target)
__getip._thread_tkwait(mode, target)
end
_thread_vwait(var)
click to toggle source
def _thread_vwait(var)
__getip._thread_vwait(var)
end
_toUTF8(str, encoding=nil)
click to toggle source
def _toUTF8(str, encoding=nil)
__getip._toUTF8(str, encoding)
end
_unset_global_var(var)
click to toggle source
def _unset_global_var(var)
__getip._unset_global_var(var)
end
_unset_global_var2(var, idx)
click to toggle source
def _unset_global_var2(var, idx)
__getip._unset_global_var2(var, idx)
end
_unset_variable(var, flag)
click to toggle source
def _unset_variable(var, flag)
__getip._unset_variable(var, flag)
end
_unset_variable2(var, idx, flag)
click to toggle source
def _unset_variable2(var, idx, flag)
__getip._unset_variable2(var, idx, flag)
end
abort(msg = nil)
click to toggle source
def abort(msg = nil)
__getip.abort(msg)
end
add_tk_procs(name, args=nil, body=nil)
click to toggle source
def self.add_tk_procs(name, args=nil, body=nil)
if name.kind_of?(Array)
name.each{|param| self.add_tk_procs(*param)}
else
name = name.to_s
@@ADD_TK_PROCS << [name, args, body]
@@IP_TABLE.each{|tg, ip|
ip._add_tk_procs(name, args, body)
}
end
end
alias_delete(slave, cmd_name)
click to toggle source
def self.alias_delete(slave, cmd_name)
__getip.alias_delete(slave, cmd_name)
self
end
alias_info(slave, cmd_name)
click to toggle source
def self.alias_info(slave, cmd_name)
__getip.alias_info(slave, cmd_name)
end
alias_target(aliascmd, slave = '')
click to toggle source
def self.alias_target(aliascmd, slave = '')
__getip.alias_target(aliascmd, slave)
end
aliases(slave = '')
click to toggle source
def self.aliases(slave = '')
__getip.aliases(slave)
end
alive?()
click to toggle source
def self.alive?
__getip.alive?
end
allow_ruby_exit=(mode)
click to toggle source
def allow_ruby_exit= (mode)
__getip.allow_ruby_exit = mode
end
allow_ruby_exit?()
click to toggle source
def allow_ruby_exit?
__getip.allow_ruby_exit?
end
assign_receiver_and_watchdog(target)
click to toggle source
def self.assign_receiver_and_watchdog(target)
ret = [nil]
@assign_thread.raise(@assign_request.new(target, ret))
while ret[0] == nil
unless @assign_thread.alive?
raise RuntimeError, 'lost the thread to assign a receiver and a watchdog thread'
end
end
if ret[0].kind_of?(Exception)
raise ret[0]
else
ret[0]
end
end
background_call(*args, &blk)
click to toggle source
background_eval(*args, &blk)
click to toggle source
background_eval_proc(*args, &blk)
click to toggle source
background_eval_str(cmd, *eval_args)
click to toggle source
background_eval_string(cmd, *eval_args)
click to toggle source
bg_call(*args, &blk)
click to toggle source
bg_eval(*args, &blk)
click to toggle source
def bg_eval(*args, &blk)
__getip.bg_eval(*args, &blk)
end
bg_eval_proc(*args, &blk)
click to toggle source
def bg_eval_proc(*args, &blk)
__getip.bg_eval_proc(*args, &blk)
end
bg_eval_str(cmd, *eval_args)
click to toggle source
bg_eval_string(cmd, *eval_args)
click to toggle source
def bg_eval_string(cmd, *eval_args)
__getip.bg_eval_string(cmd, *eval_args)
end
bgerror(cmd = Proc.new, slave = nil, &b)
click to toggle source
def self.bgerror(cmd = Proc.new, slave = nil, &b)
__getip.bgerror(cmd, slave, &b)
end
call(*args, &blk)
click to toggle source
cb_entry_class()
click to toggle source
def self.cb_entry_class
@@CB_ENTRY_CLASS
end
cb_eval(cmd, *args)
click to toggle source
def INTERP.cb_eval(cmd, *args)
TkUtil._get_eval_string(TkUtil.eval_cmd(cmd, *args))
end
create_table()
click to toggle source
def self.create_table
if __getip.slave?
begin
raise SecurityError, "slave-IP has no permission creating a new table"
rescue SecurityError => e
caller_info = e.backtrace[1]
if caller_info =~ %r{^#{MultiTkIp::BASE_DIR}/(tk|tkextlib)/[^:]+\.rb:}
else
raise e
end
end
end
id = @@TK_TABLE_LIST.size
obj = Object.new
@@TK_TABLE_LIST << obj
obj.instance_variable_set(:@id, id)
obj.instance_variable_set(:@mutex, Mutex.new)
obj.instance_eval{
def self.mutex
@mutex
end
def self.method_missing(m, *args)
MultiTkIp.tk_object_table(@id).__send__(m, *args)
end
}
obj.freeze
@@IP_TABLE.each{|tg, ip| ip._add_new_tables }
return obj
end
def_alias(slave, new_cmd, org_cmd, *args)
click to toggle source
def self.def_alias(slave, new_cmd, org_cmd, *args)
ret = __getip.def_alias(slave, new_cmd, org_cmd, *args)
(ret == new_cmd)? self: nil
end
default_encoding()
click to toggle source
default_encoding=(enc)
click to toggle source
def default_encoding=(enc)
__getip.default_encoding=(enc)
end
default_master?()
click to toggle source
def self.default_master?
__getip == @@DEFAULT_MASTER
end
delete()
click to toggle source
def delete
__getip.delete
end
delete_cmd(slave, cmd)
click to toggle source
def self.delete_cmd(slave, cmd)
__getip.delete_cmd(slave, cmd)
self
end
delete_slaves(*args)
click to toggle source
def self.delete_slaves(*args)
__getip.delete_slaves(*args)
self
end
deleted?()
click to toggle source
def deleted?
__getip.deleted?
end
do_one_event(flag = TclTkLib::EventFlag::ALL)
click to toggle source
def do_one_event(flag = TclTkLib::EventFlag::ALL)
__getip.do_one_event(flag)
end
encoding()
click to toggle source
encoding=(enc)
click to toggle source
def encoding=(enc)
__getip.encoding=(enc)
end
encoding_convert_from(str, enc=None)
click to toggle source
encoding_convert_to(str, enc=None)
click to toggle source
encoding_convertfrom(str, enc=None)
click to toggle source
def encoding_convertfrom(str, enc=None)
__getip.encoding_convertfrom(str, enc)
end
encoding_convertto(str, enc=None)
click to toggle source
def encoding_convertto(str, enc=None)
__getip.encoding_convertto(str, enc)
end
encoding_name()
click to toggle source
def encoding_name
__getip.encoding_name
end
encoding_obj()
click to toggle source
def encoding_obj
__getip.encoding_obj
end
encoding_table()
click to toggle source
def encoding_table
__getip.encoding_table
end
eval(*args, &blk)
click to toggle source
def eval(*args, &blk)
__getip.eval(*args, &blk)
end
eval_proc(*args, &blk)
click to toggle source
class method
def eval_proc(*args, &blk)
__getip.eval_proc(*args, &blk)
end
eval_str(cmd, *eval_args)
click to toggle source
eval_string(cmd, *eval_args)
click to toggle source
def eval_string(cmd, *eval_args)
__getip.eval_string(cmd, *eval_args)
end
exist?(slave = '')
click to toggle source
def self.exist?(slave = '')
__getip.exist?(slave)
end
exit(st = true)
click to toggle source
def exit(st = true)
__getip.exit(st)
end
exit!(st = false)
click to toggle source
def exit!(st = false)
__getip.exit!(st)
end
expose_cmd(slave, cmd, aliasname = nil)
click to toggle source
def self.expose_cmd(slave, cmd, aliasname = nil)
__getip.expose_cmd(slave, cmd, aliasname)
self
end
force_default_encoding=(mode)
click to toggle source
def force_default_encoding=(mode)
__getip.force_default_encoding=(mode)
end
force_default_encoding?()
click to toggle source
def force_default_encoding?
__getip.force_default_encoding?
end
get_cb_entry(cmd)
click to toggle source
def self.get_cb_entry(cmd)
@@CB_ENTRY_CLASS.new(__getip, cmd).freeze
end
get_eventloop_tick()
click to toggle source
def get_eventloop_tick
__getip.get_eventloop_tick
end
get_eventloop_weight()
click to toggle source
def get_eventloop_weight
__getip.get_eventloop_weight
end
get_limit(limit_type, slave = '', slot = nil)
click to toggle source
def self.get_limit(limit_type, slave = '', slot = nil)
__getip.get_limit(limit_type, slave, slot)
end
get_no_event_wait()
click to toggle source
def get_no_event_wait
__getip.get_no_event_wait
end
has_mainwindow?()
click to toggle source
def has_mainwindow?
__getip.has_mainwindow?
end
hidden_cmds(slave = '')
click to toggle source
def self.hidden_cmds(slave = '')
__getip.hidden_cmds(slave)
end
hide_cmd(slave, cmd, aliasname = nil)
click to toggle source
def self.hide_cmd(slave, cmd, aliasname = nil)
__getip.hide_cmd(slave, cmd, aliasname)
self
end
inherited(subclass)
click to toggle source
def self.inherited(subclass)
if @@IP_TABLE[Thread.current.group] == @@DEFAULT_MASTER
begin
class << subclass
self.methods.each{|m|
name = m.to_s
begin
unless name == '__id__' || name == '__send__' || name == 'freeze'
undef_method(m)
end
rescue Exception
end
}
end
ensure
subclass.freeze
fail SecurityError,
"cannot create subclass of MultiTkIp on a untrusted ThreadGroup"
end
end
end
init_ip_env(script = Proc.new)
click to toggle source
def self.init_ip_env(script = Proc.new)
@@INIT_IP_ENV << script
if __getip.slave?
begin
raise SecurityError, "slave-IP has no permission initializing IP env"
rescue SecurityError => e
caller_info = e.backtrace[1]
if caller_info =~ %r{^#{MultiTkIp::BASE_DIR}/(tk|tkextlib)/[^:]+\.rb:}
else
raise e
end
end
end
@@DEFAULT_MASTER.__init_ip_env__(@@IP_TABLE, script)
end
init_ip_internal()
click to toggle source
def self.init_ip_internal
__getip._init_ip_internal(@@INIT_IP_ENV, @@ADD_TK_PROCS)
end
invalid_namespace?()
click to toggle source
def invalid_namespace?
__getip.invalid_namespace?
end
invoke_hidden(slave, cmd, *args)
click to toggle source
def self.invoke_hidden(slave, cmd, *args)
__getip.invoke_hidden(slave, cmd, *args)
end
invoke_hidden_on_global(slave, cmd, *args)
click to toggle source
def self.invoke_hidden_on_global(slave, cmd, *args)
__getip.invoke_hidden_on_global(slave, cmd, *args)
end
invoke_hidden_on_namespace(slave, ns, cmd, *args)
click to toggle source
def self.invoke_hidden_on_namespace(slave, ns, cmd, *args)
__getip.invoke_hidden_on_namespace(slave, ns, cmd, *args)
end
ip_name()
click to toggle source
def self.ip_name
__getip.ip_name
end
mainloop(check_root = true)
click to toggle source
def self.mainloop(check_root = true)
begin
TclTkLib.set_eventloop_window_mode(true)
@interp_thread.value
ensure
TclTkLib.set_eventloop_window_mode(false)
end
end
mainloop_abort_on_exception()
click to toggle source
def mainloop_abort_on_exception
TclTkLib.mainloop_abort_on_exception
end
mainloop_abort_on_exception=(mode)
click to toggle source
def mainloop_abort_on_exception=(mode)
TclTkLib.mainloop_abort_on_exception=(mode)
end
mainloop_watchdog(check_root = true)
click to toggle source
def mainloop_watchdog(check_root = true)
__getip.mainloop_watchdog(check_root)
end
make_safe()
click to toggle source
def make_safe
__getip.make_safe
end
manipulable?()
click to toggle source
def self.manipulable?
true
end
mark_trusted(slave = '')
click to toggle source
def self.mark_trusted(slave = '')
__getip.mark_trusted(slave)
self
end
master?()
click to toggle source
def self.master?
__getip.master?
end
method_missing(m, *args)
click to toggle source
def self.method_missing(m, *args)
MultiTkIp.tk_object_table(@id).__send__(m, *args)
end
mutex()
click to toggle source
def self.mutex
@mutex
end
new(ip, cmd)
click to toggle source
def initialize(ip, cmd)
@ip = ip
@safe = safe = $SAFE
cmd = MultiTkIp._proc_on_safelevel(&cmd)
@cmd = proc{|*args| cmd.call(safe, *args)}
self.freeze
end
new(target, ret)
click to toggle source
def self.new(target, ret)
obj = super()
obj.target = target
obj.ret = ret
obj
end
new_master(safe=nil, keys={}, &blk)
click to toggle source
def new_master(safe=nil, keys={}, &blk)
if MultiTkIp::WITH_RUBY_VM
fail RuntimeError,
'sorry, still not support multiple master-interpreters on RubyVM'
end
if safe.kind_of?(Hash)
keys = safe
elsif safe.kind_of?(Integer)
raise ArgumentError, "unexpected argument(s)" unless keys.kind_of?(Hash)
if !keys.key?(:safe) && !keys.key?('safe')
keys[:safe] = safe
end
elsif safe == nil
else
raise ArgumentError, "unexpected argument(s)"
end
ip = __new(__getip, nil, keys)
if block_given?
ip._proc_on_safelevel(&blk).call(ip.safe_level)
end
ip
end
Also aliased as: new
new_safeTk(safe=4, keys={}, &blk)
click to toggle source
new_safe_slave(safe=4, keys={}, &blk)
click to toggle source
def new_safe_slave(safe=4, keys={}, &blk)
if safe.kind_of?(Hash)
keys = safe
elsif safe.kind_of?(Integer)
raise ArgumentError, "unexpected argument(s)" unless keys.kind_of?(Hash)
if !keys.key?(:safe) && !keys.key?('safe')
keys[:safe] = safe
end
else
raise ArgumentError, "unexpected argument(s)"
end
ip = __new(__getip, true, keys)
if block_given?
ip._proc_on_safelevel(&blk).call(ip.safe_level)
end
ip
end
new_slave(safe=nil, keys={}, &blk)
click to toggle source
def new_slave(safe=nil, keys={}, &blk)
if safe.kind_of?(Hash)
keys = safe
elsif safe.kind_of?(Integer)
raise ArgumentError, "unexpected argument(s)" unless keys.kind_of?(Hash)
if !keys.key?(:safe) && !keys.key?('safe')
keys[:safe] = safe
end
elsif safe == nil
else
raise ArgumentError, "unexpected argument(s)"
end
ip = __new(__getip, false, keys)
if block_given?
ip._proc_on_safelevel(&blk).call(ip.safe_level)
end
ip
end
new_trusted_slave(safe=nil, keys={}, &blk)
click to toggle source
path()
click to toggle source
def self.path
__getip.path
end
recursion_limit(slave = '', limit = None)
click to toggle source
def self.recursion_limit(slave = '', limit = None)
__getip.recursion_limit(slave)
end
remove_tk_procs(*names)
click to toggle source
def self.remove_tk_procs(*names)
names.each{|name|
name = name.to_s
@@ADD_TK_PROCS.delete_if{|elem|
elem.kind_of?(Array) && elem[0].to_s == name
}
}
@@IP_TABLE.each{|tg, ip|
ip._remove_tk_procs(*names)
}
end
restart(app_name = nil, keys = {})
click to toggle source
def restart(app_name = nil, keys = {})
init_ip_internal
__getip._invoke('set', 'argv0', app_name) if app_name
if keys.kind_of?(Hash)
__getip._invoke('set', 'argv', _keys2opts(keys))
end
__getip.restart
end
safe?()
click to toggle source
def safe?
__getip.safe?
end
safe_base?()
click to toggle source
def safe_base?
begin
__getip.safe_base?
rescue
false
end
end
safe_level()
click to toggle source
def self.safe_level
__getip.safe_level
end
safe_level=(safe)
click to toggle source
def self.safe_level=(safe)
self.set_safe_level(safe)
end
set_eventloop_tick(tick)
click to toggle source
def set_eventloop_tick(tick)
__getip.set_eventloop_tick(tick)
end
set_eventloop_weight(loop_max, no_event_tick)
click to toggle source
def set_eventloop_weight(loop_max, no_event_tick)
__getip.set_eventloop_weight(loop_max, no_event_tick)
end
set_limit(limit_type, slave = '', opts = {})
click to toggle source
def self.set_limit(limit_type, slave = '', opts = {})
__getip.set_limit(limit_type, slave, opts)
end
set_no_event_wait(tick)
click to toggle source
def set_no_event_wait(tick)
__getip.set_no_event_wait(tick)
end
set_safe_level(safe)
click to toggle source
def self.set_safe_level(safe)
__getip.set_safe_level(safe)
end
share_stderr(dist, src = '')
click to toggle source
def self.share_stderr(dist, src = '')
__getip.share_stderr(dist, src)
self
end
share_stdin(dist, src = '')
click to toggle source
def self.share_stdin(dist, src = '')
__getip.share_stdin(dist, src)
self
end
share_stdio(dist, src = '')
click to toggle source
def self.share_stdio(dist, src = '')
__getip.share_stdio(dist, src)
self
end
share_stdout(dist, src = '')
click to toggle source
def self.share_stdout(dist, src = '')
__getip.share_stdout(dist, src)
self
end
slave?()
click to toggle source
def self.slave?
not self.master?
end
slaves(all = false)
click to toggle source
def self.slaves(all = false)
__getip.slaves(all)
end
table()
click to toggle source
def self.table
@table
end
thread_eval_proc(*args, &blk)
click to toggle source
tk_cmd_tbl()
click to toggle source
def self.tk_cmd_tbl
@@TK_CMD_TBL
end
tk_object_table(id)
click to toggle source
def self.tk_object_table(id)
__getip._tk_table_list[id]
end
tk_windows()
click to toggle source
def self.tk_windows
__getip._tk_windows
end
to_eval()
click to toggle source
def self.to_eval
__getip.to_eval
end
transfer_stderr(dist, src = '')
click to toggle source
def self.transfer_stderr(dist, src = '')
__getip.transfer_stderr(dist, src)
self
end
transfer_stdin(dist, src = '')
click to toggle source
def self.transfer_stdin(dist, src = '')
__getip.transfer_stdin(dist, src)
self
end
transfer_stdio(dist, src = '')
click to toggle source
def self.transfer_stdio(dist, src = '')
__getip.transfer_stdio(dist, src)
self
end
transfer_stdout(dist, src = '')
click to toggle source
def self.transfer_stdout(dist, src = '')
__getip.transfer_stdout(dist, src)
self
end
__create_safe_slave_obj(safe_opts, app_name, tk_opts)
click to toggle source
def __create_safe_slave_obj(safe_opts, app_name, tk_opts)
raise SecurityError, "no permission to manipulate" unless self.manipulable?
ip_name = _create_slave_ip_name
slave_ip = @interp.create_slave(ip_name, true)
slave_ip.instance_eval{
@force_default_encoding ||= TkUtil.untrust([false])
@encoding ||= TkUtil.untrust([nil])
def @encoding.to_s; self.join(nil); end
}
@slave_ip_tbl[ip_name] = slave_ip
def slave_ip.safe_base?
true
end
@interp._eval("::safe::interpInit #{ip_name}")
slave_ip._invoke('set', 'argv0', app_name) if app_name.kind_of?(String)
if tk_opts
tk_opts = __check_safetk_optkeys(tk_opts)
if tk_opts.key?('use')
@slave_ip_top[ip_name] = ''
else
tk_opts, top_path = __create_safetk_frame(slave_ip, ip_name, app_name,
tk_opts)
@slave_ip_top[ip_name] = top_path
end
@interp._eval("::safe::loadTk #{ip_name} #{_keys2opts(tk_opts)}")
@interp._invoke('__replace_slave_tk_commands__', ip_name)
else
@slave_ip_top[ip_name] = nil
end
if safe_opts.key?('deleteHook') || safe_opts.key?(:deleteHook)
@interp._eval("::safe::interpConfigure #{ip_name} " +
_keys2opts(safe_opts))
else
@interp._eval("::safe::interpConfigure #{ip_name} " +
_keys2opts(safe_opts) + '-deleteHook {' +
TkComm._get_eval_string(proc{|slave|
self._default_delete_hook(slave)
}) + '}')
end
[slave_ip, ip_name]
end
__create_trusted_slave_obj(name, keys)
click to toggle source
def __create_trusted_slave_obj(name, keys)
raise SecurityError, "no permission to manipulate" unless self.manipulable?
ip_name = _create_slave_ip_name
slave_ip = @interp.create_slave(ip_name, false)
slave_ip.instance_eval{
@force_default_encoding ||= TkUtil.untrust([false])
@encoding ||= TkUtil.untrust([nil])
def @encoding.to_s; self.join(nil); end
}
slave_ip._invoke('set', 'argv0', name) if name.kind_of?(String)
slave_ip._invoke('set', 'argv', _keys2opts(keys))
@interp._invoke('load', '', 'Tk', ip_name)
@interp._invoke('__replace_slave_tk_commands__', ip_name)
@slave_ip_tbl[ip_name] = slave_ip
[slave_ip, ip_name]
end
__eval(str)
click to toggle source
def __eval(str)
raise SecurityError, "no permission to manipulate" unless self.manipulable?
@interp.__eval(str)
end
__invoke(*args)
click to toggle source
def __invoke(*args)
raise SecurityError, "no permission to manipulate" unless self.manipulable?
@interp.__invoke(*args)
end
__pseudo_toplevel()
click to toggle source
instance method
def __pseudo_toplevel
ip = MultiTkIp.__getip
(ip == @@DEFAULT_MASTER || ip == self) &&
self.__pseudo_toplevel_evaluable? && @pseudo_toplevel[1]
end
__pseudo_toplevel=(m)
click to toggle source
def __pseudo_toplevel=(m)
unless (Thread.current.group == ThreadGroup::Default &&
MultiTkIp.__getip == @@DEFAULT_MASTER)
fail SecurityError, "no permission to manipulate"
end
if m.respond_to?(:pseudo_toplevel_evaluable?)
@pseudo_toplevel[0] = true
@pseudo_toplevel[1] = m
else
fail ArgumentError, 'fail to set pseudo-toplevel'
end
self
end
__pseudo_toplevel_evaluable=(mode)
click to toggle source
def __pseudo_toplevel_evaluable=(mode)
unless (Thread.current.group == ThreadGroup::Default &&
MultiTkIp.__getip == @@DEFAULT_MASTER)
fail SecurityError, "no permission to manipulate"
end
@pseudo_toplevel[0] = (mode)? true: false
end
__pseudo_toplevel_evaluable?()
click to toggle source
def __pseudo_toplevel_evaluable?
begin
@pseudo_toplevel[0] && @pseudo_toplevel[1].pseudo_toplevel_evaluable?
rescue Exception
false
end
end
_add_new_tables()
click to toggle source
def _add_new_tables
(@@TK_TABLE_LIST.size - @tk_table_list.size).times{
@tk_table_list << TkUtil.untrust({})
}
end
_add_tk_procs(name, args, body)
click to toggle source
def _add_tk_procs(name, args, body)
return if slave?
@interp._invoke('proc', name, args, body) if args && body
@interp._invoke('interp', 'slaves').split.each{|slave|
@interp._invoke('interp', 'alias', slave, name, '', name)
}
end
_conv_listelement(arg)
click to toggle source
def _conv_listelement(arg)
raise SecurityError, "no permission to manipulate" unless self.manipulable?
@interp._conv_listelement(arg)
end
_create_slave_object(keys={})
click to toggle source
def _create_slave_object(keys={})
raise SecurityError, "no permission to manipulate" unless self.manipulable?
ip = MultiTkIp.new_slave(self, keys={})
@slave_ip_tbl[ip.name] = ip
end
_default_delete_hook(slave)
click to toggle source
def _default_delete_hook(slave)
raise SecurityError, "no permission to manipulate" unless self.manipulable?
@slave_ip_tbl.delete(slave)
top = @slave_ip_top.delete(slave)
if top.kind_of?(String)
if top == ''
begin
@interp._eval("::safe::disallowTk #{slave}")
rescue
warn("Warning: fail to call '::safe::disallowTk'") if $DEBUG
end
else
begin
@interp._eval("::safe::tkDelete {} #{top} #{slave}")
rescue
warn("Warning: fail to call '::safe::tkDelete'") if $DEBUG
begin
@interp._eval("destroy #{top}")
rescue
warn("Warning: fail to destroy toplevel") if $DEBUG
end
end
end
end
end
_destroy_slaves_of_slaveIP(ip)
click to toggle source
def _destroy_slaves_of_slaveIP(ip)
unless ip.deleted?
ip._split_tklist(ip._invoke_without_enc('interp', 'slaves')).each{|name|
name = _fromUTF8(name)
begin
after_ids = ip._eval_without_enc("#{name} eval {after info}")
ip._eval_without_enc("#{name} eval {foreach i {#{after_ids}} {after cancel $i}}")
rescue Exception
end
begin
ip._invoke(name, 'eval', 'destroy', '.')
rescue Exception
end
if ip._eval_without_enc("catch {::safe::interpConfigure #{name}}") == '0'
begin
ip._eval_without_enc("::safe::interpDelete #{name}")
rescue Exception
end
end
unless ip.deleted?
if ip._invoke('interp', 'exists', name) == '1'
begin
ip._invoke('interp', 'delete', name)
rescue Exception
end
end
end
}
end
end
_eval(str)
click to toggle source
def _eval(str)
raise SecurityError, "no permission to manipulate" unless self.manipulable?
@interp._eval(str)
end
_eval_with_enc(str)
click to toggle source
def _eval_with_enc(str)
raise SecurityError, "no permission to manipulate" unless self.manipulable?
@interp._eval_with_enc(str)
end
_eval_without_enc(str)
click to toggle source
def _eval_without_enc(str)
raise SecurityError, "no permission to manipulate" unless self.manipulable?
@interp._eval_without_enc(str)
end
_fromUTF8(str, encoding=nil)
click to toggle source
def _fromUTF8(str, encoding=nil)
raise SecurityError, "no permission to manipulate" unless self.manipulable?
@interp._fromUTF8(str, encoding)
end
_get_global_var(var)
click to toggle source
def _get_global_var(var)
raise SecurityError, "no permission to manipulate" unless self.manipulable?
@interp._get_global_var(var)
end
_get_global_var2(var, idx)
click to toggle source
def _get_global_var2(var, idx)
raise SecurityError, "no permission to manipulate" unless self.manipulable?
@interp._get_global_var2(var, idx)
end
_get_variable(var, flag)
click to toggle source
def _get_variable(var, flag)
raise SecurityError, "no permission to manipulate" unless self.manipulable?
@interp._get_variable(var, flag)
end
_get_variable2(var, idx, flag)
click to toggle source
def _get_variable2(var, idx, flag)
raise SecurityError, "no permission to manipulate" unless self.manipulable?
@interp._get_variable2(var, idx, flag)
end
_init_ip_env(script)
click to toggle source
def _init_ip_env(script)
self.eval_proc{script.call(self)}
end
_init_ip_internal(init_ip_env, add_tk_procs)
click to toggle source
def _init_ip_internal(init_ip_env, add_tk_procs)
init_ip_env.each{|script| self._init_ip_env(script)}
add_tk_procs.each{|name, args, body|
if master?
@interp._invoke('proc', name, args, body) if args && body
else
@set_alias_proc.call(name)
end
}
end
_invoke(*args)
click to toggle source
def _invoke(*args)
raise SecurityError, "no permission to manipulate" unless self.manipulable?
@interp._invoke(*args)
end
_invoke_with_enc(*args)
click to toggle source
def _invoke_with_enc(*args)
raise SecurityError, "no permission to manipulate" unless self.manipulable?
@interp._invoke_with_enc(*args)
end
_invoke_without_enc(*args)
click to toggle source
def _invoke_without_enc(*args)
raise SecurityError, "no permission to manipulate" unless self.manipulable?
@interp._invoke_without_enc(*args)
end
_ip_id_()
click to toggle source
_merge_tklist(*args)
click to toggle source
def _merge_tklist(*args)
raise SecurityError, "no permission to manipulate" unless self.manipulable?
@interp._merge_tklist(*args)
end
_proc_on_current_safelevel(cmd=nil, &blk)
click to toggle source
def _proc_on_current_safelevel(cmd=nil, &blk)
safe = $SAFE
cmd = _proc_on_safelevel(cmd, &blk)
Proc.new{|*args| cmd.call(safe, *args)}
end
_proc_on_safelevel(cmd=nil)
click to toggle source
instance & class method
def _proc_on_safelevel(cmd=nil)
if cmd
if cmd.kind_of?(Method)
_proc_on_safelevel{|*args| cmd.call(*args)}
else
_proc_on_safelevel(&cmd)
end
else
Proc.new{|safe, *args|
untrust_proc = proc{|err|
begin
err.untrust if err.respond_to?(:untrust)
rescue SecurityError
end
err
}
$SAFE=safe if $SAFE < safe;
begin
yield(*args)
rescue Exception => e
fail untrust_proc.call(e)
end
}
end
end
_receiver_mainloop(check_root)
click to toggle source
def _receiver_mainloop(check_root)
if @evloop_thread[0] && @evloop_thread[0].alive?
@evloop_thread[0]
else
@evloop_thread[0] = Thread.new{
while !@interp.deleted?
break if check_root && !@interp.has_mainwindow?
sleep 0.5
end
}
@evloop_thread[0]
end
end
_remove_tk_procs(*names)
click to toggle source
def _remove_tk_procs(*names)
return if slave?
names.each{|name|
name = name.to_s
return if @interp.deleted?
@interp._invoke('rename', name, '')
return if @interp.deleted?
@interp._invoke('interp', 'slaves').split.each{|slave|
return if @interp.deleted?
@interp._invoke('interp', 'alias', slave, name, '') rescue nil
}
}
end
_return_value()
click to toggle source
def _return_value
raise SecurityError, "no permission to manipulate" unless self.manipulable?
@interp._return_value
end
_set_global_var(var, value)
click to toggle source
def _set_global_var(var, value)
raise SecurityError, "no permission to manipulate" unless self.manipulable?
@interp._set_global_var(var, value)
end
_set_global_var2(var, idx, value)
click to toggle source
def _set_global_var2(var, idx, value)
raise SecurityError, "no permission to manipulate" unless self.manipulable?
@interp._set_global_var2(var, idx, value)
end
_set_variable(var, value, flag)
click to toggle source
def _set_variable(var, value, flag)
raise SecurityError, "no permission to manipulate" unless self.manipulable?
@interp._set_variable(var, value, flag)
end
_set_variable2(var, idx, value, flag)
click to toggle source
def _set_variable2(var, idx, value, flag)
raise SecurityError, "no permission to manipulate" unless self.manipulable?
@interp._set_variable2(var, idx, value, flag)
end
_split_tklist(str)
click to toggle source
def _split_tklist(str)
raise SecurityError, "no permission to manipulate" unless self.manipulable?
@interp._split_tklist(str)
end
_thread_tkwait(mode, target)
click to toggle source
def _thread_tkwait(mode, target)
raise SecurityError, "no permission to manipulate" unless self.manipulable?
@interp._thread_tkwait(mode, target)
end
_thread_vwait(var)
click to toggle source
def _thread_vwait(var)
raise SecurityError, "no permission to manipulate" unless self.manipulable?
@interp._thread_vwait(var)
end
_tk_cmd_tbl()
click to toggle source
def _tk_cmd_tbl
tbl = {}
MultiTkIp.tk_cmd_tbl.each{|id, ent| tbl[id] = ent if ent.ip == self }
tbl
end
_tk_table_list()
click to toggle source
def _tk_table_list
@tk_table_list
end
_tk_windows()
click to toggle source
def _tk_windows
@tk_windows
end
_toUTF8(str, encoding=nil)
click to toggle source
def _toUTF8(str, encoding=nil)
raise SecurityError, "no permission to manipulate" unless self.manipulable?
@interp._toUTF8(str, encoding)
end
_unset_global_var(var)
click to toggle source
def _unset_global_var(var)
raise SecurityError, "no permission to manipulate" unless self.manipulable?
@interp._unset_global_var(var)
end
_unset_global_var2(var, idx)
click to toggle source
def _unset_global_var2(var, idx)
raise SecurityError, "no permission to manipulate" unless self.manipulable?
@interp._unset_global_var2(var, idx)
end
_unset_variable(var, flag)
click to toggle source
def _unset_variable(var, flag)
raise SecurityError, "no permission to manipulate" unless self.manipulable?
@interp._unset_variable(var, flag)
end
_unset_variable2(var, idx, flag)
click to toggle source
def _unset_variable2(var, idx, flag)
raise SecurityError, "no permission to manipulate" unless self.manipulable?
@interp._unset_variable2(var, idx, flag)
end
abort(msg = nil)
click to toggle source
def abort(msg = nil)
raise SecurityError, "no permission to manipulate" unless self.manipulable?
if master? && !safe? && allow_ruby_exit?
if msg
Kernel.abort(msg)
else
Kernel.abort
end
else
delete
1
end
end
alias_delete(slave, cmd_name)
click to toggle source
def alias_delete(slave, cmd_name)
raise SecurityError, "no permission to manipulate" unless self.manipulable?
@interp._invoke('interp', 'alias', _slavearg(slave), cmd_name, '')
self
end
alias_info(slave, cmd_name)
click to toggle source
def alias_info(slave, cmd_name)
raise SecurityError, "no permission to manipulate" unless self.manipulable?
_lst2ary(@interp._invoke('interp', 'alias', _slavearg(slave), cmd_name))
end
alias_target(aliascmd, slave = '')
click to toggle source
def alias_target(aliascmd, slave = '')
raise SecurityError, "no permission to manipulate" unless self.manipulable?
@interp._invoke('interp', 'target', _slavearg(slave), aliascmd)
end
aliases(slave = '')
click to toggle source
def aliases(slave = '')
raise SecurityError, "no permission to manipulate" unless self.manipulable?
_lst2ary(@interp._invoke('interp', 'aliases', _slavearg(slave)))
end
alive?()
click to toggle source
def alive?
raise SecurityError, "no permission to manipulate" unless self.manipulable?
begin
return false unless @cmd_receiver.alive?
return false if @interp.deleted?
return false if @interp._invoke('interp', 'exists', '') == '0'
rescue Exception
return false
end
true
end
allow_ruby_exit=(mode)
click to toggle source
def allow_ruby_exit= (mode)
raise SecurityError, "no permission to manipulate" unless self.manipulable?
@interp.allow_ruby_exit = mode
end
allow_ruby_exit?()
click to toggle source
def allow_ruby_exit?
raise SecurityError, "no permission to manipulate" unless self.manipulable?
@interp.allow_ruby_exit?
end
background_call(*args)
click to toggle source
background_eval(*args, &blk)
click to toggle source
background_eval_proc(*args)
click to toggle source
background_eval_str(cmd, *eval_args)
click to toggle source
background_eval_string(cmd, *eval_args)
click to toggle source
bg_call(*args)
click to toggle source
bg_eval(*args, &blk)
click to toggle source
def bg_eval(*args, &blk)
if block_given?
bg_eval_proc(*args, &blk)
elsif args[0]
if args[0].respond_to?(:call)
bg_eval_proc(*args)
else
bg_eval_string(*args)
end
else
fail ArgumentError, "no argument to eval"
end
end
bg_eval_proc(*args)
click to toggle source
def bg_eval_proc(*args)
if block_given?
cmd = Proc.new
else
unless (cmd = args.shift)
fail ArgumentError, "A Proc or Method object is expected for 1st argument"
end
end
Thread.new{
eval_proc(cmd, *args)
}
end
bg_eval_str(cmd, *eval_args)
click to toggle source
bg_eval_string(cmd, *eval_args)
click to toggle source
def bg_eval_string(cmd, *eval_args)
unless cmd.kind_of?(String)
raise RuntimeError, "A String object is expected for the 'cmd' argument"
end
Thread.new{
eval_proc_core(true,
proc{|safe|
Kernel.eval("$SAFE=#{safe} if $SAFE < #{safe};" << cmd,
*eval_args)
})
}
end
call(*args)
click to toggle source
begin¶ ↑
def eval_proc(*args)
if block_given?
cmd = Proc.new
else
unless (cmd = args.shift)
fail ArgumentError, "A Proc or Method object is expected for 1st argument"
end
end
if TclTkLib.mainloop_thread? == true
current = Thread.current
backup_ip = current[:callback_ip]
current[:callback_ip] = self
begin
eval_proc_core(false,
proc{|safe, *params|
$SAFE=safe if $SAFE < safe
cmd.call(*params)
}, *args)
ensure
current[:callback_ip] = backup_ip
end
else
eval_proc_core(true,
proc{|safe, *params|
$SAFE=safe if $SAFE < safe
Thread.new(*params, &cmd).value
},
*args)
end
end
def call(*args)
unless @ip.deleted?
current = Thread.current
backup_ip = current[:callback_ip]
current[:callback_ip] = @ip
begin
ret = @ip.cb_eval(@cmd, *args)
fail ret if ret.kind_of?(Exception)
ret
rescue TkCallbackBreak, TkCallbackContinue => e
fail e
rescue SecurityError => e
if e.backtrace[0] =~ /^(.+?):(\d+):in `(exit|exit!|abort)'/
@ip.delete
elsif @ip.safe?
if @ip.respond_to?(:cb_error)
@ip.cb_error(e)
else
nil
end
else
fail e
end
rescue Exception => e
fail e if e.message =~ /^TkCallback/
if @ip.safe?
if @ip.respond_to?(:cb_error)
@ip.cb_error(e)
else
nil
end
else
fail e
end
ensure
current[:callback_ip] = backup_ip
end
end
end
cb_error(e)
click to toggle source
def cb_error(e)
if @cb_error_proc[0].respond_to?(:call)
@cb_error_proc[0].call(e)
end
end
cb_eval(cmd, *args)
click to toggle source
begin¶ ↑
def cb_eval(cmd, *args)
ret = self.eval_callback(*args){|safe, *params|
$SAFE=safe if $SAFE < safe
TkComm._get_eval_string(TkUtil.eval_cmd(cmd, *params))
}
if ret.kind_of?(Exception)
raise ret
end
ret
end
def cb_eval(cmd, *args)
self.eval_callback(*args,
&_proc_on_safelevel{|*params|
TkComm._get_eval_string(TkUtil.eval_cmd(cmd, *params))
})
end
def_alias(slave, new_cmd, org_cmd, *args)
click to toggle source
def def_alias(slave, new_cmd, org_cmd, *args)
raise SecurityError, "no permission to manipulate" unless self.manipulable?
ret = @interp._invoke('interp', 'alias', _slavearg(slave), new_cmd,
'', org_cmd, *args)
(ret == new_cmd)? self: nil
end
default_encoding()
click to toggle source
default_encoding=(enc)
click to toggle source
def default_encoding=(enc)
raise SecurityError, "no permission to manipulate" unless self.manipulable?
@interp.default_encoding = enc
end
delete()
click to toggle source
def delete
raise SecurityError, "no permission to manipulate" unless self.manipulable?
@slave_ip_tbl.each{|name, subip|
_destroy_slaves_of_slaveIP(subip)
begin
unless subip.deleted?
after_ids = subip._eval_without_enc("after info")
subip._eval_without_enc("foreach i {#{after_ids}} {after cancel $i}")
end
rescue Exception
end
if @interp._eval_without_enc("catch {::safe::interpConfigure #{name}}") == '0'
begin
@interp._eval_without_enc("::safe::interpDelete #{name}")
rescue Exception
else
next if subip.deleted?
end
end
if subip.respond_to?(:safe_base?) && subip.safe_base? &&
!subip.deleted?
begin
subip._eval_without_enc('exit')
rescue Exception
end
else
begin
subip.delete unless subip.deleted?
rescue Exception
end
end
}
begin
after_ids = @interp._eval_without_enc("after info")
@interp._eval_without_enc("foreach i {#{after_ids}} {after cancel $i}")
rescue Exception
end
begin
@interp._invoke('destroy', '.') unless @interp.deleted?
rescue Exception
end
if @safe_base && !@interp.deleted?
@interp._eval_without_enc('exit')
end
@interp.delete
self
end
delete_cmd(slave, cmd)
click to toggle source
def delete_cmd(slave, cmd)
raise SecurityError, "no permission to manipulate" unless self.manipulable?
slave_invoke = @interp._invoke('list', 'rename', cmd, '')
@interp._invoke('interp', 'eval', _slavearg(slave), slave_invoke)
self
end
delete_slaves(*args)
click to toggle source
def delete_slaves(*args)
raise SecurityError, "no permission to manipulate" unless self.manipulable?
slaves = args.collect{|s| _slavearg(s)}
@interp._invoke('interp', 'delete', *slaves) if slaves.size > 0
self
end
deleted?()
click to toggle source
def deleted?
raise SecurityError, "no permission to manipulate" unless self.manipulable?
@interp.deleted?
end
encoding()
click to toggle source
encoding=(enc)
click to toggle source
def encoding=(enc)
raise SecurityError, "no permission to manipulate" unless self.manipulable?
@interp.encoding = enc
end
encoding_convert_from(str, enc=None)
click to toggle source
encoding_convert_to(str, enc=None)
click to toggle source
encoding_convertfrom(str, enc=None)
click to toggle source
def encoding_convertfrom(str, enc=None)
raise SecurityError, "no permission to manipulate" unless self.manipulable?
@interp.encoding_convertfrom(str, enc)
end
encoding_convertto(str, enc=None)
click to toggle source
def encoding_convertto(str, enc=None)
raise SecurityError, "no permission to manipulate" unless self.manipulable?
@interp.encoding_convertto(str, enc)
end
encoding_name()
click to toggle source
def encoding_name
raise SecurityError, "no permission to manipulate" unless self.manipulable?
@interp.encoding_name
end
encoding_obj()
click to toggle source
def encoding_obj
raise SecurityError, "no permission to manipulate" unless self.manipulable?
@interp.encoding_obj
end
encoding_table()
click to toggle source
def encoding_table
@interp.encoding_table
end
eval(*args, &blk)
click to toggle source
def eval(*args, &blk)
if block_given?
eval_proc(*args, &blk)
elsif args[0]
if args[0].respond_to?(:call)
eval_proc(*args)
else
eval_string(*args)
end
else
fail ArgumentError, "no argument to eval"
end
end
eval_callback(*args)
click to toggle source
Not stable, so disable this feature
def eval_callback(*args)
if block_given?
cmd = Proc.new
else
cmd = args.shift
end
begin
if @@CALLBACK_SUBTHREAD.table[self].index(Thread.current)
last_th = nil
else
last_th = @@CALLBACK_SUBTHREAD.table[self][-1]
end
@@CALLBACK_SUBTHREAD.new(self){
@@CALLBACK_SUBTHREAD.table[self] << Thread.current
begin
last_th.join if last_th
eval_proc_core(false, cmd, *args)
rescue Exception=>e
e
ensure
@@CALLBACK_SUBTHREAD.table[self].delete(Thread.current)
end
}
end
end
eval_proc(*args, &blk)
click to toggle source
def eval_proc(*args, &blk)
if block_given?
cmd = _proc_on_safelevel(&blk)
else
unless (cmd = args.shift)
fail ArgumentError, "A Proc or Method object is expected for 1st argument"
end
cmd = _proc_on_safelevel(&cmd)
end
if TclTkLib.mainloop_thread? == true
current = Thread.current
backup_ip = current[:callback_ip]
current[:callback_ip] = self
begin
eval_proc_core(false, cmd, *args)
ensure
current[:callback_ip] = backup_ip
end
else
eval_proc_core(true,
proc{|safe, *params|
Thread.new{cmd.call(safe, *params)}.value
},
*args)
end
end
Also aliased as: call
eval_str(cmd, *eval_args)
click to toggle source
eval_string(cmd, *eval_args)
click to toggle source
def eval_string(cmd, *eval_args)
unless cmd.kind_of?(String)
raise RuntimeError, "A String object is expected for the 'cmd' argument"
end
eval_proc_core(true,
proc{|safe|
Kernel.eval("$SAFE=#{safe} if $SAFE < #{safe};" << cmd,
*eval_args)
})
end
exist?(slave = '')
click to toggle source
def exist?(slave = '')
raise SecurityError, "no permission to manipulate" unless self.manipulable?
ret = @interp._invoke('interp', 'exists', _slavearg(slave))
(ret == '1')? true: false
end
exit(st = true)
click to toggle source
def exit(st = true)
raise SecurityError, "no permission to manipulate" unless self.manipulable?
if master? && !safe? && allow_ruby_exit?
Kernel.exit(st)
else
delete
st
end
end
exit!(st = false)
click to toggle source
def exit!(st = false)
raise SecurityError, "no permission to manipulate" unless self.manipulable?
if master? && !safe? && allow_ruby_exit?
Kernel.exit!(st)
else
delete
st
end
end
expose_cmd(slave, cmd, aliasname = nil)
click to toggle source
def expose_cmd(slave, cmd, aliasname = nil)
raise SecurityError, "no permission to manipulate" unless self.manipulable?
if aliasname
@interp._invoke('interp', 'expose', _slavearg(slave), cmd, aliasname)
else
@interp._invoke('interp', 'expose', _slavearg(slave), cmd)
end
self
end
force_default_encoding=(mode)
click to toggle source
def force_default_encoding=(mode)
raise SecurityError, "no permission to manipulate" unless self.manipulable?
@interp.force_default_encoding = mode
end
force_default_encoding?()
click to toggle source
def force_default_encoding?
raise SecurityError, "no permission to manipulate" unless self.manipulable?
@interp.force_default_encoding?
end
get_bgerror_handler(slave = '')
click to toggle source
def get_bgerror_handler(slave = '')
raise SecurityError, "no permission to manipulate" unless self.manipulable?
procedure(@interp._invoke('interp', 'bgerror', _slavearg(slave)))
end
get_limit(limit_type, slave = '', slot = nil)
click to toggle source
def get_limit(limit_type, slave = '', slot = nil)
raise SecurityError, "no permission to manipulate" unless self.manipulable?
if slot
num_or_str(@interp._invoke('interp', 'limit', _slavearg(slave),
limit_type, slot))
else
l = @interp._split_tklist(@interp._invoke_without_enc('interp', 'limit',
_slavearg(slave),
limit_type))
l.map!{|s| _fromUTF8(s)}
r = {}
until l.empty?
key = l.shift[1..-1]
val = l.shift
val = num_or_str(val) if val
r[key] = val
end
r
end
end
has_mainwindow?()
click to toggle source
def has_mainwindow?
raise SecurityError, "no permission to manipulate" unless self.manipulable?
@interp.has_mainwindow?
end
hidden_cmds(slave = '')
click to toggle source
def hidden_cmds(slave = '')
raise SecurityError, "no permission to manipulate" unless self.manipulable?
_lst2ary(@interp._invoke('interp', 'hidden', _slavearg(slave)))
end
hide_cmd(slave, cmd, aliasname = nil)
click to toggle source
def hide_cmd(slave, cmd, aliasname = nil)
raise SecurityError, "no permission to manipulate" unless self.manipulable?
if aliasname
@interp._invoke('interp', 'hide', _slavearg(slave), cmd, aliasname)
else
@interp._invoke('interp', 'hide', _slavearg(slave), cmd)
end
self
end
inspect()
click to toggle source
def inspect
cmd.inspect
end
invalid_namespace?()
click to toggle source
def invalid_namespace?
raise SecurityError, "no permission to manipulate" unless self.manipulable?
@interp.invalid_namespace?
end
invoke_hidden(slave, cmd, *args)
click to toggle source
def invoke_hidden(slave, cmd, *args)
raise SecurityError, "no permission to manipulate" unless self.manipulable?
if args[-1].kind_of?(Hash)
keys = _symbolkey2str(args.pop)
else
keys = []
end
keys << _slavearg(slave)
if Tk::TCL_MAJOR_VERSION > 8 ||
(Tk::TCL_MAJOR_VERSION == 8 && Tk::TCL_MINOR_VERSION >= 5)
keys << '--'
end
keys << cmd
keys.concat(args)
@interp._invoke('interp', 'invokehidden', *keys)
end
invoke_hidden_on_global(slave, cmd, *args)
click to toggle source
def invoke_hidden_on_global(slave, cmd, *args)
raise SecurityError, "no permission to manipulate" unless self.manipulable?
if args[-1].kind_of?(Hash)
keys = _symbolkey2str(args.pop)
else
keys = []
end
keys << _slavearg(slave)
keys << '-global'
if Tk::TCL_MAJOR_VERSION > 8 ||
(Tk::TCL_MAJOR_VERSION == 8 && Tk::TCL_MINOR_VERSION >= 5)
keys << '--'
end
keys << cmd
keys.concat(args)
@interp._invoke('interp', 'invokehidden', *keys)
end
invoke_hidden_on_namespace(slave, ns, cmd, *args)
click to toggle source
def invoke_hidden_on_namespace(slave, ns, cmd, *args)
raise SecurityError, "no permission to manipulate" unless self.manipulable?
if args[-1].kind_of?(Hash)
keys = _symbolkey2str(args.pop)
else
keys = []
end
keys << _slavearg(slave)
keys << '-namespace' << TkComm._get_eval_string(ns)
keys << '--' << cmd
keys.concat(args)
@interp._invoke('interp', 'invokehidden', *keys)
end
ip_name()
click to toggle source
def ip_name
@ip_name || ''
end
mainloop(check_root = true, restart_on_dead = false)
click to toggle source
def mainloop(check_root = true, restart_on_dead = true)
def mainloop(check_root = true, restart_on_dead = false)
raise SecurityError, "no permission to manipulate" unless self.manipulable?
if WITH_RUBY_VM
return @interp_thread.value if @interp_thread
end
if self != @@DEFAULT_MASTER
if @wait_on_mainloop[0]
begin
@wait_on_mainloop[1] += 1
if $SAFE >= 4
_receiver_mainloop(check_root).join
else
@cmd_queue.enq([@system, 'call_mainloop',
Thread.current, check_root])
Thread.stop
end
rescue MultiTkIp_OK => ret
if ret.value.kind_of?(Thread)
return ret.value.value
else
return ret.value
end
rescue SystemExit => e
warn("Warning: " + e.inspect + " on " + self.inspect) if $DEBUG
begin
self._eval_without_enc('exit')
rescue Exception
end
self.delete
rescue StandardError => e
if $DEBUG
warn("Warning: " + e.class.inspect +
((e.message.length > 0)? ' "' + e.message + '"': '') +
" on " + self.inspect)
end
return e
rescue Exception => e
return e
ensure
@wait_on_mainloop[1] -= 1
end
end
return
end
unless restart_on_dead
@wait_on_mainloop[1] += 1
begin
@interp.mainloop(check_root)
ensure
@wait_on_mainloop[1] -= 1
end
else
loop do
break unless self.alive?
if check_root
begin
break if TclTkLib.num_of_mainwindows == 0
rescue StandardError
break
end
end
break if @interp.deleted?
begin
@wait_on_mainloop[1] += 1
@interp.mainloop(check_root)
rescue StandardError => e
if TclTkLib.mainloop_abort_on_exception != nil
if $DEBUG
warn("Warning: Tk mainloop receives " << e.class.inspect <<
" exception (ignore) : " << e.message);
end
end
rescue Exception => e
raise e
ensure
@wait_on_mainloop[1] -= 1
Thread.pass
end
end
end
self
end
make_safe()
click to toggle source
def make_safe
raise SecurityError, "no permission to manipulate" unless self.manipulable?
@interp.make_safe
end
manipulable?()
click to toggle source
def manipulable?
return true if (Thread.current.group == ThreadGroup::Default)
ip = MultiTkIp.__getip
(ip == self) || ip._is_master_of?(@interp)
end
mark_trusted(slave = '')
click to toggle source
def mark_trusted(slave = '')
raise SecurityError, "no permission to manipulate" unless self.manipulable?
@interp._invoke('interp', 'marktrusted', _slavearg(slave))
self
end
master?()
click to toggle source
def master?
if @ip_name
false
else
true
end
end
mutex()
click to toggle source
path()
click to toggle source
def path
@ip_name || ''
end
recursion_limit(slave = '', limit = None)
click to toggle source
def recursion_limit(slave = '', limit = None)
raise SecurityError, "no permission to manipulate" unless self.manipulable?
number(@interp._invoke('interp', 'recursionlimit',
_slavearg(slave), limit))
end
restart(app_name = nil, keys = {})
click to toggle source
def restart(app_name = nil, keys = {})
raise SecurityError, "no permission to manipulate" unless self.manipulable?
_init_ip_internal(@@INIT_IP_ENV, @@ADD_TK_PROCS)
@interp._invoke('set', 'argv0', app_name) if app_name
if keys.kind_of?(Hash)
@interp._invoke('set', 'argv', _keys2opts(keys))
end
@interp.restart
end
running_mainloop?()
click to toggle source
def running_mainloop?
@wait_on_mainloop[1] > 0
end
safe?()
click to toggle source
def safe?
raise SecurityError, "no permission to manipulate" unless self.manipulable?
@interp.safe?
end
safe_base?()
click to toggle source
def safe_base?
raise SecurityError, "no permission to manipulate" unless self.manipulable?
@safe_base
end
safe_level()
click to toggle source
def safe_level
@safe_level[0]
end
safe_level=(safe)
click to toggle source
def safe_level=(safe)
set_safe_level(safe)
end
safeip_add_to_access_path(dir)
click to toggle source
def safeip_add_to_access_path(dir)
ip = MultiTkIp.__getip
ip._eval("::safe::interpAddToAccessPath #{@ip_name} #{dir}")
end
safeip_configinfo(slot = nil)
click to toggle source
def safeip_configinfo(slot = nil)
ip = MultiTkIp.__getip
ret = {}
if slot
conf = _lst2ary(ip._eval("::safe::interpConfigure " +
@ip_name + " -#{slot}"))
if conf[0] == '-deleteHook'
if conf[1] =~ /rb_out\S*(?:\s+(::\S*|[{](::.*)[}]|["](::.*)["]))? (c(_\d+_)?(\d+))/
ret[conf[0][1..-1]] = MultiTkIp._tk_cmd_tbl[$4]
else
ret[conf[0][1..-1]] = conf[1]
end
else
ret[conf[0][1..-1]] = conf[1]
end
else
Hash[*_lst2ary(ip._eval("::safe::interpConfigure " +
@ip_name))].each{|k, v|
if k == '-deleteHook'
if v =~ /rb_out\S*(?:\s+(::\S*|[{](::.*)[}]|["](::.*)["]))? (c(_\d+_)?(\d+))/
ret[k[1..-1]] = MultiTkIp._tk_cmd_tbl[$4]
else
ret[k[1..-1]] = v
end
else
ret[k[1..-1]] = v
end
}
end
ret
end
safeip_delete()
click to toggle source
def safeip_delete
ip = MultiTkIp.__getip
ip._eval("::safe::interpDelete " + @ip_name)
end
safeip_find_in_access_path(dir)
click to toggle source
def safeip_find_in_access_path(dir)
ip = MultiTkIp.__getip
ip._eval("::safe::interpFindInAccessPath #{@ip_name} #{dir}")
end
safeip_set_log_cmd(cmd = Proc.new)
click to toggle source
def safeip_set_log_cmd(cmd = Proc.new)
ip = MultiTkIp.__getip
ip._eval("::safe::setLogCmd #{@ip_name} #{_get_eval_string(cmd)}")
end
set_bgerror_handler(cmd = Proc.new, slave = nil, &b)
click to toggle source
def set_bgerror_handler(cmd = Proc.new, slave = nil, &b)
raise SecurityError, "no permission to manipulate" unless self.manipulable?
unless TkComm._callback_entry?(cmd)
if !slave && b
slave = cmd
cmd = Proc.new(&b)
end
end
slave = '' unless slave
@interp._invoke('interp', 'bgerror', _slavearg(slave), cmd)
end
set_cb_error(cmd = Proc.new)
click to toggle source
def set_cb_error(cmd = Proc.new)
@cb_error_proc[0] = cmd
end
set_limit(limit_type, slave = '', opts = {})
click to toggle source
def set_limit(limit_type, slave = '', opts = {})
raise SecurityError, "no permission to manipulate" unless self.manipulable?
@interp._invoke('interp', 'limit', _slavearg(slave), limit_type, opts)
end
set_safe_level(safe)
click to toggle source
def set_safe_level(safe)
if safe > @safe_level[0]
@safe_level[0] = safe
@cmd_queue.enq([@system, 'set_safe_level', safe])
end
@safe_level[0]
end
share_stderr(dist, src = '')
click to toggle source
def share_stderr(dist, src = '')
raise SecurityError, "no permission to manipulate" unless self.manipulable?
@interp._invoke('interp', 'share', src, 'stderr', dist)
self
end
share_stdin(dist, src = '')
click to toggle source
def share_stdin(dist, src = '')
raise SecurityError, "no permission to manipulate" unless self.manipulable?
@interp._invoke('interp', 'share', src, 'stdin', dist)
self
end
share_stdio(dist, src = '')
click to toggle source
def share_stdio(dist, src = '')
raise SecurityError, "no permission to manipulate" unless self.manipulable?
@interp._invoke('interp', 'share', src, 'stdin', dist)
@interp._invoke('interp', 'share', src, 'stdout', dist)
@interp._invoke('interp', 'share', src, 'stderr', dist)
self
end
share_stdout(dist, src = '')
click to toggle source
def share_stdout(dist, src = '')
raise SecurityError, "no permission to manipulate" unless self.manipulable?
@interp._invoke('interp', 'share', src, 'stdout', dist)
self
end
slave?()
click to toggle source
def slave?
not master?
end
slaves(all = false)
click to toggle source
def slaves(all = false)
raise SecurityError, "no permission to manipulate" unless self.manipulable?
@interp._invoke('interp','slaves').split.map!{|name|
if @slave_ip_tbl.key?(name)
@slave_ip_tbl[name]
elsif all
name
else
nil
end
}.compact!
end
thread_eval_proc(*args)
click to toggle source
to_eval()
click to toggle source
def to_eval
@ip_name || ''
end
transfer_stderr(dist, src = '')
click to toggle source
def transfer_stderr(dist, src = '')
raise SecurityError, "no permission to manipulate" unless self.manipulable?
@interp._invoke('interp', 'transfer', src, 'stderr', dist)
self
end
transfer_stdin(dist, src = '')
click to toggle source
def transfer_stdin(dist, src = '')
raise SecurityError, "no permission to manipulate" unless self.manipulable?
@interp._invoke('interp', 'transfer', src, 'stdin', dist)
self
end
transfer_stdio(dist, src = '')
click to toggle source
def transfer_stdio(dist, src = '')
raise SecurityError, "no permission to manipulate" unless self.manipulable?
@interp._invoke('interp', 'transfer', src, 'stdin', dist)
@interp._invoke('interp', 'transfer', src, 'stdout', dist)
@interp._invoke('interp', 'transfer', src, 'stderr', dist)
self
end
transfer_stdout(dist, src = '')
click to toggle source
def transfer_stdout(dist, src = '')
raise SecurityError, "no permission to manipulate" unless self.manipulable?
@interp._invoke('interp', 'transfer', src, 'stdout', dist)
self
end
wait_on_mainloop=(bool)
click to toggle source
def wait_on_mainloop=(bool)
@wait_on_mainloop[0] = bool
end
wait_on_mainloop?()
click to toggle source
def wait_on_mainloop?
@wait_on_mainloop[0]
end