示例#1
0
        /// Get a member of this module by name.
        public PyObj GetMember(string attrName)
        {
            PyObj result;

            unsafe
            {
                var rawDict = CPython.PyModule_GetDict(obj);
                if (rawDict == null)
                {
                    throw new NullReferenceException("Failed to get dict from module.");
                }
                var rawString = CPython.PyUnicode_FromString(attrName);
                if (rawString == null)
                {
                    throw new NullReferenceException("Failed to create PyObject from string.");
                }
                var rawResult = CPython.PyDict_GetItem(rawDict, rawString);
                if (rawResult == null)
                {
                    throw new NullReferenceException("Failed to get item by key.");
                }
                result = new PyObj(rawResult);
            }
            return(result);
        }
示例#2
0
 /// If this Python object supports [] indexing, get an item by its key.
 public PyObj GetItem(PyObj key)
 {
     PyObj result;
     unsafe
     {
         var rawResult = CPython.PyObject_GetItem(obj, key.obj);
         if (rawResult == null) throw new NullReferenceException("Failed to get item by key.");
         result = new PyObj(rawResult);
     }
     return result;
 }
示例#3
0
 /// Call this Python object with the given arguments.
 public PyObj CallObject(PyObj args)
 {
     PyObj result;
     unsafe
     {
         var rawResult = CPython.PyObject_CallObject(obj, args.obj);
         if (rawResult == null) throw new NullReferenceException("Calling PyObject returned null.");
         result = new PyObj(rawResult);
     }
     return result;
 }
示例#4
0
 /// Create a PyObject from a long integer.
 public static PyObj FromLong(long value)
 {
     PyObj result;
     unsafe
     {
         var rawResult = CPython.PyLong_FromLong(value);
         if (rawResult == null) throw new NullReferenceException("Failed to create PyObject from long.");
         result = new PyObj(rawResult);
     }
     return result;
 }
示例#5
0
 /// Create a PyObject from a double.
 public static PyObj FromDouble(double value)
 {
     PyObj result;
     unsafe
     {
         var rawResult = CPython.PyFloat_FromDouble(value);
         if (rawResult == null) throw new NullReferenceException("Failed to create PyObject from double.");
         result = new PyObj(rawResult);
     }
     return result;
 }
示例#6
0
 public PyObj Next()
 {
     PyObj result;
     unsafe
     {
         var rawResult = CPython.PyIter_Next(obj);
         if (rawResult == null) throw new NullReferenceException("PyIter refused to yield an item.");
         result = new PyObj(rawResult);
     }
     return result;
 }
示例#7
0
 /// Get an attribute from this PyObject by string name.
 public PyObj GetAttrString(string attrName)
 {
     PyObj result;
     unsafe
     {
         var rawResult = CPython.PyObject_GetAttrString(obj, attrName);
         if (rawResult == null) throw new NullReferenceException(
             string.Format("Failed to get attribute `{0}` from PyObject.", attrName));
         result = new PyObj(rawResult);
     }
     return result;
 }
示例#8
0
        /// If this Python object supports [] indexing, get an item by its key.
        public PyObj GetItem(PyObj key)
        {
            PyObj result;

            unsafe
            {
                var rawResult = CPython.PyObject_GetItem(obj, key.obj);
                if (rawResult == null)
                {
                    throw new NullReferenceException("Failed to get item by key.");
                }
                result = new PyObj(rawResult);
            }
            return(result);
        }
示例#9
0
        /// Call this Python object with the given arguments.
        public PyObj CallObject(PyObj args)
        {
            PyObj result;

            unsafe
            {
                var rawResult = CPython.PyObject_CallObject(obj, args.obj);
                if (rawResult == null)
                {
                    throw new NullReferenceException("Calling PyObject returned null.");
                }
                result = new PyObj(rawResult);
            }
            return(result);
        }
示例#10
0
        /// Create a PyObject from a long integer.
        public static PyObj FromLong(long value)
        {
            PyObj result;

            unsafe
            {
                var rawResult = CPython.PyLong_FromLong(value);
                if (rawResult == null)
                {
                    throw new NullReferenceException("Failed to create PyObject from long.");
                }
                result = new PyObj(rawResult);
            }
            return(result);
        }
示例#11
0
        /// Create a PyObject from a double.
        public static PyObj FromDouble(double value)
        {
            PyObj result;

            unsafe
            {
                var rawResult = CPython.PyFloat_FromDouble(value);
                if (rawResult == null)
                {
                    throw new NullReferenceException("Failed to create PyObject from double.");
                }
                result = new PyObj(rawResult);
            }
            return(result);
        }
示例#12
0
 /// Get a member of this module by name.
 public PyObj GetMember(string attrName)
 {
     PyObj result;
     unsafe
     {
         var rawDict = CPython.PyModule_GetDict(obj);
         if (rawDict == null) throw new NullReferenceException("Failed to get dict from module.");
         var rawString = CPython.PyUnicode_FromString(attrName);
         if (rawString == null) throw new NullReferenceException("Failed to create PyObject from string.");
         var rawResult = CPython.PyDict_GetItem(rawDict, rawString);
         if (rawResult == null) throw new NullReferenceException("Failed to get item by key.");
         result = new PyObj(rawResult);
     }
     return result;
 }
示例#13
0
        public PyObj Next()
        {
            PyObj result;

            unsafe
            {
                var rawResult = CPython.PyIter_Next(obj);
                if (rawResult == null)
                {
                    throw new NullReferenceException("PyIter refused to yield an item.");
                }
                result = new PyObj(rawResult);
            }
            return(result);
        }
示例#14
0
        /// Get an attribute from this PyObject by string name.
        public PyObj GetAttrString(string attrName)
        {
            PyObj result;

            unsafe
            {
                var rawResult = CPython.PyObject_GetAttrString(obj, attrName);
                if (rawResult == null)
                {
                    throw new NullReferenceException(
                              string.Format("Failed to get attribute `{0}` from PyObject.", attrName));
                }
                result = new PyObj(rawResult);
            }
            return(result);
        }