Inheritance: IronPython.Runtime.DictionaryStorage, ISerializable, IDeserializationCallback
Esempio n. 1
0
 public virtual DictionaryStorage Clone() {
     CommonDictionaryStorage storage = new CommonDictionaryStorage();
     foreach (KeyValuePair<object, object> kvp in GetItems()) {
         storage.Add(kvp.Key, kvp.Value);
     }
     return storage;
 }
Esempio n. 2
0
        public DictionaryStorage CopyTo(DictionaryStorage into)
        {
            Debug.Assert(into != null);

            if (_buckets != null)
            {
                using (new OrderedLocker(this, into)) {
                    CommonDictionaryStorage commonInto = into as CommonDictionaryStorage;
                    if (commonInto != null)
                    {
                        CommonCopyTo(commonInto);
                    }
                    else
                    {
                        UncommonCopyTo(ref into);
                    }
                }
            }

            var nullValue = _nullValue;

            if (nullValue != null)
            {
                into.Add(ref into, null, nullValue.Value);
            }
            return(into);
        }
Esempio n. 3
0
 void ISet.SetData(IEnumerable set)
 {
     _items = new CommonDictionaryStorage();
     foreach (object o in set)
     {
         _items.Add(o, o);
     }
 }
Esempio n. 4
0
 internal SetCollection(IEnumerator setData)
 {
     _items = new CommonDictionaryStorage();
     while (setData.MoveNext())
     {
         add(setData.Current);
     }
 }
Esempio n. 5
0
        internal PythonDictionary(IDictionary dict)
        {
            var storage = new CommonDictionaryStorage();

            foreach (DictionaryEntry de in dict)
            {
                storage.AddNoLock(de.Key, de.Value);
            }
            _storage = storage;
        }
Esempio n. 6
0
        public virtual DictionaryStorage Clone()
        {
            CommonDictionaryStorage storage = new CommonDictionaryStorage();

            foreach (KeyValuePair <object, object> kvp in GetItems())
            {
                storage.Add(kvp.Key, kvp.Value);
            }
            return(storage);
        }
Esempio n. 7
0
        public static PythonTuple Reduce(CommonDictionaryStorage items, PythonType type)
        {
            object[] keys = new object[items.Count];
            int      i    = 0;

            foreach (object key in items.GetKeys())
            {
                keys[i++] = key;
            }
            return(PythonTuple.MakeTuple(type, PythonTuple.MakeTuple(List.FromArrayNoCopy(keys)), null));
        }
Esempio n. 8
0
        private static CommonDictionaryStorage ListToDictionary(object set)
        {
            IEnumerator             setData = PythonOps.GetEnumerator(set);
            CommonDictionaryStorage items   = new CommonDictionaryStorage();

            while (setData.MoveNext())
            {
                object o = setData.Current;
                items.Add(o, o);
            }
            return(items);
        }
 public override void Add(ref DictionaryStorage storage, object key, object value) {
     lock (this) {
         if (storage == this) {
             CommonDictionaryStorage newStorage = new CommonDictionaryStorage();
             newStorage.AddNoLock(key, value);
             storage = newStorage;
             return;
         }
     }
     
     // race, try again...
     storage.Add(ref storage, key, value);
 }
        public DebuggerDictionaryStorage(IDictionary<object, object> data) {
            Debug.Assert(data != null);

            _hidden = new CommonDictionaryStorage();
            foreach (var key in data.Keys) {
                string strKey = key as string;
                if (strKey != null && strKey.Length > 0 && strKey[0] == '$') {
                    _hidden.Add(strKey, null);
                }
            }

            _data = data;
        }
Esempio n. 11
0
        public void __init__(object setData)
        {
            CommonDictionaryStorage newStorage = new CommonDictionaryStorage();

            IEnumerator ie = PythonOps.GetEnumerator(setData);

            while (ie.MoveNext())
            {
                object current = ie.Current;
                newStorage.AddNoLock(current, current);
            }
            _items = newStorage;
        }
        public DebuggerDictionaryStorage(IDictionary <object, object> data)
        {
            Debug.Assert(data != null);

            _hidden = new CommonDictionaryStorage();
            foreach (var key in data.Keys)
            {
                if (key is string strKey && strKey.Length > 0 && strKey[0] == '$')
                {
                    _hidden.Add(strKey, null);
                }
            }

            _data = data;
        }
