PyObject_GenericGetAttr() private method

private PyObject_GenericGetAttr ( IntPtr obj, IntPtr name ) : IntPtr
obj IntPtr
name IntPtr
return IntPtr
Esempio n. 1
0
        /// <summary>
        /// MethodBinding __getattribute__ implementation.
        /// </summary>
        public static IntPtr tp_getattro(IntPtr ob, IntPtr key)
        {
            var self = (MethodBinding)GetManagedObject(ob);

            if (!Runtime.PyString_Check(key))
            {
                Exceptions.SetError(Exceptions.TypeError, "string expected");
                return(IntPtr.Zero);
            }

            string name = Runtime.GetManagedString(key);

            switch (name)
            {
            case "__doc__":
                IntPtr doc = self.m.GetDocString();
                Runtime.XIncref(doc);
                return(doc);

            // FIXME: deprecate __overloads__ soon...
            case "__overloads__":
            case "Overloads":
                var om = new OverloadMapper(self.m, self.target);
                return(om.pyHandle);

            default:
                return(Runtime.PyObject_GenericGetAttr(ob, key));
            }
        }
Esempio n. 2
0
        //====================================================================
        // MethodBinding __getattribute__ implementation.
        //====================================================================

        public static IntPtr tp_getattro(IntPtr ob, IntPtr key)
        {
            MethodBinding self = (MethodBinding)GetManagedObject(ob);

            if (!Runtime.PyString_Check(key))
            {
                Exceptions.SetError(Exceptions.TypeError, "string expected");
                return(IntPtr.Zero);
            }

            string name = Runtime.GetManagedString(key);

            if (name == "__doc__")
            {
                IntPtr doc = self.m.GetDocString();
                Runtime.Incref(doc);
                return(doc);
            }

            if (name == "__overloads__")
            {
                OverloadMapper om = new OverloadMapper(self.m, self.target);
                Runtime.Incref(om.pyHandle);
                return(om.pyHandle);
            }

            return(Runtime.PyObject_GenericGetAttr(ob, key));
        }
Esempio n. 3
0
        //====================================================================
        // Exceptions __getattribute__ implementation.
        // handles Python's args and message attributes
        //====================================================================

        public static IntPtr tp_getattro(IntPtr ob, IntPtr key)
        {
            if (!Runtime.PyString_Check(key))
            {
                Exceptions.SetError(Exceptions.TypeError, "string expected");
                return(IntPtr.Zero);
            }

            string name = Runtime.GetManagedString(key);

            if (name == "args")
            {
                Exception e = ToException(ob);
                IntPtr    args;
                if (e.Message != String.Empty)
                {
                    args = Runtime.PyTuple_New(1);
                    IntPtr msg = Runtime.PyUnicode_FromString(e.Message);
                    Runtime.PyTuple_SetItem(args, 0, msg);
                }
                else
                {
                    args = Runtime.PyTuple_New(0);
                }
                return(args);
            }

            if (name == "message")
            {
                return(ExceptionClassObject.tp_str(ob));
            }

            return(Runtime.PyObject_GenericGetAttr(ob, key));
        }
Esempio n. 4
0
        /// <summary>
        /// Descriptor __getattribute__ implementation.
        /// </summary>
        public static IntPtr tp_getattro(IntPtr ob, IntPtr key)
        {
            var self = (MethodObject)GetManagedObject(ob);

            if (!Runtime.PyString_Check(key))
            {
                return(Exceptions.RaiseTypeError("string expected"));
            }

            if (Runtime.PyUnicode_Compare(key, PyIdentifier.__doc__) == 0)
            {
                IntPtr doc = self.GetDocString();
                Runtime.XIncref(doc);
                return(doc);
            }

            return(Runtime.PyObject_GenericGetAttr(ob, key));
        }
Esempio n. 5
0
        /// <summary>
        /// Descriptor __getattribute__ implementation.
        /// </summary>
        public static IntPtr tp_getattro(IntPtr ob, IntPtr key)
        {
            var self = (MethodObject)GetManagedObject(ob);

            if (!Runtime.PyString_Check(key))
            {
                return(Exceptions.RaiseTypeError("string expected"));
            }

            string name = Runtime.GetManagedString(key);

            if (name == "__doc__")
            {
                IntPtr doc = self.GetDocString();
                Runtime.XIncref(doc);
                return(doc);
            }

            return(Runtime.PyObject_GenericGetAttr(ob, key));
        }
Esempio n. 6
0
        /// <summary>
        /// MethodBinding __getattribute__ implementation.
        /// </summary>
        public static IntPtr tp_getattro(IntPtr ob, IntPtr key)
        {
            var self = (MethodBinding)GetManagedObject(ob);

            if (!Runtime.PyString_Check(key))
            {
                Exceptions.SetError(Exceptions.TypeError, "string expected");
                return(IntPtr.Zero);
            }

            string name = InternString.GetManagedString(key);

            switch (name)
            {
            case "__doc__":
                IntPtr doc = self.m.GetDocString();
                Runtime.XIncref(doc);
                return(doc);

            // FIXME: deprecate __overloads__ soon...
            case "__overloads__":
            case "Overloads":
                var om = new OverloadMapper(self.m, self.target);
                return(om.pyHandle);

            case "__signature__" when Runtime.InspectModule is not null:
                var sig = self.Signature;
                if (sig is null)
                {
                    return(Runtime.PyObject_GenericGetAttr(ob, key));
                }
                return(sig.NewReferenceOrNull().DangerousMoveToPointerOrNull());

            case "__name__":
                return(self.m.GetName().DangerousMoveToPointerOrNull());

            default:
                return(Runtime.PyObject_GenericGetAttr(ob, key));
            }
        }
Esempio n. 7
0
        /// <summary>
        /// Expose the wrapped implementation through attributes in both
        /// converted/encoded (__implementation__) and raw (__raw_implementation__) form.
        /// </summary>
        public static IntPtr tp_getattro(IntPtr ob, IntPtr key)
        {
            var clrObj = (CLRObject)GetManagedObject(ob);

            if (!Runtime.PyString_Check(key))
            {
                return(Exceptions.RaiseTypeError("string expected"));
            }

            string name = Runtime.GetManagedString(key);

            if (name == "__implementation__")
            {
                return(Converter.ToPython(clrObj.inst));
            }
            else if (name == "__raw_implementation__")
            {
                return(CLRObject.GetInstHandle(clrObj.inst));
            }

            return(Runtime.PyObject_GenericGetAttr(ob, key));
        }