a ì)gã@s~dZddlmZmZmZeZddlmZm Z ddl m Z m Z m Z mZGdd„de e ƒZdd„Zdd d „Zdd d „Zdd„ZdS)z*Collection of low-level utility functions.é)Úabsolute_importÚdivisionÚprint_function)Ú binary_typeÚ text_type)ÚHashableÚMappingÚMutableMappingÚSequencec@sXeZdZdZdd„Zdd„Zdd„Zdd „Zd d „Zd d „Z dd„Z dd„Z dd„Z dS)Ú ImmutableDictz!Dictionary that cannot be updatedcOst|i|¤Ž|_dS©N)ÚdictÚ_store)ÚselfÚargsÚkwargs©rúK/usr/lib/python3.9/site-packages/ansible/module_utils/common/collections.pyÚ__init__szImmutableDict.__init__cCs |j|Sr ©r)rÚkeyrrrÚ __getitem__szImmutableDict.__getitem__cCs |j ¡Sr )rÚ__iter__©rrrrrszImmutableDict.__iter__cCs |j ¡Sr )rÚ__len__rrrrrszImmutableDict.__len__cCstt| ¡ƒƒSr )ÚhashÚ frozensetÚitemsrrrrÚ__hash__szImmutableDict.__hash__cCs2z| ¡t|ƒkrWdSWnty,Yn0dS)NTF)rrÚ TypeError)rÚotherrrrÚ__eq__s   zImmutableDict.__eq__cCsd t|jƒ¡S)NzImmutableDict({0}))ÚformatÚreprrrrrrÚ__repr__(szImmutableDict.__repr__cCst|jfi|¤ŽS)aÎ Create an ImmutableDict as a combination of the original and overriding_mapping :arg overriding_mapping: A Mapping of replacement and additional items :return: A copy of the ImmutableDict with key-value pairs from the overriding_mapping added If any of the keys in overriding_mapping are already present in the original ImmutableDict, the overriding_mapping item replaces the one in the original ImmutableDict. )r r)rZoverriding_mappingrrrÚunion+s zImmutableDict.unioncs6t|ƒ‰‡fdd„ˆj ¡Dƒ}t‡fdd„|DƒƒS)aK Create an ImmutableDict as a combination of the original minus keys in subtractive_iterable :arg subtractive_iterable: Any iterable containing keys that should not be present in the new ImmutableDict :return: A copy of the ImmutableDict with keys from the subtractive_iterable removed c3s|]}|ˆvr|VqdSr r©Ú.0Úk)Ú remove_keysrrÚ @óz+ImmutableDict.difference..c3s|]}|ˆj|fVqdSr rr&rrrr*Ar+)rrÚkeysr )rZsubtractive_iterabler,r)r)rrÚ difference7szImmutableDict.differenceN) Ú__name__Ú __module__Ú __qualname__Ú__doc__rrrrrr!r$r%r-rrrrr s  r cCst|ttfƒpt|ddƒS)zCIdentify whether the input has a string-like type (inclding bytes).Z __ENCRYPTED__F)Ú isinstancerrÚgetattr)ÚseqrrrÚ is_stringDsr5FcCs8|st|ƒrdSzt|ƒWdSty2YdS0dS)z*Identify whether the input is an iterable.FTN)r5Úiterr©r4Zinclude_stringsrrrÚ is_iterableJs  r8cCs|st|ƒrdSt|tƒS)zÀIdentify whether the input is a sequence. Strings and bytes are not sequences here, unless ``include_string`` is ``True``. Non-indexable things are never of a sequence type. F)r5r2r r7rrrÚ is_sequenceVs r9cCs8t|ƒstdƒ‚tƒ}|D]}| |d¡d||<q|S)aTReturns a dictionary with the number of appearances of each element of the iterable. Resembles the collections.Counter class functionality. It is meant to be used when the code is run on Python 2.6.* where collections.Counter is not available. It should be deprecated and replaced when support for Python < 2.7 is dropped. z%Argument provided is not an iterableré)r8Ú Exceptionr Úget)r4ZcountersÚelemrrrÚcountds r>N)F)F)r1Z __future__rrrÚtypeZ __metaclass__Zansible.module_utils.sixrrZ/ansible.module_utils.common._collections_compatrrr r r r5r8r9r>rrrrÚs6