Esempio n. 13
0
        public override void Add(ref DictionaryStorage storage, object key, object value)
        {
            lock (this) {
                if (storage == this)
                {
                    CommonDictionaryStorage newStorage = new CommonDictionaryStorage();
                    newStorage.AddNoLock(key, value);
                    storage = newStorage;
                    return;
                }
            }

            // race, try again...
            storage.Add(ref storage, key, value);
        }
Esempio n. 14
0
 internal SetIterator(CommonDictionaryStorage items, bool mutable)
 {
     _items = items;
     if (mutable)
     {
         lock (items) {
             _version    = _items.Version;
             _enumerator = items.GetKeys().GetEnumerator();
         }
     }
     else
     {
         _version    = _items.Version;
         _enumerator = items.GetKeys().GetEnumerator();
     }
 }
Esempio n. 15
0
        public AttributesDictionaryStorage(IAttributesCollection data)
        {
            Debug.Assert(data != null);

            _hidden = new CommonDictionaryStorage();
            foreach (var key in data.Keys)
            {
                string strKey = key as string;
                if (strKey != null && strKey.Length > 0 && strKey[0] == '$')
                {
                    _hidden.Add(strKey, null);
                }
            }

            _data = data;
        }
Esempio n. 16
0
        private void Init(params object[] o)
        {
            if (o.Length > 1)
            {
                throw PythonOps.TypeError("set expected at most 1 arguments, got {0}", o.Length);
            }

            _items = new CommonDictionaryStorage();
            if (o.Length != 0)
            {
                IEnumerator setData = PythonOps.GetEnumerator(o[0]);
                while (setData.MoveNext())
                {
                    add(setData.Current);
                }
            }
        }
Esempio n. 17
0
        public override bool Remove(ref DictionaryStorage storage, object key) {
            if (_storage.Contains(key)) {
                lock (this) {
                    if (storage == this) {
                        var newStore = new CommonDictionaryStorage();
                        _storage.CopyTo(newStore);
                        newStore.Remove(key);
                        storage = newStore;
                        return true;
                    }
                }

                // race, try again
                return storage.Remove(ref storage, key);
            }
            
            return false;
        }
Esempio n. 18
0
        public override void CopyTo(DictionaryStorage /*!*/ into)
        {
            Debug.Assert(into != null);

            if (_buckets != null)
            {
                using (new OrderedLocker(this, into)) {
                    CommonDictionaryStorage commonInto = into as CommonDictionaryStorage;
                    if (commonInto != null)
                    {
                        CommonCopyTo(commonInto);
                    }
                    else
                    {
                        UncommonCopyTo(into);
                    }
                }
            }
        }
Esempio n. 19
0
        public override bool Remove(ref DictionaryStorage storage, object key)
        {
            if (_storage.Contains(key))
            {
                lock (this) {
                    if (storage == this)
                    {
                        var newStore = new CommonDictionaryStorage();
                        _storage.CopyTo(newStore);
                        newStore.Remove(key);
                        storage = newStore;
                        return(true);
                    }
                }

                // race, try again
                return(storage.Remove(ref storage, key));
            }

            return(false);
        }
Esempio n. 20
0
        private void CommonCopyTo(CommonDictionaryStorage into)
        {
            if (into._buckets == null)
            {
                into._buckets = new Bucket[_buckets.Length];
            }
            else
            {
                int curSize = into._buckets.Length;
                int newSize = (int)((_count + into._count) / Load) + 2;
                while (curSize < newSize)
                {
                    curSize *= ResizeMultiplier;
                }
                into.EnsureSize(curSize);
            }

            if (into._keyType == null)
            {
                into._keyType  = _keyType;
                into._hashFunc = _hashFunc;
                into._eqFunc   = _eqFunc;
            }
            else if (into._keyType != _keyType)
            {
                into.SetHeterogeneousSites();
            }

            for (int i = 0; i < _buckets.Length; i++)
            {
                Bucket curBucket = _buckets[i];

                if (curBucket.Key != null &&
                    curBucket.Key != _removed &&
                    into.AddWorker(into._buckets, curBucket.Key, curBucket.Value, curBucket.HashCode))
                {
                    into._count++;
                }
            }
        }
