ó
‚•oTc           @   s¾   d  d l  Z  d  d l Z d  d l Z d  d l Z d d g Z e j e ƒ Z d d d d d d d e	 d d d d d	 „ Z
 d e f d
 „  ƒ  YZ e d k rº e j d e j ƒ e
 d ƒ n  d S(   iÿÿÿÿNt   minit   GrowlNotifiert
   PythonMinit   Messages   Mini Messaget	   localhostiZ  c         C   s   t  d | d | g d | g d | d | d | d | ƒ } | j ƒ  } | t k	 rU | S| j d | d	 | d
 |  d | d | d |	 d |
 d | ƒ S(   Nt   applicationNamet   notificationst   defaultNotificationst   applicationIcont   hostnamet   passwordt   portt   noteTypet   titlet   descriptiont   icont   stickyt   priorityt   callbackt
   identifier(   R   t   registert   Truet   notify(   R   R   R   R   R   R	   R
   R   R   R   R   t   notificationIconR   t   growlt   result(    (    s!   /var/www/SABnzbd/gntp/notifier.pyR       s(    				c           B   s’   e  Z d  Z d Z d g  d d d d d d „ Z d „  Z d „  Z d e d d d d „ Z	 d	 „  Z
 d
 „  Z d „  Z d „  Z d „  Z d „  Z RS(   t   MD5i   s   Python GNTPR   iZ  c         C   sj   | |  _  t | ƒ |  _ | r0 t | ƒ |  _ n |  j |  _ | |  _ | |  _ | |  _ t | ƒ |  _ d  S(   N(	   R   t   listR   R   R   R
   R	   t   intR   (   t   selfR   R   R   R   R	   R
   R   (    (    s!   /var/www/SABnzbd/gntp/notifier.pyt   __init__O   s    				c         C   s   t  j d ƒ | j d ƒ S(   Ns   Checking icont   http(   t   loggert   debugt
   startswith(   R   t   data(    (    s!   /var/www/SABnzbd/gntp/notifier.pyt
   _checkIcon_   s    c         C   s  t  j d |  j |  j ƒ t j ƒ  } | j d |  j ƒ x0 |  j D]% } | |  j	 k } | j
 | | ƒ qB W|  j rÁ |  j |  j ƒ rœ | j d |  j ƒ qÁ | j |  j ƒ } | j d | ƒ n  |  j rã | j |  j |  j ƒ n  |  j | ƒ |  j | ƒ |  j d | ƒ S(   Ns   Sending registration to %s:%ss   Application-Names   Application-IconR   (   R    R!   R	   R   t   gntpt   GNTPRegistert
   add_headerR   R   R   t   add_notificationR   R$   t   add_resourceR
   t   set_passwordt   passwordHasht   add_origin_infot   register_hookt   _send(   R   R   t   notificationt   enabledt   id(    (    s!   /var/www/SABnzbd/gntp/notifier.pyR   i   s     		c	         C   sn  t  j d | |  j |  j ƒ t j ƒ  }	 |	 j d |  j ƒ |	 j d | ƒ |	 j d | ƒ |  j r} |	 j	 |  j |  j
 ƒ n  | r– |	 j d | ƒ n  | r¯ |	 j d | ƒ n  | rù |  j | ƒ r× |	 j d | ƒ qù |	 j | ƒ }
 |	 j d |
 ƒ n  | r|	 j d | ƒ n  | r+|	 j d	 | ƒ n  | rD|	 j d
 | ƒ n  |  j |	 ƒ |  j |	 ƒ |  j d |	 ƒ S(   Ns"   Sending notification [%s] to %s:%ss   Application-Names   Notification-Names   Notification-Titles   Notification-Stickys   Notification-Prioritys   Notification-Icons   Notification-Texts   Notification-Callback-Targets   Notification-Coalescing-IDR   (   R    R!   R	   R   R%   t
   GNTPNoticeR'   R   R
   R*   R+   R$   R)   R,   t   notify_hookR.   (   R   R   R   R   R   R   R   R   R   t   noticeR1   (    (    s!   /var/www/SABnzbd/gntp/notifier.pyR   ‚   s2    	c         C   sˆ   t  j ƒ  } | j d | ƒ | j d | ƒ | j d | ƒ |  j r^ | j |  j |  j ƒ n  |  j | ƒ |  j | ƒ |  j d | ƒ S(   Ns   Subscriber-IDs   Subscriber-Names   Subscriber-Portt	   subscribe(	   R%   t   GNTPSubscribeR'   R
   R*   R+   R,   t   subscribe_hookR.   (   R   R1   t   nameR   t   sub(    (    s!   /var/www/SABnzbd/gntp/notifier.pyR5   ´   s    	c         C   si   | j  d t j ƒ  ƒ | j  d d ƒ | j  d t j ƒ | j  d t j ƒ  ƒ | j  d t j ƒ  ƒ d  S(   Ns   Origin-Machine-Names   Origin-Software-Names   gntp.pys   Origin-Software-Versions   Origin-Platform-Names   Origin-Platform-Version(   R'   t   platformt   nodeR%   t   __version__t   system(   R   t   packet(    (    s!   /var/www/SABnzbd/gntp/notifier.pyR,   Â   s
    c         C   s   d  S(   N(    (   R   R>   (    (    s!   /var/www/SABnzbd/gntp/notifier.pyR-   Ê   s    c         C   s   d  S(   N(    (   R   R>   (    (    s!   /var/www/SABnzbd/gntp/notifier.pyR3   Í   s    c         C   s   d  S(   N(    (   R   R>   (    (    s!   /var/www/SABnzbd/gntp/notifier.pyR7   Ð   s    c         C   s\  | j  ƒ  | j ƒ  } t j d |  j |  j | j ƒ t j t j t j	 ƒ } | j
 |  j ƒ | j |  j |  j f ƒ | j | ƒ | j d ƒ } x& | j d ƒ sº | | j d ƒ 7} q• Wt j | ƒ } | j ƒ  t j d |  j |  j | j ƒ t | ƒ t j k rt S| j ƒ  d d k r<d | j ƒ  d k r<t St j d	 | j ƒ  ƒ | j ƒ  S(
   Ns   To : %s:%s <%s>i   s   

s   From : %s:%s <%s>i    t   404t   disabledi   s   Invalid response: %s(   t   validatet   encodeR    R!   R	   R   t	   __class__t   sockett   AF_INETt   SOCK_STREAMt
   settimeoutt   socketTimeoutt   connectt   sendt   recvt   endswithR%   t
   parse_gntpt   closet   typet   GNTPOKR   t   error(   R   t   messagetypeR>   R#   t   st	   recv_datat   response(    (    s!   /var/www/SABnzbd/gntp/notifier.pyR.   Ó   s&    

,N(   t   __name__t
   __module__R+   RH   t   NoneR   R$   R   t   FalseR   R5   R,   R-   R3   R7   R.   (    (    (    s!   /var/www/SABnzbd/gntp/notifier.pyR   @   s   		
	1					t   __main__t   levels   Testing mini notification(   R%   RD   t   loggingR:   t   __all__t	   getLoggerRV   R    RX   RY   R    t   objectR   t   basicConfigt   DEBUG(    (    (    s!   /var/www/SABnzbd/gntp/notifier.pyt   <module>   s   		$³