Provides both helpers for implementing Python dictionaries as well as providing public methods that should be exposed on all dictionary types. Currently these are published on IDictionary<object, object>
示例#1
0
        public object __cmp__(CodeContext context, object other)
        {
            IDictionary <object, object> oth = other as IDictionary <object, object>;

            // CompareTo is allowed to throw (string, int, etc... all do it if they don't get a matching type)
            if (oth == null)
            {
                object len, iteritems;
                if (!PythonOps.TryGetBoundAttr(context, other, "__len__", out len) ||
                    !PythonOps.TryGetBoundAttr(context, other, "iteritems", out iteritems))
                {
                    return(NotImplementedType.Value);
                }

                // user-defined dictionary...
                int lcnt = Count;
                int rcnt = PythonContext.GetContext(context).ConvertToInt32(PythonOps.CallWithContext(context, len));

                if (lcnt != rcnt)
                {
                    return(lcnt > rcnt ? 1 : -1);
                }

                return(DictionaryOps.CompareToWorker(context, this, new List(PythonOps.CallWithContext(context, iteritems))));
            }

            CompareUtil.Push(this, oth);
            try {
                return(DictionaryOps.CompareTo(context, this, oth));
            } finally {
                CompareUtil.Pop(this, oth);
            }
        }
示例#2
0
        internal static int CompareToWorker(CodeContext /*!*/ context, IDictionary <object, object> left, List ritems)
        {
            List litems = DictionaryOps.items(left);

            litems.sort(context);
            ritems.sort(context);

            return(litems.CompareToWorker(ritems));
        }
示例#3
0
 public int __cmp__(CodeContext /*!*/ context, [NotNull] PythonDictionary /*!*/ other)
 {
     CompareUtil.Push(this, other);
     try {
         return(DictionaryOps.CompareTo(context, this, other));
     } finally {
         CompareUtil.Pop(this, other);
     }
 }
示例#4
0
        bool IAttributesCollection.TryGetValue(SymbolId name, out object value)
        {
            if (GetType() != typeof(PythonDictionary) &&
                DictionaryOps.TryGetValueVirtual(DefaultContext.Default, this, SymbolTable.IdToString(name), ref DefaultGetItem, out value))
            {
                return(true);
            }

            // call Dict.TryGetValue to get the real value.
            return(_storage.TryGetValue(SymbolTable.IdToString(name), out value));
        }
示例#5
0
        internal static int CompareTo(CodeContext /*!*/ context, IDictionary <object, object> left, IDictionary <object, object> right)
        {
            int lcnt = left.Count;
            int rcnt = right.Count;

            if (lcnt != rcnt)
            {
                return(lcnt > rcnt ? 1 : -1);
            }

            List ritems = DictionaryOps.items(right);

            return(CompareToWorker(context, left, ritems));
        }
示例#6
0
 public virtual string /*!*/ __repr__(CodeContext /*!*/ context)
 {
     return(DictionaryOps.__repr__(context, this));
 }
示例#7
0
 public void update(CodeContext /*!*/ context, object b)
 {
     DictionaryOps.update(context, this, b);
 }
示例#8
0
 public void update(CodeContext /*!*/ context, object b, [ParamDictionary] IDictionary <object, object> f)
 {
     DictionaryOps.update(context, this, b);
     DictionaryOps.update(context, this, f);
 }
示例#9
0
 public object setdefault(object key)
 {
     return(DictionaryOps.setdefault(this, key));
 }
示例#10
0
 public object setdefault(object key, object defaultValue)
 {
     return(DictionaryOps.setdefault(this, key, defaultValue));
 }
示例#11
0
 public PythonTuple popitem()
 {
     return(DictionaryOps.popitem(this));
 }
示例#12
0
 public object pop(object key, object defaultValue)
 {
     return(DictionaryOps.pop(this, key, defaultValue));
 }
示例#13
0
 public object pop(object key)
 {
     return(DictionaryOps.pop(this, key));
 }
示例#14
0
 public bool has_key(object key)
 {
     return(DictionaryOps.has_key(this, key));
 }
示例#15
0
 public object get(object key)
 {
     return(DictionaryOps.get(this, key));
 }