a F `#@sTddlmZddlmZgdZGdddeZGdddeZGdd d eZ d S) ) namedtuple) XMLParser)DBusSpecificationErrorDBusSpecificationDBusSpecificationParserc@seZdZdZdS)rz,Exception for the DBus specification errors.N)__name__ __module__ __qualname____doc__r r 8/usr/lib/python3.9/site-packages/dasbus/specification.pyr#src@seZdZdZdZdZdZdZdZdZ dZ e d gd Z e d gd Z e d gdZdgZeddZddZeddZeddZddZddZdS)rzDBus XML specification.inoutreadwriteZ readwritereturna Signalnameinterface_nametypeMethodrrZin_typeZout_typePropertyrrreadablewritabler_memberscCs t||S)z.Return a DBus specification for the given XML.)rparse_specification)clsxmlr r r from_xmlpszDBusSpecification.from_xmlcCs i|_dS)z Create a new DBus specification.N)rselfr r r __init__uszDBusSpecification.__init__cCstt|jS)z%Interfaces of the DBus specification.)listdictrkeysr"r r r interfacesyszDBusSpecification.interfacescCst|jS)z"Members of the DBus specification.)r%rvaluesr"r r r members~szDBusSpecification.memberscCs||j|j|jf<dS)z!Add a member of a DBus interface.N)rrr)r#memberr r r add_memberszDBusSpecification.add_membercCs8z|j||fWSty"Yn0td||dS)z!Get a member of a DBus interface.z)DBus specification has no member '{}.{}'.N)rKeyErrorrformat)r#r member_namer r r get_members zDBusSpecification.get_memberN)rrr r DIRECTION_IN DIRECTION_OUT ACCESS_READ ACCESS_WRITEACCESS_READWRITEZRETURN_PARAMETERSTANDARD_INTERFACESrrrr __slots__ classmethodr!r$propertyr(r*r,r0r r r r r(s*&    rc@sleZdZdZeZeefddZeddZ eddZ edd Z ed d Z ed d Z eddZdS)rz)Class for parsing DBus XML specification.cCs$|}||tj||||S)zGenerate a representation of a DBus XML specification. :param xml: the XML specification to parse :param factory: the DBus specification factory :return: a representation od the DBus specification ) _parse_xmlrr6)rr factory specificationr r r rs z+DBusSpecificationParser.parse_specificationcCs4|j|}|D]}|j|s"q|||qdS)zParse the given XML.N) xml_parserZxml_to_elementZ is_interface_parse_interface)rr<r Znodeinterface_elementr r r r:s   z"DBusSpecificationParser._parse_xmlcCst|j|}|D]^}|j|r.|||}n6|j|rH|||}n|j|r|||}nq||q|S)z8Parse the interface element from the DBus specification.) r=get_nameZ is_property_parse_propertyZ is_signal _parse_signalZ is_method _parse_methodr,)rr<r?rZmember_elementr+r r r r>s     z(DBusSpecificationParser._parse_interfacecCsX|j|}|j|}|j|}|tjtjfv}|tjtjfv}tj|||||dS)z7Parse the property element from the DBus specification.r) r=r@get_typeZ get_accessrr3r5r4r)rrZproperty_elementZ property_nameZ property_typeZproperty_accessrrr r r rAs$   z'DBusSpecificationParser._parse_propertycCsT|j|}g}|D](}|j|s&q|j|}||qtj||||dS)z5Parse the signal element from the DBus specification.r)r=r@ is_parameterrDappendrr _get_type)rrZsignal_elementZ signal_nameZ signal_typeelement element_typer r r rBs    z%DBusSpecificationParser._parse_signalc Cs|j|}g}g}|D]T}|j|s*q|j|}|j|}|tjkrX||q|tjkr||qtj ||| || |dS)z5Parse the method element from the DBus specification.r) r=r@rEZ get_directionrDrr1rFr2rrG) rrZmethod_elementZ method_nameZin_typesZ out_typesrH directionrIr r r rCs$        z%DBusSpecificationParser._parse_methodcCs|sdSdd|S)zJoin types into one value.Nz({}))r.join)rtypesr r r rGsz!DBusSpecificationParser._get_typeN)rrr r rr=r8rrr:r>rArBrCrGr r r r rs       rN) collectionsrZ dasbus.xmlr__all__ Exceptionrobjectrrr r r r s  m