ó
1ËoQc           @   sp   d  d l  Z  d  d l Z d  d l Z d Z e e e j d ƒ ƒ Z d e Z d d d „  ƒ  YZ	 d d „ Z d S(	   iÿÿÿÿNs   
i   s   %%0%ddt   MIMEMessagec           B   sG   e  Z d  „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z RS(   c         C   s(   g  |  _  d |  _ d |  _ d |  _ d  S(   Nt    (   t   _filest   _xmlMessaget	   _startCIDt	   _boundary(   t   self(    (    s:   /usr/lib/python2.7/dist-packages/wstools/MIMEAttachment.pyt   __init__   s    			c         C   sš   g  } | j  |  j ƒ x$ |  j D] } | j  | j ƒ  ƒ q  Wt j | ƒ } t | ƒ |  _ ~ ~ d t t	 j
 t j ƒ t t	 j
 t j ƒ d |  _ d  S(   Nt   <t   >(   t   appendR   R   t   readt   NLt   joint   _make_boundaryR   t   _fmtt   randomt	   randranget   syst   maxintR   (   R   t   msgpartst   it   alltext(    (    s:   /usr/lib/python2.7/dist-packages/wstools/MIMEAttachment.pyt   makeBoundary   s    c         C   s&  t  |  j ƒ d k r" |  j ƒ  n  t d |  j t } | d t 7} | d t 7} | d |  j t t 7} | |  j t 7} x‰ |  j D]~ } | d |  j t 7} | d t 7} | d t 7} | d t t | ƒ ƒ d	 t t 7} | j	 d ƒ | | j
 ƒ  t 7} q‡ W| d |  j d t 7} | S(
   s(   it return a string with the MIME messagei    s   --s*   Content-Type: text/xml; charset="us-ascii"s   Content-Transfer-Encoding: 7bits   Content-Id: s&   Content-Type: application/octet-streams!   Content-Transfer-Encoding: binarys   Content-Id: <R	   (   t   lenR   R   R   R   R   R   t   strt   idt   seekR   (   R   t	   returnstrt   file(    (    s:   /usr/lib/python2.7/dist-packages/wstools/MIMEAttachment.pyt   toString+   s     &c         C   s   |  j  j | ƒ d S(   s3   
        it adds a file to this attachment
        N(   R   R
   (   R   R   (    (    s:   /usr/lib/python2.7/dist-packages/wstools/MIMEAttachment.pyt
   attachFileC   s    c         C   s   | |  _  d S(   sP   
        it adds the XML message. we can have only one XML SOAP message
        N(   R   (   R   t
   xmlMessage(    (    s:   /usr/lib/python2.7/dist-packages/wstools/MIMEAttachment.pyt   addXMLMessageI   s    c         C   s   |  j  S(   s‰   
        this function returns the string used in the mime message as a
        boundary. First the write method as to be called
        (   R   (   R   (    (    s:   /usr/lib/python2.7/dist-packages/wstools/MIMEAttachment.pyt   getBoundaryO   s    c         C   s   |  j  S(   sB   
        This function returns the CID of the XML message
        (   R   (   R   (    (    s:   /usr/lib/python2.7/dist-packages/wstools/MIMEAttachment.pyt   getStartCIDV   s    (	   t   __name__t
   __module__R   R   R   R   R!   R"   R#   (    (    (    s:   /usr/lib/python2.7/dist-packages/wstools/MIMEAttachment.pyR       s   						c         C   s¨   t  j t j ƒ } d	 t | d } |  d  k r4 | S| } d } xa t r£ t j d t j	 | ƒ d t j
 ƒ } | j |  ƒ s‚ Pn  | d t | ƒ } | d 7} qC W| S(
   Nt   =i
   s   ==i    s   ^--s   (--)?$t   .i   s
   ==========(   R   R   R   R   R   t   Nonet   Truet   ret   compilet   escapet	   MULTILINEt   searchR   (   t   textt   tokent   boundaryt   bt   countert   cre(    (    s:   /usr/lib/python2.7/dist-packages/wstools/MIMEAttachment.pyR   ]   s    	&(    (   R*   R   R   R   R   t   reprR   t   _widthR   R    R(   R   (    (    (    s:   /usr/lib/python2.7/dist-packages/wstools/MIMEAttachment.pyt   <module>	   s   
H