Ejemplo n.º 1
0
        public static PyListIterator Create(PyList list)
        {
            var iterator = PyTypeObject.DefaultNew <PyListIterator>(PyListIteratorClass.Instance);

            iterator.CurrentIdx   = 0;
            iterator.IteratedList = list;

            return(iterator);
        }
Ejemplo n.º 2
0
 public static PyBool __contains__(PyList self, PyObject v)
 {
     if (self.list.Contains(v))
     {
         return(PyBool.True);
     }
     else
     {
         return(PyBool.False);
     }
 }
Ejemplo n.º 3
0
 // TODO: Manage slices
 public static void __setitem__(PyList self, int i, PyObject value)
 {
     try
     {
         self.list[i] = value;
     }
     catch (IndexOutOfRangeException)
     {
         // TODO: Represent as a more natural Python exception;
         throw new Exception("IndexError: list assignment index out of range");
     }
 }
Ejemplo n.º 4
0
 public static object __getitem__(PyList self, PyInteger i)
 {
     try
     {
         return(self.list[(int)i.InternalValue]);
     }
     catch (IndexOutOfRangeException)
     {
         // TODO: Represent as a more natural Python exception;
         throw new Exception("IndexError: list index out of range");
     }
 }
Ejemplo n.º 5
0
 public static void __delitem__(PyList self, PyInteger i)
 {
     try
     {
         self.list.RemoveAt((int)i.InternalValue);
     }
     catch (IndexOutOfRangeException)
     {
         // TODO: Represent as a more natural Python exception;
         throw new Exception("IndexError: list assignment index out of range");
     }
 }
Ejemplo n.º 6
0
        public static PyBool __eq__(PyList self, PyObject other)
        {
            var otherList = other as PyList;

            if (otherList == null)
            {
                return(PyBool.False);
            }

            if (otherList.list.Count != self.list.Count)
            {
                return(PyBool.False);
            }

            for (int i = 0; i < self.list.Count; ++i)
            {
                if (self.list[i].__eq__(otherList.list[i]).boolean == false)
                {
                    return(PyBool.False);
                }
            }
            return(PyBool.True);
        }
Ejemplo n.º 7
0
        public static PyBool __eq__(PyList self, object other)
        {
            var otherList = other as PyList;

            if (otherList == null)
            {
                return(PyBool.False);
            }

            if (otherList.list.Count != self.list.Count)
            {
                return(PyBool.False);
            }

            for (int i = 0; i < self.list.Count; ++i)
            {
                var selfPyObject  = self.list[i] as PyObject;
                var otherPyObject = otherList.list[i] as PyObject;

                if (selfPyObject == null || otherPyObject == null)
                {
                    return(PyBool.False);
                }
                else if (selfPyObject != null)
                {
                    if (selfPyObject.__eq__(otherPyObject).InternalValue == false)
                    {
                        return(PyBool.False);
                    }
                }
                else if (!self.list[i].Equals(otherList.list[i]))
                {
                    return(PyBool.False);
                }
            }
            return(PyBool.True);
        }
Ejemplo n.º 8
0
 public static void __setitem__(PyList self, PyInteger i, PyObject value)
 {
     __setitem__(self, (int)i.InternalValue, value);
 }
Ejemplo n.º 9
0
 public static void prepend(PyList self, PyObject toAdd)
 {
     self.list.Insert(0, toAdd);
 }
Ejemplo n.º 10
0
 public static void append(PyList self, PyObject toAdd)
 {
     self.list.Add(toAdd);
 }
Ejemplo n.º 11
0
 public static void clear(PyList self)
 {
     self.list.Clear();
 }
Ejemplo n.º 12
0
 public static PyBool __ne__(PyList self, PyObject other)
 {
     return(!__eq__(self, other));
 }