o `@sRddlmZmZmZddlmZddlZddlmZddl m Z ddl m Z ddl mZddlmZdd lmZmZdd lmZmZmZmZdd lmZdd lmZmZmZmZdd l m!Z!m"Z"ddl#m$Z$ddl%m&Z&ddl'm(Z(m)Z)m*Z*m+Z+m,Z,e dddGdddZ-d"ddZ.GdddZ/Gddde!Z0GdddZ1d"d d!Z2dS)#) as_completedFuturewait_for)countN)Optional)warn)IOLoop)IOStream)Event)Queue QueueFull) SASLParsermake_auth_externalBEGINAuthenticationError)get_bus)Parser MessageTypeMessage MessageFlag) ProxyBase unwrap_msg)Router) message_bus)MessageFilters FilterHandle ReplyMatcher RouterClosedcheck_replyablezsjeepney.io.tornado is deprecated. Tornado is now built on top of asyncio, so please use jeepney.io.asyncio instead.) stacklevelc@sDeZdZdefddZdddefddZd efd d Zd d ZdS)DBusConnectionstreamcCs$||_t|_tdd|_d|_dS)Nr)start)r#rparserroutgoing_serial unique_name)selfr#r)4/usr/lib/python3/dist-packages/jeepney/io/tornado.py__init__s  zDBusConnection.__init__Nserialmessagecs0|dur t|j}|j||IdHdSN)nextr&r#write serialiser(r.r-r)r)r*send!s zDBusConnection.sendreturncs> |j}|dur |S|jjdddIdH}|j|q)NTipartial)r%get_next_messager# read_bytesadd_data)r(msgbr)r)r*receive's  zDBusConnection.receivecC|jdSr/)r#closer(r)r)r*r?0zDBusConnection.close) __name__ __module__ __qualname__r r+rr4r=r?r)r)r)r*r"s  r"SESSIONcst|}ttjtjd}||IdH|dtIdHt}|js?| |j dddIdH|j rr/)r[setr@r)r)r*stoprrAzDBusRouter.stopcCs|Sr/r)r@r)r)r* __enter__uszDBusRouter.__enter__cCs |dS)NF)rhr(exc_typeexc_valexc_tbr)r)r*__exit__xszDBusRouter.__exit__cCs|jjSr/)rUr'r@r)r)r*r'~szDBusRouter.unique_namer.csF|jjtjkr|jjtj@st||IdHS| |IdHdSr/) header message_typer method_returnflagsrno_reply_expectedrrbr4)r(r.r)r)r* send_messages  zDBusRouter.send_messager;c CsH|j|rdS|j|D]}z|j|Wqty!YqwdS)zHandle one received messageN)rYdispatchrZmatchesrc put_nowaitr )r(r;rfr)r)r* _dispatchs  zDBusRouter._dispatchcsxz1 t|j|jgD]"}|IdH}|dur&Wd|_|jdS|||j |qqd|_|jw)z'Receiver loop - runs in a separate taskTNF) rrUr=r[wait is_runningrYdrop_allrxrVincoming)r(coror;r)r)r*r^s   zDBusRouter._receiver)rBrCrDr"r+r4rbrr rfrhrirnpropertyr'rrtrxr^r)r)r)r*rOKs    rOcs2eZdZdeffdd ZddZddZZS)rPrVcst|||_dSr/)superr+_router)r(msggenrV __class__r)r*r+s  zProxy.__init__cCsd|j|jS)Nz Proxy({}, {}))format_msggenrr@r)r)r*__repr__szProxy.__repr__csfdd}|S)Ncs8|i|}|jjtjusJtj|IdHSr/)rorpr method_callrrrb)argskwargsr;make_msgr(r)r*innersz!Proxy._method_call..innerr))r(rrr)rr* _method_callszProxy._method_call)rBrCrDrOr+rr __classcell__r)r)rr*rPsrPc@s.eZdZdZdZd ddZddZddZdS) _RouterContextNrEcCs ||_dSr/rR)r(rRr)r)r*r+s z_RouterContext.__init__cs&t|jIdH|_t|j|_|jSr/)rXrRrUrOrVr@r)r)r* __aenter__s z_RouterContext.__aenter__cs|j|jdSr/)rVrhrUr?rjr)r)r* __aexit__s z_RouterContext.__aexit__rE)rBrCrDrUrVr+rrr)r)r)r*rs   rcCst|S)aOpen a D-Bus 'router' to send and receive messages. Use as an async context manager:: async with open_dbus_router() as req: ... :param str bus: 'SESSION' or 'SYSTEM' or a supported address. :return: :class:`DBusRouter` This is a shortcut for:: conn = await open_dbus_connection() async with conn: async with conn.router() as req: ... )rrr)r)r*open_dbus_routersrr)3asynciorrr itertoolsrrItypingrwarningsrtornado.iolooprtornado.iostreamr tornado.locksr tornado.queuesr r jeepney.authr rrr jeepney.busrjeepney.low_levelrrrrjeepney.wrappersrrjeepney.routingrjeepney.bus_messagesrcommonrrrrrr"rXrOrPrrr)r)r)r*s2          ^