def __instancecheck__(self, instance): if not isinstance(instance, ffi.CData): return False if ffi.typeof(instance) != ffi.typeof('SEXP'): return False if self is SEXP: return True return _sexpnums[self.__name__] == lib.TYPEOF(instance)
def __new__(cls, *args): if len(args) == 1: x = args[0] assert isinstance(x, ffi.CData) assert ffi.typeof(x) == ffi.typeof('SEXP') return globals()[_sexpnums_reversed[lib.TYPEOF(x)]] else: x = str(args[0]) return super(sexptype, cls).__new__(cls, x, *args[1:])
import ctypes import struct from contextlib import contextmanager from six import text_type, string_types from types import FunctionType from collections import OrderedDict if sys.version >= "3": from collections.abc import Callable long = int else: from collections import Callable dispatch.add_dispatch_policy(type, datatype) dispatch.add_dispatch_policy( ffi.CData, lambda x: sexptype(x) if ffi.typeof(x) == ffi.typeof('SEXP') else ffi.CData) def extract(kwargs, key, default=None): if key in kwargs: value = kwargs[key] del kwargs[key] else: value = default return value def ensure_initialized(): if lib.Rf_initialize_R == ffi.NULL: from .setup import init init(register_callbacks=False, register_signal_handlers=False)