o b1@sdZddlZddlmZddlmZmZddl m Z m Z ddl m Z mZddlmZdd Zd d ZGd d d e jejZGdddee jZGddde jZdS)z1 Postfix mail transport agent related protocols. N)UserDict)quoteunquote)deferprotocol)basicpolicies)logcCs t|}t|tr|d}|SNascii)_quote isinstancestrencodesquotedr;/usr/lib/python3/dist-packages/twisted/protocols/postfix.pyrs  rcCs&t|tr |d}t|}|dSr )r bytesdecode_unquoterrrrrrs   rc@sReZdZdZdZdZddZdddZd d Zd d Z d dZ ddZ ddZ dS)PostfixTCPMapServera Postfix mail transport agent TCP map protocol implementation. Receive requests for data matching given key via lineReceived, asks it's factory for the data with self.factory.get(key), and returns the data to the requester. None means no entry found. You can use postfix's postmap to test the map service:: /usr/sbin/postmap -q KEY tcp:localhost:4242 iX cCs||jdSN) setTimeouttimeout)selfrrrconnectionMade3sz"PostfixTCPMapServer.connectionMadecCs |t|dd|dS)z8 Send an SMTP-like code with a message. r  N)sendLinerr)rcodemessagerrrsendCode6s zPostfixTCPMapServer.sendCodecCs|z |dd\}}Wn ty|}d}Ynwz t|d|d}Wnty8|ddYdSwz||WdStyatt d d}|dd|d|YdSw)Ndo_r sunknown commandsCommand s failed: ) resetTimeoutsplit ValueErrorgetattrrAttributeErrorr$ BaseExceptionrsysexc_infor)rlinerequestparamsfexcInforrr lineReceived<s$   z PostfixTCPMapServer.lineReceivedcCsH|dur |dddSt|jj|}||j|j|t j dS)Nr's!Command 'get' takes 1 parameters.) r$r maybeDeferredfactoryget addCallbacks_cbGot_cbNot addErrbackr err)rkeydrrrdo_getNs zPostfixTCPMapServer.do_getcCs|d}|d|dS)Nr r')getErrorMessagerr$)rfailmsgrrrr;VszPostfixTCPMapServer._cbNotcCs*|dur |ddS|dt|dS)N)r$r)rvaluerrrr:ZszPostfixTCPMapServer._cbGotcCs^|dur |dddSz |dd\}}Wnty&|ddYdSw|dddS)Nr's!Command 'put' takes 2 parameters.r%rDsput is not implemented yet.)r$r)r*)r keyAndValuer>rFrrrdo_put`s zPostfixTCPMapServer.do_putN)r) __name__ __module__ __qualname____doc__r delimiterrr$r5r@r;r:rHrrrrr"s   rc@seZdZdZeZdS)PostfixTCPMapDictServerFactoryB An in-memory dictionary factory for PostfixTCPMapServer. N)rIrJrKrLrrrrrrrNlsrNc@s&eZdZdZeZdddZddZdS)'PostfixTCPMapDeferringDictServerFactoryrONcCs"i|_|dur|j|dSdSr)dataupdate)rrQrrr__init__{sz0PostfixTCPMapDeferringDictServerFactory.__init__cCst|j|Sr)rsucceedrQr8)rr>rrrr8sz+PostfixTCPMapDeferringDictServerFactory.getr)rIrJrKrLrrrSr8rrrrrPts   rP)rLr. collectionsr urllib.parserr rrtwisted.internetrrtwisted.protocolsrrtwisted.pythonr LineReceiver TimeoutMixinr ServerFactoryrNrPrrrrs  J