
?]Mc           @   sK  d  Z  d d k Z d d k Z d d k Z d d k Z d d k Z d d k Z d d k l Z d d k	 Z	 d d k
 l Z d d k
 l Z d d k
 l Z d d k
 l Z d d k
 l Z d d	 k l Z d d
 k l Z e Z d Z d2 Z d Z h d e i 6d e i 6d e i 6d e i 6d e i 6d e i 6d e i 6d e i  6d e i! 6d e i" 6d e i# 6d e i$ 6d  e i% 6d! e i& 6Z' d" d3 d#     YZ( d$ e) f d%     YZ* d&   Z+ d'   Z, d(   Z- d)   Z. h e+ d* 6e, d+ 6e- d, 6Z/ y e i0 d-  Wn e1 j
 o n Xe. e/ d. <d/   Z2 d0   Z3 e4 d1 j o e3   n d S(4   s/   Export an XML representation of a mailing list.iN(   t   escape(   t   Defaults(   t   Errors(   t   MemberAdaptor(   t   Utils(   t   mm_cfg(   t   MailList(   t   _t    t
   msg_headert
   msg_footert   digest_headert   digest_footert   autoresponse_postings_textt   autoresponse_admin_textt   autoresponse_request_texti   t   boolt   radiot   stringt   textt   emailt
   email_listt   hostt   numbert   uploadt   selectt   topicst   checkboxt   email_list_ext   header_filtert   Indenterc           B   s/   e  Z d  d  Z d   Z d   Z d   Z RS(   i   c         C   s   | |  _  d |  _ | |  _ d  S(   Ni    (   t   _fpt   _indentt   _width(   t   selft   fpt   indentwidth(    (    s   /usr/lib/mailman/bin/export.pyt   __init__G   s    		c         C   s   |  i  d 7_  d  S(   Ni   (   R    (   R"   (    (    s   /usr/lib/mailman/bin/export.pyt   indentL   s    c         C   s*   |  i  d 8_  |  i  d j p t  d  S(   Ni   i    (   R    t   AssertionError(   R"   (    (    s   /usr/lib/mailman/bin/export.pyt   dedentO   s    c         C   sC   | d j o" |  i  i |  i |  i d  n |  i  i |  d  S(   Ns   
R   (   R   t   writeR    R!   (   R"   t   s(    (    s   /usr/lib/mailman/bin/export.pyR)   S   s    "(   t   __name__t
   __module__R%   R&   R(   R)   (    (    (    s   /usr/lib/mailman/bin/export.pyR   F   s   		t	   XMLDumperc           B   sk   e  Z d    Z d   Z e d  Z d   Z d   Z d
 d  Z	 d
 d  Z
 d   Z d   Z d	   Z RS(   c         C   s%   t  |  |  _ d  |  _ g  |  _ d  S(   N(   R   R   t   Nonet
   _tagbuffert   _stack(   R"   R#   (    (    s   /usr/lib/mailman/bin/export.pyR%   [   s    	c         C   sp   g  } xZ | i    D]L \ } } | d  j o
 d } n t t |   } | i d | | f  q Wt i |  S(   Nt    s   %s="%s"(   t   itemsR.   R    t   strt   appendt   SPACEt   join(   R"   t   tagattrst   attrst   kt   v(    (    s   /usr/lib/mailman/bin/export.pyt
   _makeattrs`   s     
c         C   s   |  i  p d  S|  i  \ } } d  |  _  | o d |  i |  } n d } | o8 |  i d | | f IJ|  i i   |  i i |  n |  i d | | f IJd  S(   NR   R1   s   <%s%s>s   <%s%s/>(   R/   R.   R;   R   R&   R0   R4   (   R"   t   moret   namet
   attributest   attrstr(    (    s   /usr/lib/mailman/bin/export.pyt   _flushl   s    
	c         K   s   |  i    | | f |  _ d  S(   N(   R@   R/   (   R"   t   _namet	   _tagattrs(    (    s   /usr/lib/mailman/bin/export.pyt   _push_element}   s    
c         C   s|   t  |  i  } |  i d t  | pR |  i i   } | | j p t d | | f  |  i i   |  i d | IJn d  S(   NR<   s   got: %s, expected: %ss   </%s>(	   R   R/   R@   t   FalseR0   t   popR'   R   R(   (   R"   RA   t   bufferedR=   (    (    s   /usr/lib/mailman/bin/export.pyt   _pop_element   s    !c         K   s   |  i    | o d |  i |  } n d } | d  j o |  i d | | f IJn0 t t |   } |  i d | | | | f IJd  S(   NR   R1   s   <%s%s/>s   <%s%s>%s</%s>(   R@   R;   R.   R   R    t   unicode(   R"   RA   t   _valuet   _attributesR8   t   value(    (    s   /usr/lib/mailman/bin/export.pyt   _element   s    
c      	   C   s  t  t | d t   } | i | |  } | i   | \ } } | d  j o d  Sxg| d D][} t | t  p q] n | d }	 |	 i d  o q] n | d }
 d  } t	 | d  o  | i
 | |
 |	 | d  } n | d  j o t | |	  } n |	 d j o q] n | o  |	 t j o t i |  } n t |
 } t | t  oK |  i d d |	 d	 | x | D] } |  i d
 |  qqW|  i d  q] |  i d | d |	 d	 | q] Wd  S(   Nt   use_dollar_stringsi   i    R   t   getValuei   t   optionR=   t   typeRK   (   R   t   getattrRD   t   GetConfigInfot   GetConfigCategoriesR.   t
   isinstancet   tuplet
   startswitht   hasattrRN   t   DOLLAR_STRINGSR   t	   to_dollart   TYPESt   listRC   RL   RG   (   R"   t   mlistR9   t   subcatt   is_convertedt   infot   labelt   guit   datat   varnamet   vtypeRK   t   widget_typeR:   (    (    s   /usr/lib/mailman/bin/export.pyt   _do_list_categories   s<     

 
 c      	   C   s  |  i  d d | i |  i  d  |  i d | i d d d d |  i d | i d d d d x t i D]y } | i |  } | d  j o |  i	 | |  qk x@ g  } | D] } | | d	 q ~ D] } |  i	 | | |  q Wqk W|  i
 d  |  i  d
  t | i    } xt | i    D]t}	 t d |	  }
 | i |	  } | |	 j o | |
 d <n |  i  d |
  |  i d | i |	   |  i d | | i |	    |  i d | i |	   h  }
 | i |	  } | t i j o d |
 d <nH d |
 d <h d t i 6d t i 6d t i 6i | i |	  d  |
 d <|	 | j o2 | i |	 t i  o d |
 d <qd |
 d <n d |
 d <| i |	  } | o& t i i |  } | i    |
 d <n |  i d |
  xS t! i" i#   D]B \ } } | d  j o qn | i |	 |  } |  i | |  qW| i$ |	  } | p |  i d  n< |  i  d  x | D] } |  i d |  qgW|  i
 d  |  i
 d  q'W|  i
 d
  |  i
 d  d  S(!   NR[   R=   t   configurationRO   t   preferred_languageRP   R   t   passwordi    t   rostert   idt   originalt   membert   realnamet   languaget   enabledt   statust   disabledt   byusert   byadmint   bybouncet   unknownt   reasont   plaint   deliveryt   mimet   regulart   changedt   digestR   t   topic(   s   digestRx   (%   RC   t   _internal_nameRL   Rh   Ri   R   t   ADMIN_CATEGORIESt   GetConfigSubCategoriesR.   Rf   RG   t   sett   getDigestMemberKeyst   sortedt
   getMemberst   dictt   getMemberCPAddresst   getMemberNamet   getMemberPasswordt   getMemberLanguaget   getDeliveryStatusR   t   ENABLEDt   BYUSERt   BYADMINt   BYBOUNCEt   gett   getMemberOptiont   DisableMimet   getDeliveryStatusChangeTimet   datetimet   fromtimestampt	   isoformatR   t   OPTINFOR2   t   getMemberTopics(   R"   R\   t   password_schemeR9   t   subcatst   _[1]t   tR]   t	   digestersRm   R8   t   casedRq   R|   t   whenRO   t   flagRK   R   R~   (    (    s   /usr/lib/mailman/bin/export.pyt
   _dump_list   s    				
 &  	


  c         C   s   |  i  d IJ|  i d h d d 6d d 6 xi t |  D][ } y t | d t } Wn, t i j
 o t i t	 d  IJq8 n X|  i
 | |  q8 W|  i d  d  S(	   Ns&   <?xml version="1.0" encoding="UTF-8"?>t   mailmans)   http://www.w3.org/2001/XMLSchema-instances	   xmlns:xsis   ssi-1.0.xsds   xsi:noNamespaceSchemaLocationt   locks   No such list: %(listname)s(   R   RC   R   R   RD   R   t   MMUnknownListErrort   syst   stderrR   R   RG   (   R"   t	   listnamesR   t   listnameR\   (    (    s   /usr/lib/mailman/bin/export.pyt   dump  s     c         C   s    x |  i  o |  i   q Wd  S(   N(   R0   RG   (   R"   (    (    s   /usr/lib/mailman/bin/export.pyt   close  s     
N(   R+   R,   R%   R;   t   TrueR@   RC   RG   R.   RL   Rf   R   R   R   (    (    (    s   /usr/lib/mailman/bin/export.pyR-   Z   s   				
#	K	c         C   s   d S(   Ns   {NONE}(    (   Ri   (    (    s   /usr/lib/mailman/bin/export.pyt   no_password  s    c         C   s   d |  S(   Ns   {PLAIN}(    (   Ri   (    (    s   /usr/lib/mailman/bin/export.pyt   plaintext_password  s    c         C   s&   t  i |   } d t i | i    S(   Ns   {SHA}(   R   t   sha_newt   base64t	   b64encodeR}   (   Ri   t   h(    (    s   /usr/lib/mailman/bin/export.pyt   sha_password"  s    c         C   sF   t  i t  } t i |   } | i |  d t i | i   |  S(   Ns   {SSHA}(	   t   ost   urandomt   SALT_LENGTHR   R   t   updateR   R   R}   (   Ri   t   saltR   (    (    s   /usr/lib/mailman/bin/export.pyt   ssha_password'  s    t   noneRx   t   shai   t   sshac          C   s  t  i d t i d t d   }  |  i d d d d d d  d	 d
 d t d  |  i d d d d d	 d
 d t d  |  i d d d t d d d t d  |  i d d d g  d d d	 d
 d d d d d t d  |  i   \ } } | o! |  i	   |  i
 t d   n | i o- x t D] } | i   GHq$Wt i d  n | i i   t j o |  i
 t d   n |  | | f S(    Nt   versiont   usagesW   %%prog [options]

Export the configuration and members of a mailing list in XML format.s   -os   --outputfilet   metavart   FILENAMEt   defaultRP   R   t   helpsS   Output XML to FILENAME.  If not given, or if FILENAME is '-', standard out is
used.s   -ps   --password-schemeR   s   Specify the RFC 2307 style hashing scheme for passwords included in the
output.  Use -P to get a list of supported schemes, which are
case-insensitive.s   -Ps   --list-hash-schemest   actiont
   store_trues^   List the supported password hashing schemes and exit.  The scheme labels are
case-insensitive.s   -ls
   --listnameR4   t   LISTNAMEt   destR   s   The list to include in the output.  If not given, then all mailing lists are
included in the XML output.  Multiple -l flags may be given.s   Unexpected argumentsi    s   Invalid password scheme(   t   optparset   OptionParserR   t   VERSIONR   t
   add_optionR.   RD   t
   parse_argst
   print_helpt   errort   list_hash_schemest   SCHEMESt   upperR   t   exitR   t   lower(   t   parsert   optst   argsR`   (    (    s   /usr/lib/mailman/bin/export.pyt	   parseargs=  s:    





 c          C   s   t    \ }  } } | i d j o t i } n t i | i d d  } zT t |  } | i o | i } n t	 i
   } | i | t | i  | i   Wd  | t i j	 o | i   n Xd  S(   Nt   -t   ws   utf-8(   NR   (   R   t
   outputfileR.   R   t   stdoutt   codecst   openR-   R   R   t
   list_namesR   R   R   R   (   R   R   R   R#   t   dumperR   (    (    s   /usr/lib/mailman/bin/export.pyt   maind  s    
t   __main__(   R	   R
   R   R   R   R   R   (    (5   t   __doc__R   R   R   R   R   R   t   xml.sax.saxutilsR    t   pathst   MailmanR   R   R   R   R   t   Mailman.MailListR   t   Mailman.i18nR   R   t   __i18n_templates__R5   RX   R   t   Togglet   Radiot   Stringt   Textt   Emailt	   EmailListt   Hostt   Numbert
   FileUploadt   Selectt   Topicst   Checkboxt   EmailListExt   HeaderFilterRZ   R   t   objectR-   R   R   R   R   R   R   t   NotImplementedErrorR   R   R+   (    (    (    s   /usr/lib/mailman/bin/export.pyt   <module>   sr       












				

	'	
