PyObject_Repr() private method

private PyObject_Repr ( IntPtr pointer ) : IntPtr
pointer IntPtr
return IntPtr
Esempio n. 1
0
        /// <summary>
        /// Repr Method
        /// </summary>
        /// <remarks>
        /// Return a string representation of the object. This method is
        /// the managed equivalent of the Python expression "repr(object)".
        /// </remarks>
        public string Repr()
        {
            IntPtr strval = Runtime.PyObject_Repr(obj);
            string result = Runtime.GetManagedString(strval);

            Runtime.XDecref(strval);
            return(result);
        }
Esempio n. 2
0
        private static void SetConversionError(IntPtr value, Type target)
        {
            IntPtr ob  = Runtime.PyObject_Repr(value);
            string src = Runtime.GetManagedString(ob);

            Runtime.XDecref(ob);
            Exceptions.SetError(Exceptions.TypeError, $"Cannot convert {src} to {target}");
        }
Esempio n. 3
0
        static void SetConversionError(IntPtr value, Type target)
        {
            IntPtr ob  = Runtime.PyObject_Repr(value);
            string src = Runtime.GetManagedString(ob);

            Runtime.Decref(ob);
            string error = String.Format(
                "Cannot convert {0} to {1}", src, target
                );

            Exceptions.SetError(Exceptions.TypeError, error);
        }
Esempio n. 4
0
        private static void SetConversionError(IntPtr value, Type target)
        {
            // PyObject_Repr might clear the error
            Runtime.PyErr_Fetch(out var causeType, out var causeVal, out var causeTrace);

            IntPtr ob  = Runtime.PyObject_Repr(value);
            string src = Runtime.GetManagedString(ob);

            Runtime.XDecref(ob);

            Runtime.PyErr_Restore(causeType.StealNullable(), causeVal.StealNullable(), causeTrace.StealNullable());
            Exceptions.RaiseTypeError($"Cannot convert {src} to {target}");
        }
Esempio n. 5
0
        public static void Print(string msg, BorrowedReference member)
        {
            string result = msg;

            result += " ";

            if (member == null)
            {
                Console.WriteLine("null arg to print");
            }
            using var ob = Runtime.PyObject_Repr(member);
            result      += Runtime.GetManagedString(ob.BorrowOrThrow());
            result      += " ";
            Console.WriteLine(result);
        }
Esempio n. 6
0
        public static void Print(string msg, params IntPtr[] args)
        {
            string result = msg;

            result += " ";

            foreach (IntPtr t in args)
            {
                if (t == IntPtr.Zero)
                {
                    Console.WriteLine("null arg to print");
                }
                IntPtr ob = Runtime.PyObject_Repr(t);
                result += Runtime.GetManagedString(ob);
                Runtime.XDecref(ob);
                result += " ";
            }
            Console.WriteLine(result);
        }
Esempio n. 7
0
        public static void Print(string msg, params IntPtr[] args)
        {
            string result = msg;

            result += " ";

            for (int i = 0; i < args.Length; i++)
            {
                if (args[i] == IntPtr.Zero)
                {
                    Console.WriteLine("null arg to print");
                }
                IntPtr ob = Runtime.PyObject_Repr(args[i]);
                result += Runtime.GetManagedString(ob);
                Runtime.Decref(ob);
                result += " ";
            }
            Console.WriteLine(result);
            return;
        }
Esempio n. 8
0
        private static void SetConversionError(BorrowedReference value, Type target)
        {
            // PyObject_Repr might clear the error
            Runtime.PyErr_Fetch(out var causeType, out var causeVal, out var causeTrace);

            var    ob  = Runtime.PyObject_Repr(value);
            string src = "'object has no repr'";

            if (ob.IsNull())
            {
                Exceptions.Clear();
            }
            else
            {
                src = Runtime.GetManagedString(ob.Borrow()) ?? src;
            }
            ob.Dispose();

            Runtime.PyErr_Restore(causeType.StealNullable(), causeVal.StealNullable(), causeTrace.StealNullable());
            Exceptions.RaiseTypeError($"Cannot convert {src} to {target}");
        }