Beispiel #1
0
        public static PyObject __xor__(PyObject self, PyObject other)
        {
            var orded = extractInt(self) ^ extractInt(other);

            return(orded > 0 ? PyBool.True : PyBool.False);
        }
Beispiel #2
0
 public static PyBool __ne__(PyObject self, PyObject other)
 {
     return(extractInt(self) != extractInt(other));
 }
Beispiel #3
0
 public static void append(PyList self, PyObject toAdd)
 {
     self.list.Add(toAdd);
 }
Beispiel #4
0
        public static PyObject __and__(PyObject self, PyObject other)
        {
            var anded = extractInt(self) & extractInt(other);

            return(anded > 0 ? PyBool.True : PyBool.False);
        }
Beispiel #5
0
 public static new PyString __repr__(PyObject self)
 {
     return(PyString.Create(((PyString)self).ToString()));
 }
Beispiel #6
0
 public PyBool __eq__(PyObject other)
 {
     return(Equals(other));
 }
Beispiel #7
0
        public static PyInteger __len__(IInterpreter interpreter, FrameContext context, PyObject self)
        {
            var asDict = (PyDict)self;

            return(PyInteger.Create(asDict.InternalDict.Count));
        }
Beispiel #8
0
        public static PyObject __floordiv__(PyObject self, PyObject other)
        {
            var newPyInteger = PyInteger.Create((BigInteger)((decimal)extractInt(self) / PyFloatClass.ExtractAsDecimal(other)));

            return(newPyInteger);
        }
Beispiel #9
0
 public static Task <PyString> __str__(IInterpreter interpreter, FrameContext context, PyObject self)
 {
     return(__repr__(interpreter, context, self));
 }
Beispiel #10
0
        public static async Task <PyString> __repr__(IInterpreter interpreter, FrameContext context, PyObject self)
        {
            var      asDict  = (PyDict)self;
            PyString retStr  = PyString.Create("{");
            int      visited = 0;

            foreach (var mapping in asDict.dict)
            {
                var key_repr = await __visit_repr((PyObject)mapping.Key, interpreter, context);

                retStr = (PyString)PyStringClass.__add__(retStr, key_repr);
                retStr = (PyString)PyStringClass.__add__(retStr, PyString.Create(": "));

                var val_repr = await __visit_repr((PyObject)mapping.Value, interpreter, context);

                retStr = (PyString)PyStringClass.__add__(retStr, val_repr);

                // Appending commas except on last paring
                if (visited < asDict.dict.Count - 1)
                {
                    retStr = (PyString)PyStringClass.__add__(retStr, PyString.Create(", "));
                }

                visited += 1;
            }
            return((PyString)PyStringClass.__add__(retStr, PyString.Create("}")));
        }
Beispiel #11
0
 public static void __setitem__(PyList self, PyInteger i, PyObject value)
 {
     __setitem__(self, (int)i.number, value);
 }
Beispiel #12
0
        public static async Task <PyString> __repr__(IInterpreter interpreter, FrameContext context, PyObject self)
        {
            var      asList = (PyList)self;
            PyString retStr = PyString.Create("[");

            for (int i = 0; i < asList.list.Count; ++i)
            {
                var pyObj = asList.list[i];

                var __repr__      = pyObj.__getattribute__(PyClass.__REPR__);
                var functionToRun = __repr__ as IPyCallable;

                var returned = await functionToRun.Call(interpreter, context, new object[0]);

                if (returned != null)
                {
                    var asPyString = (PyString)returned;
                    retStr = (PyString)PyStringClass.__add__(retStr, asPyString);
                }

                // Appending commas except on last index
                if (i < asList.list.Count - 1)
                {
                    retStr = (PyString)PyStringClass.__add__(retStr, PyString.Create(", "));
                }
            }
            return((PyString)PyStringClass.__add__(retStr, PyString.Create("]")));
        }
Beispiel #13
0
 public static void prepend(PyList self, PyObject toAdd)
 {
     self.list.Insert(0, toAdd);
 }
Beispiel #14
0
        public static PyObject __lshift__(PyObject self, PyObject other)
        {
            var orded = (int)PyBoolClass.extractInt(self) << (int)PyBoolClass.extractInt(other);

            return(PyInteger.Create(orded));
        }
Beispiel #15
0
        public static PyObject __iter__(PyObject self)
        {
            var asDict = self as PyDict;

            return(PyKeyIterator.Create(asDict));
        }
Beispiel #16
0
        public static PyObject __truediv__(PyObject self, PyObject other)
        {
            var newPyFloat = PyFloat.Create((decimal)extractInt(self) / PyFloatClass.ExtractAsDecimal(other));

            return(newPyFloat);
        }
Beispiel #17
0
        public static PyObject __iter__(PyObject self)
        {
            var asDict = self as PyDict_Items;

            return(PyDictItemsIterator.Create(asDict.Dict));
        }
Beispiel #18
0
 public static new PyString __str__(PyObject self)
 {
     return(__repr__(self));
 }
Beispiel #19
0
        public static PyObject __iter__(PyObject self)
        {
            var asPyRange = self as PyRange;

            return(PyRangeIterator.Create(asPyRange));
        }
Beispiel #20
0
 public static PyObject __div__(PyObject self, PyObject other)
 {
     // TODO: TypeError: unsupported operand type(s) for /: '[self type]' and '[other type]'
     throw new Exception("Strings do not support division");
 }
Beispiel #21
0
        public static PyInteger __len__(IInterpreter interpreter, FrameContext context, PyObject self)
        {
            var asPyRange = (PyRange)self;

            return(PyInteger.Create(Math.Abs((asPyRange.Max - asPyRange.Min) / asPyRange.Step)));
        }
Beispiel #22
0
 public PyBool __ne__(PyObject other)
 {
     return(!Equals(other));
 }
Beispiel #23
0
 public static PyBool __ne__(PyList self, PyObject other)
 {
     return(!__eq__(self, other));
 }