Esempio n. 21
0
        internal static FrozenSetCollection Make(object setData)
        {
            FrozenSetCollection fs = setData as FrozenSetCollection;

            if (fs != null)
            {
                // constructing frozen set from frozen set, we return the original frozen set.
                return(fs);
            }

            CommonDictionaryStorage items = ListToDictionary(setData);

            if (items.Count == 0)
            {
                fs = EMPTY;
            }
            else
            {
                fs = new FrozenSetCollection(items);
            }

            return(fs);
        }
Esempio n. 22
0
 public SetCollection()
 {
     _items = new CommonDictionaryStorage();
 }
Esempio n. 23
0
 public ConstantDictionaryStorage(CommonDictionaryStorage storage)
 {
     _storage = storage;
 }
Esempio n. 24
0
        internal static PythonDictionary CertificateToPython(CodeContext context, X509Certificate cert, bool complete) {
            var dict = new CommonDictionaryStorage();

            dict.AddNoLock("notAfter", ToPythonDateFormat(cert.GetExpirationDateString()));
            dict.AddNoLock("subject", IssuerToPython(context, cert.Subject));
            if (complete) {
                dict.AddNoLock("notBefore", ToPythonDateFormat(cert.GetEffectiveDateString()));
                dict.AddNoLock("serialNumber", SerialNumberToPython(cert));
                dict.AddNoLock("version", cert.GetCertHashString());
                dict.AddNoLock("issuer", IssuerToPython(context, cert.Issuer));
            }

            return new PythonDictionary(dict);
        }
        private void CommonCopyTo(CommonDictionaryStorage into) {
            if (into._buckets == null) {
                into._buckets = new Bucket[_buckets.Length];
            } else {
                int curSize = into._buckets.Length;
                while (curSize < _count + into._count) {
                    curSize *= ResizeMultiplier;
                }
                into.EnsureSize(curSize);
            }

            if (into._keyType == null) {
                into._keyType = _keyType;
                into._hashFunc = _hashFunc;
                into._eqFunc = _eqFunc;
            } else if (into._keyType != _keyType) {
                SetHeterogeneousSites();
            }

            for (int i = 0; i < _buckets.Length; i++) {
                Bucket curBucket = _buckets[i];
                while (curBucket != null) {
                    if (AddWorker(into._buckets, curBucket.Key, curBucket.Value, curBucket.HashCode)) {
                        into._count++;
                    }
                    curBucket = curBucket.Next;
                }
            }
        }
Esempio n. 26
0
 public ConstantDictionaryStorage(CommonDictionaryStorage storage) {
     _storage = storage;
 }
Esempio n. 27
0
        private MSAst.Expression ReduceConstant() {
            for (int index = 0; index < _items.Length; index++) {
                SliceExpression slice = _items[index];
                if (!slice.SliceStop.IsConstant || !slice.SliceStart.IsConstant) {
                    return null;
                }
            }

            CommonDictionaryStorage storage = new CommonDictionaryStorage();
            for (int index = 0; index < _items.Length; index++) {
                SliceExpression slice = _items[index];

                storage.AddNoLock(slice.SliceStart.GetConstantValue(), slice.SliceStop.GetConstantValue());
            }


            return Ast.Call(AstMethods.MakeConstantDict, Ast.Constant(new ConstantDictionaryStorage(storage), typeof(object)));
        }
Esempio n. 28
0
 private FrozenSetCollection(CommonDictionaryStorage set)
 {
     _items = set;
 }
Esempio n. 29
0
        public void intersection_update(object s)
        {
            SetCollection set = intersection(s) as SetCollection;

            _items = set._items;
        }
Esempio n. 30
0
 private static void AddSubjectAltNames(CommonDictionaryStorage dict, X509Certificate2 cert2) {
     foreach (var extension in cert2.Extensions) {
         if (extension.Oid.Value != "2.5.29.17") {  // Subject Alternative Name
             continue;
         }
         var altNames = new List<object>();
         var sr = new StringReader(extension.Format(true));
         string line;
         while (null != (line = sr.ReadLine())) {
             line = line.Trim();
             var keyValue = line.Split('=');
             if (keyValue[0] == "DNS Name" && keyValue.Length == 2) {
                 altNames.Add(PythonTuple.MakeTuple("DNS", keyValue[1]));
             }
         }
         dict.AddNoLock("subjectAltName", PythonTuple.MakeTuple(altNames.ToArray()));
         break;
     }
 }