def _close(this): this = convert_to_pyobj(this) try: this.__this___buffer.close() this.__this_closed = True except Exception as e: return AILRuntimeError(str(e), 'PythonError')
def print_all_error(exit=False, exit_code=1): es = MAIN_INTERPRETER_STATE.err_stack[::-1] for e in es: eo = convert_to_pyobj(e) print(unpack_ailobj(eo.__this_to_string)(e)) if exit: sys.exit(exit_code)
def _err_to_string(this): this = convert_to_pyobj(this) ofs = this.__this___offset msg = this.__this_err_msg type = this.__this_err_type where = this.__this_err_where return '%s%s : %s' % ('in \'%s\' + %s :\n\t' % (where, ofs) if where else '', type, msg)
def _peek(this, size): this = convert_to_pyobj(this) size = unpack_ailobj(size) if type(size) != int: return AILRuntimeError('iobuffer.peek() needs an integer.') try: return this.__this___buffer.peek(size) except Exception as e: return AILRuntimeError(str(e), 'PythonError')
def _write(this, string): this = convert_to_pyobj(this) string = unpack_ailobj(string) buf = this.__this___buffer if type(string) != str: return AILRuntimeError('iobuffer.write() needs a string.') try: if not buf.writable(): return AILRuntimeError('not writeable', 'OSError') return buf.write(string) except Exception as e: return AILRuntimeError(str(e), 'PythonError')
def _read(this, size): this = convert_to_pyobj(this) size = unpack_ailobj(size) buf = this.__this___buffer if type(size) != int: return AILRuntimeError('iobuffer.read() needs an integer.') try: if not buf.readable(): return AILRuntimeError('not readable', 'OSError') return buf.read(size) except Exception as e: return AILRuntimeError(str(e), 'PythonError')
def _pop(this): this = convert_to_pyobj(this) if this.__this___stack: return this.__this___stack.pop() return null
def _empty(this): this = convert_to_pyobj(this) return len(this.__this___stack) == 0