Exemplo n.º 1
0
        public static PyObject loadObject(BinaryReader reader)
        {
            int      pos = (int)reader.BaseStream.Position;
            PyObject ret;
            int      type = reader.ReadByte();

            switch (type)
            {
            case (int)ObjectType.False:
            case (int)ObjectType.None:
            case (int)ObjectType.True:
                ret = new PyObject();
                break;

            case (int)ObjectType.Code:
                ret = new CodeBlock();
                break;

            case (int)ObjectType.StringRef:
                ret = new PyStringRef();
                break;

            case (int)ObjectType.String:
            case (int)ObjectType.UnicodeString:
            case (int)ObjectType.Interned:
                ret = new PyString();
                break;

            case (int)ObjectType.Tuple:
                ret = new PyTuple();
                break;

            case (int)ObjectType.Int:
                ret = new PyInt();
                break;

            case 103:
                // Not 100% sure this is correct but it seams to work.
                ret = new PyLong();
                break;

            default:
                return(null);
            }
            ret.type = (ObjectType)type;
            if (!ret.load(reader))
            {
                return(null);
            }
            return(ret);
        }
Exemplo n.º 2
0
 public override bool Equals(PyObject other)
 {
     if (other == null)
     {
         return(false);
     }
     if (other is PyString)
     {
         return((other as PyString).str == str);
     }
     if (other is PyInt)
     {
         PyInt ov = other as PyInt;
         return(ov.value.ToString() == str);
     }
     if (other is PyLong)
     {
         PyLong ov = other as PyLong;
         return(ov.value.ToString() == str);
     }
     return(false);
 }