import errno

from dmoj.cptbox.syscalls import *
from dmoj.executors.base_executor import ScriptExecutor


class Executor(ScriptExecutor):
    ext = '.tcl'
    name = 'TCL'
    address_grace = 131072
    command = 'tclsh'
    fs = ['.*\.tcl', '/etc/nsswitch\.conf$', '/etc/passwd$']
    test_program = '''\
gets stdin input
puts $input
'''

    def get_security(self, **kwargs):
        security = super(Executor, self).get_security(**kwargs)

        def handle_socket(debugger):
            def socket_return():
                debugger.result = -errno.EACCES

            debugger.syscall = debugger.getpid_syscall
            debugger.on_return(socket_return)
            return True

        security[sys_tgkill] = True
        security[sys_write] = lambda debugger: debugger.arg0 <= 4  # TCL uses some handles internally
        security[sys_socket] = handle_socket
        security[sys_socketcall] = handle_socket
        security[sys_connect] = True
        security[sys_access] = True
        security[sys_getsockname] = True

        return security

@@ -1,53 +1,4 @@
-import errno%0A%0Afrom dmoj.cptbox.syscalls import *%0A
 from
@@ -174,536 +174,132 @@
     
-fs = %5B'.*%5C.tcl', '/etc/nsswitch%5C.conf$
+syscalls = %5B'connect', 'access
 ', '
-/etc/passwd$'%5D%0A    test_program = '''%5C%0Agets stdin input%0Aputs $input%0A'''%0A%0A    def get_security(self, **kwargs):%0A        security = super(Executor, self).get_security(**kwargs)%0A%0A        def handle_socket(debugger):%0A            def socket_return():%0A                debugger.result = -errno.EACCES%0A%0A            debugger.syscall = debugger.getpid_syscall%0A            debugger.on_return(socket_return)%0A            return True%0A%0A        security%5Bsys_tgkill%5D = True%0A        security%5Bsys_
+getsockname',%0A                # TCL uses some handles internally%0A                ('
 write
-%5D =
+',
  lam
@@ -334,274 +334,125 @@
 %3C= 4
-  # TCL uses some handles internally%0A        security%5Bsys_socket%5D = handle_socket%0A        security%5Bsys_socketcall%5D = handle_socket%0A        security%5Bsys_connect%5D = True%0A        security%5Bsys_access%5D = True%0A        security%5Bsys_getsockname%5D = True%0A%0A        return security
+)%5D%0A    fs = %5B'.*%5C.tcl', '/etc/nsswitch%5C.conf$', '/etc/passwd$'%5D%0A    test_program = '''%5C%0Agets stdin input%0Aputs $input%0A'''
 %0A

Use new #105 features for TCL