PyString_Check() static private method

static private PyString_Check ( IntPtr ob ) : bool
ob IntPtr
return bool
Esempio n. 1
0
        /// <summary>
        /// ModuleObject __getattribute__ implementation. Module attributes
        /// are always either classes or sub-modules representing subordinate
        /// namespaces. CLR modules implement a lazy pattern - the sub-modules
        /// and classes are created when accessed and cached for future use.
        /// </summary>
        public static IntPtr tp_getattro(IntPtr ob, IntPtr key)
        {
            var self = (ModuleObject)GetManagedObject(ob);

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

            IntPtr op = Runtime.PyDict_GetItem(self.dict, key);

            if (op != IntPtr.Zero)
            {
                Runtime.XIncref(op);
                return(op);
            }

            string name = Runtime.GetManagedString(key);

            if (name == "__dict__")
            {
                Runtime.XIncref(self.dict);
                return(self.dict);
            }

            ManagedType attr = self.GetAttribute(name, true);

            if (attr == null)
            {
                Exceptions.SetError(Exceptions.AttributeError, name);
                return(IntPtr.Zero);
            }

            Runtime.XIncref(attr.pyHandle);
            return(attr.pyHandle);
        }
Esempio n. 2
0
 /// <summary>
 /// IsStringType Method
 /// </summary>
 ///
 /// <remarks>
 /// Returns true if the given object is a Python string.
 /// </remarks>
 public static bool IsStringType(PyObject value)
 {
     return(Runtime.PyString_Check(value.obj));
 }