ó
[³XMc           @   sÝ   d  Z  d d l Z d d l Z d d l Z d d l m Z d d l m Z d d l m Z m	 Z	 d d l
 m Z d „  Z d „  Z d	 e j e j f d
 „  ƒ  YZ d e j e j f d „  ƒ  YZ d e j f d „  ƒ  YZ d S(   s1   
Postfix mail transport agent related protocols.
iÿÿÿÿN(   t   basic(   t   policies(   t   protocolt   defer(   t   logc         C   s   t  j |  ƒ S(   N(   t   urllibt   quote(   t   s(    (    s=   /usr/lib/python2.7/dist-packages/twisted/protocols/postfix.pyR      s    c         C   s   t  j |  ƒ S(   N(   R   t   unquote(   R   (    (    s=   /usr/lib/python2.7/dist-packages/twisted/protocols/postfix.pyR      s    t   PostfixTCPMapServerc           B   s\   e  Z d  Z d Z d Z d „  Z d d „ Z d „  Z d „  Z d „  Z	 d	 „  Z
 d
 „  Z RS(   sz  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  s   
c         C   s   |  j  |  j ƒ d  S(   N(   t
   setTimeoutt   timeout(   t   self(    (    s=   /usr/lib/python2.7/dist-packages/twisted/protocols/postfix.pyt   connectionMade*   s    t    c         C   s!   |  j  d | | p d f ƒ d S(   s&   Send an SMTP-like code with a message.s   %3.3d %sR   N(   t   sendLine(   R   t   codet   message(    (    s=   /usr/lib/python2.7/dist-packages/twisted/protocols/postfix.pyt   sendCode-   s    c         C   sÁ   |  j  ƒ  y | j d  d ƒ \ } } Wn t k
 rE | } d  } n Xy t |  d | ƒ } Wn! t k
 r€ |  j d d ƒ n= Xy | | ƒ Wn+ |  j d d | t j ƒ  d f ƒ n Xd  S(   Ni   t   do_i  s   unknown commands   Command %r failed: %s.(	   t   resetTimeoutt   splitt   Nonet
   ValueErrort   getattrt   AttributeErrorR   t   syst   exc_info(   R   t   linet   requestt   paramst   f(    (    s=   /usr/lib/python2.7/dist-packages/twisted/protocols/postfix.pyt   lineReceived1   s    

c         C   se   | d  k r# |  j d d d ƒ n> t j |  j j | ƒ } | j |  j |  j ƒ | j	 t
 j ƒ d  S(   Ni  s   Command %r takes 1 parameters.t   get(   R   R   R   t   maybeDeferredt   factoryR!   t   addCallbackst   _cbGott   _cbNott
   addErrbackR   t   err(   R   t   keyt   d(    (    s=   /usr/lib/python2.7/dist-packages/twisted/protocols/postfix.pyt   do_getB   s
    c         C   s   |  j  d | j ƒ  ƒ d  S(   Ni  (   R   t   getErrorMessage(   R   t   fail(    (    s=   /usr/lib/python2.7/dist-packages/twisted/protocols/postfix.pyR&   J   s    c         C   s6   | d  k r |  j d ƒ n |  j d t | ƒ ƒ d  S(   Niô  iÈ   (   R   R   R   (   R   t   value(    (    s=   /usr/lib/python2.7/dist-packages/twisted/protocols/postfix.pyR%   M   s    c         C   s{   | d  k r# |  j d d d ƒ nT y | j d  d ƒ \ } } Wn% t k
 rf |  j d d d ƒ n X|  j d d ƒ d  S(   Ni  s   Command %r takes 2 parameters.t   puti   iô  s   put is not implemented yet.(   R   R   R   R   (   R   t   keyAndValueR)   R.   (    (    s=   /usr/lib/python2.7/dist-packages/twisted/protocols/postfix.pyt   do_putS   s    (   t   __name__t
   __module__t   __doc__R   t	   delimiterR   R   R    R+   R&   R%   R1   (    (    (    s=   /usr/lib/python2.7/dist-packages/twisted/protocols/postfix.pyR	      s   					t   PostfixTCPMapDictServerFactoryc           B   s   e  Z d  Z e Z RS(   s8   An in-memory dictionary factory for PostfixTCPMapServer.(   R2   R3   R4   R	   R   (    (    (    s=   /usr/lib/python2.7/dist-packages/twisted/protocols/postfix.pyR6   _   s   t'   PostfixTCPMapDeferringDictServerFactoryc           B   s)   e  Z d  Z e Z d d „ Z d „  Z RS(   s8   An in-memory dictionary factory for PostfixTCPMapServer.c         C   s,   i  |  _  | d  k	 r( |  j  j | ƒ n  d  S(   N(   t   dataR   t   update(   R   R8   (    (    s=   /usr/lib/python2.7/dist-packages/twisted/protocols/postfix.pyt   __init__j   s    	c         C   s   t  j |  j j | ƒ ƒ S(   N(   R   t   succeedR8   R!   (   R   R)   (    (    s=   /usr/lib/python2.7/dist-packages/twisted/protocols/postfix.pyR!   o   s    N(   R2   R3   R4   R	   R   R   R:   R!   (    (    (    s=   /usr/lib/python2.7/dist-packages/twisted/protocols/postfix.pyR7   e   s   (   R4   R   t   UserDictR   t   twisted.protocolsR    R   t   twisted.internetR   R   t   twisted.pythonR   R   R   t   LineReceivert   TimeoutMixinR	   t   ServerFactoryR6   R7   (    (    (    s=   /usr/lib/python2.7/dist-packages/twisted/protocols/postfix.pyt   <module>   s   		E	