mò
nÔjGc           @   sL   d  Z  d Z d k Z d k Z d d d „ Z d d d d „ Z d „  Z d S(   s%   Common functions used by googlebot.pys   avleen@gmail.com (Avleen Vig)Nc         C   s©   |  p d Sn | oA t |  ƒ t j o. xy |  D] } | i  | | i d ƒ ƒ q0 WnO | o | i  | |  i d ƒ ƒ n+ t |  ƒ t j o d i |  ƒ GHn |  GHd S(   s›   Print the message to the screen, or deliver using IRC

  Args:
    msg: string or list
    irc: IRCClient object
    channel: string
  Returns:
    None
  Ns   latin-1s   
(   t   msgt   irct   typet   listt   entryt   channelt   encodet   join(   R    R   R   R   (    (    t6   /home/avleen/devel/python/googlebot2/modules/common.pyt   DeliverMessage
   s    	  !c         C   s  | o7 |  o0 |  i | i ƒ o |  i d | i d ƒ }  n | d j o |  Sn | |  j o d Snl |  o% | o |  i d | d ƒ }  |  Sn@ |  o8 y |  i d d ƒ d }  WqÓ t j
 o |  SqÓ Xn | o? |  o8 y |  i d d ƒ d }  Wqt j
 o |  SqXn |  S(   sª   Print the message to the screen, or deliver using IRC

  Args:
    msg: string or list
    irc: IRCClient object
    channel: string
  Returns:
    msg: string or None
  s   %s: t    t   defaults   %s t    i   N(	   R   R    t
   startswitht   nicknamet   replacet   keywordt   Nonet   splitt
   IndexError(   R    R   R   (    (    R   t   NormalizeMessage!   s*    	 !c       	   C   s°   t  i  ƒ  }  |  i t d ƒ ƒ |  i d d ƒ } |  i d d ƒ } |  i d d ƒ } |  i d d ƒ } | d j o d Sn t	 i
 d	 | d
 | d | d | ƒ } | i ƒ  } | S(   sW   Sets up a new DB connection

  Args:
    None
  Returns:
    cursor: database cursor
  s   config/database.conft   databaset   db_unix_sockett   db_usernamet   db_passwordt   db_nameR   Nt   unix_sockett   usert   passwdt   db(   t   ConfigParsert	   db_configt   readfpt   opent   getR   R   R   R   t   MySQLdbt   connectR   t   cursor(   R   R   R   R   R%   R   R   (    (    R   t   SetupDBD   s     (   t   __doc__t
   __author__R   R#   R   R	   R   R&   (   R	   R(   R#   R   R&   R   (    (    R   t   ?   s   		#
