Inheritance: IronPython.Runtime.DictionaryStorage, ISerializable, IDeserializationCallback
コード例 #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;
 }
コード例 #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);
        }
コード例 #3
0
ファイル: Set.cs プロジェクト: rudimk/dlr-dotnet
 void ISet.SetData(IEnumerable set)
 {
     _items = new CommonDictionaryStorage();
     foreach (object o in set)
     {
         _items.Add(o, o);
     }
 }
コード例 #4
0
ファイル: Set.cs プロジェクト: rudimk/dlr-dotnet
 internal SetCollection(IEnumerator setData)
 {
     _items = new CommonDictionaryStorage();
     while (setData.MoveNext())
     {
         add(setData.Current);
     }
 }
コード例 #5
0
        internal PythonDictionary(IDictionary dict)
        {
            var storage = new CommonDictionaryStorage();

            foreach (DictionaryEntry de in dict)
            {
                storage.AddNoLock(de.Key, de.Value);
            }
            _storage = storage;
        }
コード例 #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);
        }
コード例 #7
0
ファイル: Set.cs プロジェクト: rudimk/dlr-dotnet
        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));
        }
コード例 #8
0
ファイル: Set.cs プロジェクト: rudimk/dlr-dotnet
        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);
        }
コード例 #9
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);
 }
コード例 #10
0
        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;
        }
コード例 #11
0
ファイル: Set.cs プロジェクト: rudimk/dlr-dotnet
        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;
        }
コード例 #12
0
        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;
        }
コード例 #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);
        }
コード例 #14
0
ファイル: Set.cs プロジェクト: rudimk/dlr-dotnet
 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();
     }
 }
コード例 #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;
        }
コード例 #16
0
ファイル: Set.cs プロジェクト: rudimk/dlr-dotnet
        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);
                }
            }
        }
コード例 #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;
        }
コード例 #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);
                    }
                }
            }
        }
コード例 #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);
        }
コード例 #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++;
                }
            }
        }
コード例 #21
0
ファイル: Set.cs プロジェクト: rudimk/dlr-dotnet
        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);
        }
コード例 #22
0
ファイル: Set.cs プロジェクト: rudimk/dlr-dotnet
 public SetCollection()
 {
     _items = new CommonDictionaryStorage();
 }
コード例 #23
0
 public ConstantDictionaryStorage(CommonDictionaryStorage storage)
 {
     _storage = storage;
 }
コード例 #24
0
ファイル: _ssl.cs プロジェクト: kevinkeeney/ironruby
        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);
        }
コード例 #25
0
        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;
                }
            }
        }
コード例 #26
0
 public ConstantDictionaryStorage(CommonDictionaryStorage storage) {
     _storage = storage;
 }
コード例 #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)));
        }
コード例 #28
0
ファイル: Set.cs プロジェクト: rudimk/dlr-dotnet
 private FrozenSetCollection(CommonDictionaryStorage set)
 {
     _items = set;
 }
コード例 #29
0
ファイル: Set.cs プロジェクト: rudimk/dlr-dotnet
        public void intersection_update(object s)
        {
            SetCollection set = intersection(s) as SetCollection;

            _items = set._items;
        }
コード例 #30
0
ファイル: _ssl.cs プロジェクト: paweljasinski/ironpython3
 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;
     }
 }