Beispiel #1
0
        public static async Task <PyString> __repr__(IInterpreter interpreter, FrameContext context, PyObject self)
        {
            var      asTuple = (PyTuple)self;
            PyString retStr  = PyString.Create("(");

            for (int i = 0; i < asTuple.Values.Length; ++i)
            {
                var pyObj = asTuple.Values[i] as PyObject;
                if (pyObj == null)
                {
                    retStr = (PyString)PyStringClass.__add__(retStr, PyString.Create(asTuple.Values[i].ToString()));
                }
                else
                {
                    var __repr__      = pyObj.__getattribute__(PyClass.__REPR__);
                    var functionToRun = __repr__ as IPyCallable;

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

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

                // Appending commas except on last index
                if (i < asTuple.Values.Length - 1)
                {
                    retStr = (PyString)PyStringClass.__add__(retStr, PyString.Create(", "));
                }
            }
            return((PyString)PyStringClass.__add__(retStr, PyString.Create(")")));
        }
Beispiel #2
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 #3
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("]")));
        }