g^dZddlZddlZddlZddlmZmZmZddlZde dee e ffdZ de dee e ffdZ de fdZde dee e e e ffd Zde dee e ffd Zde dee e ffd Zde fd Zde dee e ffd Zde de fdZde dee e e e ffdZde dee e e e ffdZde dee e e e ffdZde dee e ffdZde de fdZde de fdZde dee e ffdZdZGddejZGddejZGddej Z!Gdd e!e!Z"Gd"d#e"Z#Gd$d%e#Z$Gd&d'e#Z%Gd(d)eZ&Gd*d+e#e&!Z'Gd,d-e#Z(Gd.d/e!Z)d0Z*dS)1z6TLV parser/encoder library supporting various formats.N)ListTupleOptionalbinaryreturnc|ddvrtd|d|fz|ddkr,|ddz|ddzz|dz}||d d fS|dd krd |fS|d}||dd fS) =Parse a single Tag according to ETSI TS 101 220 Section 7.1.1rr Found illegal value 0x%02x in %sNr ) ValueError)rtags [/home/jenkins/workspace/simtester-sanitize/venv/lib/python3.11/site-packages/osmocom/tlv.pycomprehensiontlv_parse_tag_rawrs ay&&&; )V,-.. . ayDQi2oq Q.:VABBZ  d  V|QiVABBZ  cF|ddvrtd|d|fz|ddkr@|ddzdz}||dz}t|ddz}||d |d d fS|ddz}t|ddz}||d |dd fS) r rr r rrrrr ) comprehensionrrN)rbool)rrcomprs rcomprehensiontlv_parse_tagr.s ay&&&; )V,-.. . ayDay4A% vayVAY%&&"'44fQRRjAAQi$VAY%&&"'44fQRRjAArct|trt|dko|dz}||d}|dd}|ddvs |ddkrP|ddz}|ddz d z}|r|dz}d |d d z|d d zS|d}|r|dz}|d d S) z>Encode a single Tag according to ETSI TS 101 220 Section 7.1.1r r )rrrFrr rrrbig) isinstanceintrgetto_bytes)rrbyte3byte2rets rcomprehensiontlv_encode_tagr(?s#s3S4Z.C$J//E22 GGOU + +E 5z'''3u:+<+<E T!UqD(   TME5111ENN1e4L4LLL%j   4KC||Au%%%rc~t|\}}t|\}}|d|}||d}||||fSzParse a single TLV IE at the start of the given binary data. Args: binary : binary input data of BER-TLV length field Returns: Tuple of (tag:dict, len:int, remainder:bytes) N)rbertlv_parse_lenrtagdict remainderlengthvalues rcomprehensiontlv_parse_oner1VsS6f==Wi*955VY gvg E&''"I VUI ..rcR|ddkrt|dks|ddkr|ddkrd|fS|ddz}|dkr|d|ddfS|d}d}d}|s0t||dz }|d z}|||z}|dz }|0|||dfS) zGet a single raw Tag from start of input according to ITU-T X.690 8.1.2 Args: binary : binary input data of BER-TLV length field Returns: Tuple of (tag:int, remainder:bytes) rr rNFr r)lenr)rrilasts rbertlv_parse_tag_rawr8hsayDS[[A--d1B1BvayTXGXGXV| )d C byyay&*$$Qi  F1I,---D AIC 6!9 C FA   F122Jrc |ddz }t|ddz}|ddz}|dkr|||d|ddfSd}d}d }|s3t||d z }|d z}|||d zz}|dz }|3|||d||dfS) zParse a single Tag value according to ITU-T X.690 8.1.2 Args: binary : binary input data of BER-TLV length field Returns: Tuple of ({class:int, constructed:bool, tag:int}, remainder:bytes) r r3r4)class constructedrrNFr r)r)rclsr=rr6r7s rbertlv_parse_tagr@s )q.Cvay4'((K )d C byyk#FFqrr SS  F1I,---D AIC 6!9t# #C FA   k#FFqrr SSrc.dtdtttffd}dtdtfd}t|tr1||}t||d\}}|d}|d}|d}|d kr'|d z}|r|d z}||d zd zz}t |gSd }|r|d z}||d zd zz}t |g}|} || \}} | r|dz}|t |gz }| sn,|S)z=Encode a single Tag value according to ITU-T X.690 8.1.2 inprcp|}|dkrd}n|}|||z z }||||z zz}||fS)zRGet top 7 bits of integer. Returns those 7 bits as integer and the remaining LSBs.r>) bit_length)rB remain_bitsbitcntoutpr.s r get_top7_bitsz(bertlv_encode_tag..get_top7_bitssXnn&& !  FF F{V+,S[6%9:;; Yrc0d}|dz }|r |dz }|dz }| |S)zAcount the number of bytes require to represent the given integer.rr)rBr6s rcount_int_bytesz*bertlv_encode_tag..count_int_bytess; Qh  FA(C rr rr=r<r4r3r;rr:Tr )r"rr!r@r$bytes) trHrKtag_size _remainderrr=r? tag_bytesremains rbertlv_encode_tagrRs} 3 5c?    SS!SF"?1%%(He)D)DEE : E(CM"K G*C byy $J   IA cAg!^aSzz    IA cAg!^1#JJ  % f--IAv T  s #I   rc|ddkr|d|ddfS|ddz}d}t||dzkrdStdd|zD]}|dz}|||z}||d|zdfS)zParse a single Length value according to ITU-T X.690 8.1.3; only the definite form is supported here. Args: binary : binary input data of BER-TLV length field Returns: Tuple of (length, remainder) rr rNr)rrr)r5range)r num_len_octr/r6s rr+r+say4q 6!"":&&Qi$&  v;;q ( (8q!K-((  A qLF fQi FFq}~~.//rr/cP|dkr|ddS|dkrd|ddzS|dkrd|ddzS|d krd |d dzS|d krd |ddzStd)zEncode a single Length value according to ITU-T X.690 8.1.3; only the definite form is supported here. Args: length : length value to be encoded Returns: binary output data of BER-TLV length field r rr r rirlLength > 32bits not supportedr$rr/s rbertlv_encode_lenr`s}}q%((( 4E2222 6  E2222 8  E2222 :  E22228999rc~t|\}}t|\}}|d|}||d}||||fSr*)r@r+r,s rbertlv_parse_onerbsS,F33Wi*955VY gvg E&''"I VUI ..rc~t|\}}t|\}}|d|}||d}||||fS)zParse a single TLV IE at the start of the given binary data; return tag as raw integer. Args: binary : binary input data of BER-TLV length field Returns: Tuple of (tag:int, len:int, remainder:bytes) N)r8r+)rrr.r/r0s rbertlv_parse_one_rawtagrdsS,F33S)*955VY gvg E&''"I  **rct|\}}t|\}}t|t|z }|d||d|z}||d}||||fS)zReturn one single [encoded] TLV IE at the start of the given binary data. Args: binary : binary input data of BER-TLV length field Returns: Tuple of (tag:int, len:int, tlv:bytes, remainder:bytes) N)r8r+r5)rrr.r/ tl_lengthr0s rbertlv_return_one_rawtlvrgsw,F33S)*955VYF c)nn,I :I: 7F7!3 3E&''"I  **rc\t|ddd|ddfSNrr )r" from_bytesrs rdgi_parse_tag_rawrl s+ >>&!*e , ,fQRRj 88rrMc.|ddSrir$)rMs rdgi_encode_tagro$s ::a  rc|dkr|ddS|dkrd|ddzStd)zEncode a single Length value according to GlobalPlatform Systems Scripting Language Specification v1.1.0 Annex B. Args: length : length value to be encoded Returns: binary output data of encoded length field r rr rXrr]r^r_s rdgi_encode_lenrr'sT||q%((( 6  E22228999rc|ddkr3t|dksJ|ddz|dz|ddfS|d|ddfS)zParse a single Length value according to GlobalPlatform Systems Scripting Language Specification v1.1.0 Annex B. Args: binary : binary input data of BER-TLV length field Returns: Tuple of (length, remainder) rr rrrrNr5rks r dgi_parse_lenru6seayC6{{aa6!9,vabbz99ay&*$$rc~tjdd|}tjdd|S)Nz(.)([A-Z][a-z]+)z\1_\2z([a-z0-9])([A-Z]))resublower)names rcamel_to_snaker{Is7 6$h 5 5D 6%x 6 6 < < > >>rc"eZdZdZfdZxZS)TlvMetaa Metaclass which we use to set some class variables at the time of defining a subclass. This allows us to create subclasses for each TLV/IE type, where the class represents fixed parameters like the tag/type and instances of it represent the actual TLV data.c t||||}|d|dd|_|d|dd|_|d|dd}|)t j|rt|tr||_ n%d|z}t|tfd|i}||_ |S)Nrdescnestedzauto_collection_%s) super__new__r#rrinspectisclass issubclassTLV_IE_Collectionnested_collection_clstype) mcsrzbases namespacekwargsxrr? __class__s rrzTlvMeta.__new__Qs GGOOCui 8 8 eVZZt%<%<==vvzz&$'?'?@@xHd)C)CDD >W_V44>FL]9^9^>&,A # #(40Dt/1Hf3EFFC&)A #r__name__ __module__ __qualname____doc__r __classcell__rs@rr}r}MsDWWrr}c"eZdZdZfdZxZS)TlvCollectionMetaaMetaclass which we use to set some class variables at the time of defining a subclass. This allows us to create subclasses for each Collection type, where the class represents fixed parameters like the nested IE classes and instances of it represent the actual TLV data.c t||||}|d|dd|_|S)Nr)rrr#possible_nestedrrzrrrrrs rrzTlvCollectionMeta.__new__hsG GGOOCui 8 8%MM(FJJx4N4NOOrrrs@rrrdsD``rrcTeZdZdZ dZifdedefdZdZifdedefdZ defd Z dS) TranscodableNc0d|_d|_d|_dSN)encodeddecoded _constructselfs r__init__zTranscodable.__init__ws  rcontextrc0|jd}n|jr,tj|j|j|}nQ|jjr1tj|jj|j|}n|}||_|S)z{Convert from internal representation to binary bytes. Store the binary result in the internal state and return it.Nr)rrosmocom constructbuild_constructr _to_bytesr)rrdos rr$zTranscodable.to_bytes|s < BB _ ""224?DLRYZZBB ^ & ""224>3Ldl\cddBB!!B  rcJtdt|jz)Nz %s._to_bytesNotImplementedErrorrrrs rrzTranscodable._to_bytess!.4::3F"FGGGrrc\||_|jdkrd|_n|jr-tj|j|||_nX|jjr2tj|jj|||_n|||_|jS)z{Convert from binary bytes to internal representation. Store the decoded result in the internal state and return it.rNr)rrrrrparse_constructr _from_bytesrrrs rrjzTranscodable.from_bytess <3  DLL _ 0",<d|jD}t|jdd|dSt|jd|jdS)z>Return a string representing the [nested] IE data (for print).c,g|]}t|SrJrepr.0rs r zIE.__repr__..s:::q477:::r(,))r5rrrjoinrr member_strss r__repr__z IE.__repr__sv t}   B::DM:::K#Dzz222CHH[4I4I4I4IJ J#Dzz222DLLLA ArcZt|jrd|jDS|jS)aReturn a JSON-serializable dict representing just the [nested] value portion of the IE data. This does not include any indication of the type of 'self', so the resulting dict alone will be insufficient ot recreate an object from it without additional type information.c6g|]}|SrJto_dictrs rrz"IE.to_val_dict..s 777AAIIKK777r)r5rrrs r to_val_dictzIE.to_val_dicts4 t}   77777 7< rcr|jr!|j||_dSg|_||_dS)a#Set the IE internal decoded representation to data from the argument. If this is a nested IE, the child IE instance list is re-created. This method is symmetrical to to_val_dict() aboe, i.e. there is no outer dict containig the snake-reformatted type name of 'self'.N)r from_dictrr)rrs r from_val_dictzIE.from_val_dicts=  ! # 2<?? G++*'''SdSdeff f 7#4566666rcLtt|jdkS)z-Is this IE constructed by further nested IEs?r)rr5rrs ris_constructedzIE.is_constructedsC &&*+++rrrcdS)zEConvert the internal representation to entire IE including IE header.NrJrrs rto_iezIE.to_ierc|r'd}|jD]}|||z }|St|S)zHConvert the internal representation *of the value part* to binary bytes.rr)rrrrr$)rroutcrs rr$z IE.to_bytessg     5C] 0 0qwwww///J77##G#44 4rrc|jr#|j|||_dSg|_t||S)zDParse *the value part* from binary bytes to internal representation.rN)rrjrr)rrrrs rrjz IE.from_bytessS  ! ; 2==b'=RRDMMMDM77%%b'%:: :rrzcttfd|j}t|dkrt dzt|dkr|dSdS)zReturn a child IE instance of given snake-case/json type name. This only works in case there is no more than one child IE of the given type.cNtt|jkSr)r{rr)rrzs rz"IE.child_by_name..sQ8H)I)IT)Qrr'There are multiple children of class %srNlistfilterrr5KeyError)rrzrs ` r child_by_namezIE.child_by_namesrQQQQSWS`aabb x==1  DtKLL L ]]a  A;  rcttfd|j}t|dkrt dzt|dkr|dSdS)zReturn a child IE instance of given type (class). This only works in case there is no more than one child IE of the given type.c$t|Sr)r!)rr?s rrz"IE.child_by_type..sAs););rrrrNr)rr?rs ` r child_by_typezIE.child_by_typesp;;;;T]KKLL x==1  DsJKK K ]]a  A;  r)rrrrrrrrrrrrrrabcabstractmethodrLrr$rjstrrrrrrs@rrrs00! C33333BBB    # # #III 7 7 7 7 7,,, $&TTTT5TTTT(* 5 5 5e 5 5 5 5 5 557;;U;T;;;;;;#(4.HTNrr) metaclasscBeZdZdZdefdZeejde de ee ffdZ eejde de ee ffdZ ejde fdZ ejde de fd Zifd efd Zifd efd Zdefd Zifde d efdZdS)TLV_IEz>Abstract base class for various TLV type Information Elements.rc|jS)z>Compute the tag (sometimes the tag encodes part of the value).rrs r _compute_tagzTLV_IE._compute_tags xrrcdS)zBObtain the raw TAG at the start of the bytes provided by the user.NrJr?rs r_parse_tag_rawzTLV_IE._parse_tag_rawrrcdS)zIObtain the length encoded at the start of the bytes provided by the user.NrJrs r _parse_lenzTLV_IE._parse_lenrrcdS)zMEncode the tag part. Must be provided by derived (TLV format specific) class.NrJrs r _encode_tagzTLV_IE._encode_tag rrvalcdS)zxEncode the length part assuming a certain binary value. Must be provided by derived (TLV format specific) class.NrJrrs r _encode_lenzTLV_IE._encode_len$rrrc.||SNr)to_tlvrs rrz TLV_IE.to_ie)s{{7{+++rc||}|||z|zS)z8Convert the internal representation to binary TLV bytes.r)r$rrrrrs rrz TLV_IE.to_tlv,s?mmGm,,!!D$4$4S$9$99C??rc2||kS)z/Is the given rawtag compatible with this class?r)rrawtags ris_tag_compatiblezTLV_IE.is_tag_compatible1s**,,,,rcrt|dkridfS|j|\}}|rc||st |d|d|j|j|\}}|d|}||d}n|}d}|||}||fS)Nrrz: Encountered tag z! doesn't match our supported tag r)r5rrrrrrrj)rrrrr.r/r0decs rfrom_tlvzTLV_IE.from_tlv5s r77a<<s7N"n;;B??  ))&11 ; "&$$":;;;"&.";";I"F"F VYgvg&E!&''*IIEIooeWo55I~rN)rrrrr"r classmethodrrrLrrrrrrrrrrr rJrrrrsHHcQQ%U *;QQQ[QXEXeCJ&7XXX[X \U\\\\ 0u00000%',,T,,,,&(@@d@@@@ -4----3554rrceZdZdZededeeeffdZededee effdZ ededeeeffdZ defdZ dZ ifd e fd Zd S) COMPACT_TLV_IEz5TLV_IE formatted as COMPACT-TLV described in ISO 7816rrc|ddz |fS)Nrr\rJrs rrzCOMPACT_TLV_IE._parse_tag_rawJs!uz2~rc>||\}}d|i|fS)Nr)r)r?rrr.s r _decode_tagzCOMPACT_TLV_IE._decode_tagNs)..r22 v ))rc,|ddz|ddfS)NrrrJrs rrzCOMPACT_TLV_IE._parse_lenSs!us{BqrrF""rctzQNot needed as we override the to_tlv() method to encode tag+length into one byte.rrs rrzCOMPACT_TLV_IE._encode_tagW!!rctrrrs rrzCOMPACT_TLV_IE._encode_len[rrrc||}t|jdzt|dzzg|zS)Nrr\r)r$rLrr5rs rrzCOMPACT_TLV_IE.to_tlv_s@mmGm,,tx1}SC89::S@@rN)rrrrr rLrr"rrrrrrrrJrrr r Gs??%U *;[*U*uT5['9***[*#E#eCJ&7###[#"U"""""""&(AAdAAAAAArr ceZdZdZededeeeffdZededee effdZ ededee effdZ defdZ dedefd Z d S) BER_TLV_IEz=TLV_IE formatted as ASN.1 BER described in ITU-T X.690 8.1.2.rrc t|Sr)r@rs rrzBER_TLV_IE._decode_tagg###rc t|Sr)r8rs rrzBER_TLV_IE._parse_tag_rawks#B'''rc t|Srr+rs rrzBER_TLV_IE._parse_lenorrcDt|Sr)rRrrs rrzBER_TLV_IE._encode_tagss !2!2!4!4555rrc:tt|Srr`r5rs rrzBER_TLV_IE._encode_lenv S***rN)rrrrr rLrrrr"rrrrrJrrrrdsGG$U$uT5['9$$$[$((%U *;((([($E$eCJ&7$$$[$6U6666+u+++++++rrceZdZfdZxZS) ComprTlvMetac @tj||||fi|}|jrx|jdkr7|jdzdkr)td||jfz|jdz|_n6|jdzdkr(td||jfz|jdz|_|S)Nr irzBFixing up COMPR_TLV_IE class %s: tag=0x%x has no comprehension bitr )rrrprintrs rrzComprTlvMeta.__new__{s EGGOCui B B6 B B 5 %ut||! 3 3Z^bdedi]jjkkk""Z^bdedi]jjkkk r)rrrrrrs@rr%r%zs8         rr%ceZdZdZfdZededeeeffdZ ededee effdZ ededee effdZ de de fd Zdefd Zd edefd ZxZS) COMPR_TLV_IEzETLV_IE formated as COMPREHENSION-TLV as described in ETSI TS 101 220.c Htjdi|d|_dS)NFrJ)rrrrs rrzCOMPR_TLV_IE.__init__s.""6""""rrrc t|Sr)rrs rrzCOMPR_TLV_IE._decode_tags)"---rc t|Sr)rrs rrzCOMPR_TLV_IE._parse_tag_raws-b111rc t|Srrrs rrzCOMPR_TLV_IE._parse_lenrrrcf|}|dkr |dz|dzkS|dz|dzkS)zdOverride is_tag_compatible as we need to mask out the comprehension bit when doing compares.r irr)rrctags rrzCOMPR_TLV_IE.is_tag_compatiblesD  "" $;;&=FVO3 3$;&4-/ /rcDt|Sr)r(rrs rrzCOMPR_TLV_IE._encode_tags*4+<+<+>+>???rrc:tt|Srr"rs rrzCOMPR_TLV_IE._encode_lenr#r)rrrrrr rLrrrr"rrrrrrrrs@rr)r)sGOO#####.U.uT5['9...[.22%U *;222[2$E$eCJ&7$$$[$000000@U@@@@+u+++++++++rr)ceZdZdZededeeeffdZededeeeffdZ defdZ dedefdZ d S) DGI_TLV_IEz[TLV_IE formated as GlobalPlatform Systems Scripting Language Specification v1.1.0 Annex B.rrc t|Sr)rlrs rrzDGI_TLV_IE._parse_tag_raws $$$rc t|Sr)rurs rrzDGI_TLV_IE._parse_lensR   rcDt|Sr)rorrs rrzDGI_TLV_IE._encode_tagsd//11222rrc:tt|Sr)rrr5rs rrzDGI_TLV_IE._encode_lensc#hh'''rN) rrrrr rLrr"rrrrrJrrr3r3see%%%U *;%%%[%!E!eCJ&7!!![!3U3333(u(((((((rr3ceZdZdZgZddZdZdZdZifde de d e e fd Z d e e d e e fd Zd Zifde fdZifde fdZifde fdZdS)rzA TLV_IE_Collection consists of multiple TLV_IE classes identified by their tags. A given encoded DO may contain any of them in any order, and may contain multiple instances of each DO.Nc ||_|d|j|_i|_i|_d|jD|_d|jD|_|dg|_d|_dS)Nrci|] }|j| SrJrrms r z.TLV_IE_Collection.__init__..s>>>Aqua>>>rc8i|]}t|j|SrJ)r{rr;s rr=z.TLV_IE_Collection.__init__..s$TTT!qz : :ATTTrr)rr#rmembersmembers_by_tagmembers_by_namerr)rrrs rrzTLV_IE_Collection.__init__s zz(D,@AA  !>>>>>TTt|TTT :r22  rc~d|jD}t|jdd|dS)Nc,g|]}t|SrJ)rrs rrz-TLV_IE_Collection.__str__..s444!s1vv444rrrr)r?rrrrs r__str__zTLV_IE_Collection.__str__sC44t|444 ::...0E0E0E0EFFrcdd|jD}|jdd|dS)Nc,g|]}t|SrJrrs rrz.TLV_IE_Collection.__repr__..s5551tAww555rrrr)r?rrrs rrzTLV_IE_Collection.__repr__s:55 555 >>>388K+@+@+@+@AArct|tr%|j|jz}t|j|St j|r4t |trt|j|j|gzSt)zFExtending TLV_IE_Collections with other TLV_IE_Collections or TLV_IEs.)r) r!rr?rrrrr TypeError)rotherr?s r__add__zTLV_IE_Collection.__add__s~ e. / / lU]2G$TYw??? ? _U # #  5&(A(A $TYt|ug7MNNN NOrrrrc||_g}|}tt|j}t |r||d<||\}}|nt|tr|dz}||jvrG|j|}|} | ||\} }| | nud|j j |fz} t| |j f|gdd}d|_d|_|} | ||\} }| | t |||_|S) zCreate a list of TLV_IEs from the collection based on binary input data. Args: binary : binary bytes of encoded data Returns: list of instances of TLV_IE sub-classes containing parsed data siblingsNr rz unknown_%s_%X)rrrc.d|iSNraw)hex)sas rrz.TLV_IE_Collection.from_bytes..squuww/?rcLt|jdSrN)rLfromhexr)rQs rrz.TLV_IE_Collection.from_bytes..s%-- %8H*I*Ir)rnextiterr@valuesr5rrr)r append__base__rrrrr) rrrresr.firstr_rr?inst_decrzs rrjzTLV_IE_Collection.from_bytess  T$-44667788)nn !"%GJ **955GC{%.. !Djd))))#.suu"&-- 7-"K"Ki 4    '%.*A3)GG4%.!2CTVNR5T5TUU"?"? I I suu"&-- 7-"K"Ki 4   1)nn !2  rrc Vg}|D]}|D]}||jvrJ|j|}|}||||i||Ut |d|d|d|j||_|S)zCreate a list of TLV_IE instances from the collection based on an array of dicts, where they key indicates the name of the TLV_IE subclass to use.z: Unknown TLV Class z in z ; expected )keysrArrXrr)rrrZr6kr?r]s rrzTLV_IE_Collection.from_dicts V VAVVXX V V,,,.q1C355DNNAqt9---JJt$$$$$&*ddAAAwww8L8Q8Q8S8S8S&UVVV V  rc$d|jDS)Nc6g|]}|SrJrrs rrz-TLV_IE_Collection.to_dict..'s 333 333r)rrs rrzTLV_IE_Collection.to_dict$s43T]3333rcdd}|j|d<|jD]}|||z }|S)NrrLr)rr)rrrrs rr$zTLV_IE_Collection.to_bytes)sC"m  - -A 188G8,, ,CC rc0|||Sr)rjrs rr zTLV_IE_Collection.from_tlv0sr7333rc.||Srrnrs rrzTLV_IE_Collection.to_tlv3s}}W}---rr)rrrrrrrDrrJrLrrrrjrrr$r rrJrrrrsLO    GGGBBB   9;''''tF|''''RdV ,444 (*,.44D4444&(..d......rrcd}d}t|tr{||rd||rYi}|D]4}t|d}||||<5|}d|DSd|DSt|trd|DS|S)zhierarchically flatten each list-of-dicts into a single dict. This is useful to make the output of hierarchical TLV decoder structures flatter and more easy to read.c@|D]}t|tsdSdS)NFT)r!r)les rare_all_elements_dictz1flatten_dict_lists..are_all_elements_dict:s4  Aa&& uu trcZd|D}t|t|kS)Nc\h|])}t|d*S)r)rr`rs r zBflatten_dict_lists..are_elements_unique..As+666QtAFFHH~~a(666rrt)lod set_of_keyss rare_elements_uniquez/flatten_dict_lists..are_elements_unique@s.66#666 3xx3{++++rrc4i|]\}}|t|SrJflatten_dict_listsrravs rr=z&flatten_dict_lists..Ms'CCC!A(++CCCrc,g|]}t|SrJrsrs rrz&flatten_dict_lists..Os!777a&q))777rc4i|]\}}|t|SrJrsrus rr=z&flatten_dict_lists..Qs'???CAa$Q''???r)r!rr`itemsr)rBrkrqnewdictrjkeys rrtrt7s ,,,#t  % % 8*=*=c*B*B 8G & &16688nnQ' v CCCsyy{{CCC C773777 7 C  ??399;;???? r)+rrrrwtypingrrrrrLr"rrrr(r1r8r@rRr+r`rbrdrgrlrorrrur{ABCMetar}rABCrrrr rr%r)r3rrtrJrrrs<<$ (((((((((( !5!U3:5F!!!! BuBtU{1CBBBB"&&&&&. /u /tS%7N1O / / / /$5e+<0TUTuT5['9TTTT.2E2222h0U0uS%Z'80000(:c:e::::* /U /uT3u-D'E / / / / +E +eCeU4J.K + + + + +U +uS#ue5K/L + + + +$9e9c5j(99999 c e     :3 :5 : : : : %% %E#u*$5 % % % %&???ck.        .J.J.J.J.J37.J.J.Jbkkkkkkkkk\55555R555pAAAAAVAAA:++++++++,     7    + + + + +6\ + + + +F(((((((($w.w.w.w.w."3w.w.w.w.tr