3 uAc@sdZddlmZddlmZddlmZddlmZGddde Z Gdd d ee e Z Gd d d e Z Gd d d e ZGddde eZGddde ZGddde ZGddde ZGddde eZddZdS)z?Classes and functions to easily access DBus introspection data.)absolute_import) ElementTree)StringIO)with_metaclassc@s(eZdZdZiZeddZddZdS) IElemMetazMetaclass for introspection elements. Sets elemname class member automatically from class name if not set explicitly. Registers classes for their element names.cCs>d}x4|D],}|j}||kr.t|r.|d7}||7}q W|S)N_)lowerlen)clsZclsnameelemnamecZc_lowerr#/usr/lib/python3.6/introspection.pyclsname_to_elemname(s  zIElemMeta.clsname_to_elemnamecCs|dkrtj||||Sd|krL|jds6td|tj|dd|d<|d}|tjkrntd||ftj||||}|tj|<|S)NIElemr z;Class '%s' needs to set elemname (or be called 'IElem...'))z4Class '%s' tries to register duplicate elemname '%s')type__new__ startswith TypeErrorrrelemnames_to_classes)r namebasesZdctr klsrrrr3s     zIElemMeta.__new__N)__name__ __module__ __qualname____doc__r classmethodrrrrrrr s rcs@eZdZdZd fdd Zd ddZddZed d ZZ S) rz&Base class for introspection elements.Ncs*tjj|jtjd}tt|j|||S)N)rrgettagsuperrr)r elemparentr) __class__rrrOsz IElem.__new__cs$|_|_fdd|D_dS)Ncsg|]}t|dqS))r$)r).0r )selfrr Wsz"IElem.__init__..)r#r$child_elements)r'r#r$r)r'r__init__TszIElem.__init__cCsZd|jr|jn d|jj|jf}x2|jD](}x"t|jdD]}|d|7}q>Wq*W|S)Nz%s %rz unknown:%s z %s)r r#r!attribr)strsplit)r'sr Zccrrr__str__Ys  z IElem.__str__cCs|jjS)N)r#r,)r'rrrr,asz IElem.attrib)N)N) rrrrrr*r0propertyr, __classcell__rr)r%rrLs  rc@seZdZdZdZdS) IElemUnknownz-Catch-all for unknown introspection elements.N)rrrrr rrrrr3fsr3c@seZdZdZeddZdS)IElemNameMixinz,Mixin for introspection elements with names.cCs |jdS)Nr)r,)r'rrrroszIElemNameMixin.nameN)rrrrr1rrrrrr4lsr4cs"eZdZdZdfdd ZZS) IElemNodezIntrospection node.Ncs(tt|j||dd|jD|_dS)NcSsg|]}t|tr|qSr) isinstancer5)r&r rrrr({sz&IElemNode.__init__..)r"r5r*r)Z child_nodes)r'r#r$)r%rrr*wszIElemNode.__init__)N)rrrrr*r2rr)r%rr5tsr5c@seZdZdZdS)IElemInterfacezIntrospection interface.N)rrrrrrrrr7~sr7c@seZdZdZdS) IElemMethodzIntrospection interface method.N)rrrrrrrrr8sr8c@seZdZdZdS)IElemArgzIntrospection method argument.N)rrrrrrrrr9sr9c@seZdZdZdS) IElemSignalzIntrospection interface signal.N)rrrrrrrrr:sr:cCs.t}t|dst|}|j|}t|}|S)Nread)rhasattrrparser)Zstring_or_fileZtreeZxml_rootZ elem_rootrrr introspects   r>N)rZ __future__rZxml.etree.ElementTreeriorZsixrrrobjectrr3r4r5r7r8r9r:r>rrrrs    ,