ó
G¥êRc           @   sÅ   d  d l  m Z m Z m Z d  d l m Z d d l m Z m Z d d l	 Z	 d d l
 Z
 d e f d „  ƒ  YZ d „  Z d	 e f d
 „  ƒ  YZ d e f d „  ƒ  YZ e d e f d „  ƒ  Yƒ Z d S(   i   (   t   USPBlockt	   RPCClientt   ProtocolError(   t	   constantsiÿÿÿÿ(   t   total_orderingt   wrapsNt   DiscussErrorc           B   s   e  Z d  Z d „  Z RS(   sL   An error returned from Discuss server itself which has a Discuss error code.c         C   sN   | |  _  | t j k r6 t j |  d t j | ƒ n t j |  d | ƒ d  S(   Ns   Discuss error: %ss   Unknown discuss error (code %i)(   t   codeR   t   errorst	   Exceptiont   __init__(   t   selfR   (    (    s2   /usr/lib/python2.7/dist-packages/discuss/client.pyR
      s    	(   t   __name__t
   __module__t   __doc__R
   (    (    (    s2   /usr/lib/python2.7/dist-packages/discuss/client.pyR      s   c            s   t  ˆ  ƒ ‡  f d †  ƒ } | S(   Nc            sI   y ˆ  |  | | Ž SWn. t  j k
 rD |  j j ƒ  ˆ  |  | | Ž SXd  S(   N(   t   sockett   timeoutt   rpct   connect(   R   t   argst   kwargs(   t   f(    s2   /usr/lib/python2.7/dist-packages/discuss/client.pyt   autoreconnect   s
    (   R   (   R   R   (    (   R   s2   /usr/lib/python2.7/dist-packages/discuss/client.pyt   autoreconnects   s    t   Clientc           B   sG   e  Z d  Z d e d d „ Z e d „  ƒ Z e d „  ƒ Z d „  Z	 RS(   s   Discuss client.i4  c         C   sF   t  | | | | ƒ |  _ | rB |  j ƒ  j d ƒ rB t d ƒ ‚ n  d  S(   Ns   ???@s   Authentication to server failed(   R   R   t   who_am_it
   startswithR   (   R   t   servert   portt   authR   (    (    s2   /usr/lib/python2.7/dist-packages/discuss/client.pyR
   .   s    c         C   s+   t  t j ƒ } |  j j | ƒ } | j ƒ  S(   s(   Ask server for the server version number(   R    R   t   GET_SERVER_VERSIONR   t   requestt   read_long_integer(   R   R   t   reply(    (    s2   /usr/lib/python2.7/dist-packages/discuss/client.pyt   get_server_version3   s    c         C   s+   t  t j ƒ } |  j j | ƒ } | j ƒ  S(   sk   Ask server for the Kerberos principal with which discuss identified
        the client after the handshake.(   R    R   t   WHO_AM_IR   R   t   read_string(   R   R   R!   (    (    s2   /usr/lib/python2.7/dist-packages/discuss/client.pyR   ;   s    c         C   s   |  j  j j ƒ  d S(   s   Disconnect from the server.N(   R   R   t   close(   R   (    (    s2   /usr/lib/python2.7/dist-packages/discuss/client.pyR%   D   s    N(
   R   R   R   t   Truet   NoneR
   R   R"   R   R%   (    (    (    s2   /usr/lib/python2.7/dist-packages/discuss/client.pyR   +   s
   	t   Meetingc           B   sÎ   e  Z d  Z d „  Z e e d „ ƒ Z e d „  ƒ Z e d „  ƒ Z e d „  ƒ Z	 e d „  ƒ Z
 e d d d d	 „ ƒ Z e d d
 d „ ƒ Z e d „  ƒ Z e d „  ƒ Z e d „  ƒ Z e d „  ƒ Z RS(   s   Discuss meeting.c         C   sV   | |  _  | j |  _ | |  _ | j d ƒ d |  _ |  j j | f |  _ t |  _ d  S(   Nt   /iÿÿÿÿ(	   t   clientR   t   namet   splitt
   short_nameR   t   idt   Falset   info_loaded(   R   R*   R+   (    (    s2   /usr/lib/python2.7/dist-packages/discuss/client.pyR
   L   s    		c         C   sE  |  j  r | r d St t j ƒ } | j |  j ƒ |  j j | ƒ } | j ƒ  |  _	 | j
 ƒ  |  _ | j
 ƒ  |  _ | j
 ƒ  |  _ | j ƒ  |  _ | j ƒ  |  _ | j ƒ  |  _ | j ƒ  |  _ t j j | j ƒ  ƒ |  _ t j j | j ƒ  ƒ |  _ | j ƒ  |  _ | j
 ƒ  |  _ | j ƒ  } | d k r8t | ƒ ‚ n  t |  _  d S(   s'   Load all the properties into the class.Ni    (   R0   R    R   t   GET_MTG_INFOt
   put_stringR+   R   R   R    t   versionR$   t   locationt	   long_namet   chairmant   firstt   lastt   lowestt   highestt   datetimet   fromtimestampt   date_createdt   date_modifiedt   read_booleant   publict   access_modesR   R&   (   R   t   forceR   R!   t   result(    (    s2   /usr/lib/python2.7/dist-packages/discuss/client.pyt	   load_infoT   s*    c         C   s‚   t  t j ƒ } | j |  j ƒ | j d ƒ | j | ƒ |  j j | ƒ } | j ƒ  } | j	 ƒ  } | d k r~ t
 | ƒ ‚ n  | S(   s¿   Check whether the meeting has updated since last time we looked at it.
        Returns true if given last < real last, false if they are equal and error
        if given is greater than real.i    (   R    R   t   UPDATED_MTGR2   R+   t   put_long_integerR   R   R?   R    R   (   R   R8   R   R!   t   updatedRC   (    (    s2   /usr/lib/python2.7/dist-packages/discuss/client.pyt   check_updateq   s    c         C   sR   t  t j ƒ } | j |  j ƒ | j | ƒ | j t j 7_ |  j j	 | ƒ d S(   s5   Send request for the tranasction into the connection.N(
   R    R   t   GET_TRN_INFO3R2   R+   RF   t
   block_typet	   PROC_BASER   t   send(   R   t   numberR   (    (    s2   /usr/lib/python2.7/dist-packages/discuss/client.pyt   request_transaction„   s
    c         C   sQ  |  j  j ƒ  } | j ƒ  } | j ƒ  } t |  | ƒ } | | _ | | _ | j ƒ  | _ | j ƒ  | _ | j ƒ  | _ | j ƒ  | _	 | j ƒ  | _
 | j ƒ  | _ | j ƒ  | _ t j j | j ƒ  ƒ | _ | j ƒ  | _ | j ƒ  | _ | j ƒ  | _ | j ƒ  | _ | j ƒ  | _ | j ƒ  | _ | j ƒ  } | d k rMt | ƒ ‚ n  | S(   s)   Read the transaction from the connection.i    (   R   t   receiveR    t   TransactionR3   t   currentt   prevt   nextt   preft   nreft   freft   lreft   chain_indexR;   R<   t   date_enteredt	   num_linest	   num_charsR$   t   subjectt   authort   flagst	   signatureR   (   R   R!   R3   RM   t   trnRC   (    (    s2   /usr/lib/python2.7/dist-packages/discuss/client.pyt   receive_transaction   s0    		c         C   s   |  j  | ƒ |  j ƒ  S(   s?   Retrieve the informataion about a transaction using the number.(   RN   Ra   (   R   RM   (    (    s2   /usr/lib/python2.7/dist-packages/discuss/client.pyt   get_transaction°   s    i   iÿÿÿÿc         C   s$  | d k r" |  j  ƒ  |  j } n  | | d } | } d } | } g  } xÕ | d k r| | | k r— | d k r— |  j | ƒ | d 7} | d 8} qK yJ |  j ƒ  }	 | j |	 ƒ | rà | d |	 j d | | d d | ƒ n  Wn. t k
 r}
 |
 j t j	 k r|
 ‚ qn X| d 8} qK W| S(   sr   Return an iterator over the given range of transaction. Without
        arguments, iterates over all transactions.iÿÿÿÿi   iô  i    t   curt   totalt   left(
   RD   R8   RN   Ra   t   appendRM   R   R   R   t   DELETED_TRN(   R   t   startt   endt   feedbackt
   to_requestt   to_readt   buffer_sizeRc   RC   R`   t   err(    (    s2   /usr/lib/python2.7/dist-packages/discuss/client.pyt   transactions¸   s.    

+i    c   
      C   s   t  t j | r t j n t j ƒ } | j |  j ƒ | j t | ƒ ƒ | j | ƒ | rk | j | ƒ n  | j | ƒ t  t j	 ƒ } | | _
 |  j j | ƒ |  j j | ƒ |  j j ƒ  } | j t j k rà t d ƒ ‚ n  | j ƒ  } | j ƒ  }	 |	 d k rt |	 ƒ ‚ n  |  j | ƒ S(   s!   Add a transaction to the meeting.s   Transport-level errori    (   R    R   RK   t   ADD_TRN2t   ADD_TRNR2   R+   RF   t   lent	   TFILE_BLKt   bufferR   RL   RO   RJ   t
   REPLY_TYPER   R    R   Rb   (
   R   t   textR\   R_   t   reply_toR   t   tfileR!   t   new_idRC   (    (    s2   /usr/lib/python2.7/dist-packages/discuss/client.pyt   postÛ   s&    %	c   	      C   s°   t  t j ƒ } | j |  j ƒ |  j j | ƒ } | j ƒ  } | d k rX t | ƒ ‚ n  | j ƒ  } g  } x? t	 | ƒ D]1 } | j
 ƒ  } | j
 ƒ  } | j | | f ƒ qw W| S(   s]   Retrieve the access list of the meeting. Returns the list
        of principal-access tuples.i    (   R    R   t   GET_ACLR2   R+   R   R   R    R   t   rangeR$   Rf   (	   R   R   R!   RC   t   lengtht   aclt   it   modest	   principal(    (    s2   /usr/lib/python2.7/dist-packages/discuss/client.pyt   get_aclú   s    c         C   su   t  t j ƒ } | j |  j ƒ | j | ƒ |  j j | ƒ } | j ƒ  } | j ƒ  } | d k rq t	 | ƒ ‚ n  | S(   s7   Retrieve the access mode of a given Kerberos principal.i    (
   R    R   t
   GET_ACCESSR2   R+   R   R   R$   R    R   (   R   R   R   R!   R€   RC   (    (    s2   /usr/lib/python2.7/dist-packages/discuss/client.pyt
   get_access  s    c         C   sv   t  t j ƒ } | j |  j ƒ | j | ƒ | j | ƒ |  j j | ƒ } | j ƒ  } | d k rr t | ƒ ‚ n  d S(   s/   Changes the access mode of the given principal.i    N(	   R    R   t
   SET_ACCESSR2   R+   R   R   R    R   (   R   R   R€   R   R!   RC   (    (    s2   /usr/lib/python2.7/dist-packages/discuss/client.pyt
   set_access!  s    c         C   si   t  t j ƒ } | j |  j ƒ | j | ƒ |  j j | ƒ } | j ƒ  } | d k re t	 | ƒ ‚ n  d S(   s'   Undelete the transaction by its number.i    N(
   R    R   t   RETRIEVE_TRNR2   R+   RF   R   R   R    R   (   R   t
   trn_numberR   R!   RC   (    (    s2   /usr/lib/python2.7/dist-packages/discuss/client.pyt   undelete_transaction/  s    N(   R   R   R   R
   R   R/   RD   RH   RN   Ra   Rb   R'   Ro   Rz   R‚   R„   R†   R‰   (    (    (    s2   /usr/lib/python2.7/dist-packages/discuss/client.pyR(   I   s    	!"RP   c           B   sG   e  Z d  Z d „  Z e d „  ƒ Z e d „  ƒ Z d „  Z d „  Z RS(   s?   Discuss transaction. Returned by methods of the meeting object.c         C   s"   | |  _  | |  _ | j |  _ d  S(   N(   t   meetingRM   R   (   R   RŠ   RM   (    (    s2   /usr/lib/python2.7/dist-packages/discuss/client.pyR
   @  s    		c         C   sÕ   t  t j t j ƒ } | j |  j j ƒ | j |  j ƒ | j d ƒ |  j	 j
 | ƒ |  j	 j ƒ  } |  j	 j ƒ  } | j t j k s˜ | j t j k r§ t d ƒ ‚ n  | j ƒ  } | d k rÎ t | ƒ ‚ n  | j S(   s%   Retrieve the text of the transaction.i    s7   Bad server response when retriving transaction contents(   R    R   RK   t   GET_TRNR2   RŠ   R+   RF   RM   R   RL   RO   RJ   Rs   Ru   R   R    R   Rt   (   R   R   Rx   R!   RC   (    (    s2   /usr/lib/python2.7/dist-packages/discuss/client.pyt   get_textE  s    $c         C   so   t  t j ƒ } | j |  j j ƒ | j |  j ƒ |  j j	 | ƒ } | j
 ƒ  } | d k rk t | ƒ ‚ n  d S(   s   Delete the transaction.i    N(   R    R   t
   DELETE_TRNR2   RŠ   R+   RF   RM   R   R   R    R   (   R   R   R!   RC   (    (    s2   /usr/lib/python2.7/dist-packages/discuss/client.pyt   deleteY  s    c         C   s   |  j  | j  k  S(   N(   RM   (   R   t   other(    (    s2   /usr/lib/python2.7/dist-packages/discuss/client.pyt   __le__f  s    c         C   s?   t  | t ƒ r7 |  j | j k o6 |  j j | j j k St Sd  S(   N(   t
   isinstanceRP   RM   RŠ   R+   R/   (   R   R   (    (    s2   /usr/lib/python2.7/dist-packages/discuss/client.pyt   __eq__i  s    ((	   R   R   R   R
   R   RŒ   RŽ   R   R’   (    (    (    s2   /usr/lib/python2.7/dist-packages/discuss/client.pyRP   <  s   		(   R   R    R   R   t    R   t	   functoolsR   R   R;   R   R	   R   R   t   objectR   R(   RP   (    (    (    s2   /usr/lib/python2.7/dist-packages/discuss/client.pyt   <module>   s   	ó