ó
ºb\c           @   sX  d  Z  d Z d d l m Z m Z y d d l m Z e Z Wn e	 Z n Xd e
 f d     YZ d e f d     YZ d	 e f d
     YZ d e f d     YZ d e f d     YZ d e f d     YZ d e f d     YZ d e f d     YZ d e f d     YZ d e f d     YZ d e f d     YZ d e f d     YZ d S(   sz  
Copyright (c) 2010 Ozonetel, Inc.

Adapted from Twilio Python library. Thanks a lot to Twilio
for providing the library.

Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
s   1.0.0iÿÿÿÿ(   t   escapet	   quoteattr(   t   urlfetcht   KooKooExceptionc           B   s   e  Z RS(    (   t   __name__t
   __module__(    (    (    s!   /var/www/html/recognise/kookoo.pyR   '   s    t   Verbc           B   s   e  Z d  Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z	 d   Z
 d	   Z d
   Z d   Z d   Z d   Z RS(   s   KooKoo basic verb object.
    c         K   s   |  j  j |  _ d  |  _ d  |  _ g  |  _ i  |  _ xQ | j   D]C \ } } | d k ra d } n  | r@ t	 t
 |   |  j | <q@ q@ Wd  S(   Nt   sendert   from(   t	   __class__R   t   namet   Nonet   bodyt	   nestablest   verbst   attrst   itemsR   t   str(   t   selft   kwargst   kt   v(    (    s!   /var/www/html/recognise/kookoo.pyt   __init__/   s    				 	 c         C   s#  d |  j  } |  j j   } t |  x) | D]! } | d | |  j | f 7} q- W|  j sp t |  j  d k r| d 7} |  j r | t |  j  7} n  t |  j  d k r| d 7} xF |  j D]8 } x/ t |  d  j	 d  D] } | d | 7} qâ WqÂ Wn  | d |  j  7} n
 | d	 7} | S(
   Ns   <%ss    %s=%si    t   >s   
iÿÿÿÿs   	%s
s   </%s>
s   />
(
   R
   R   t   keyst   sortedR   t   lenR   R    R   t   split(   R   t   sR   t   aR   t   l(    (    s!   /var/www/html/recognise/kookoo.pyt   __repr__:   s"    

	
 
c         C   sd   |  j  s t d |  j   n  | j |  j  k rP t d | j |  j f   n  |  j j |  | S(   Ns   %s is not nestables   %s is not nestable inside %s(   R   R   R
   R   t   append(   R   t   verb(    (    s!   /var/www/html/recognise/kookoo.pyR    N   s    	c         C   s   t  j t |    S(   N(   t   urllibt   quoteR   (   R   (    (    s!   /var/www/html/recognise/kookoo.pyt   asUrlW   s    c         K   s   |  j  t | |   S(   N(   R    t   PlayText(   R   t   textR   (    (    s!   /var/www/html/recognise/kookoo.pyt   addPlayTextZ   s    c         K   s   |  j  t | |   S(   N(   R    t	   PlayAudio(   R   t   urlR   (    (    s!   /var/www/html/recognise/kookoo.pyt   addPlayAudio]   s    c         K   s   |  j  t |    S(   N(   R    t   Hangup(   R   R   (    (    s!   /var/www/html/recognise/kookoo.pyt	   addHangup`   s    c         K   s   |  j  t |    S(   N(   R    t   CollectDtmf(   R   R   (    (    s!   /var/www/html/recognise/kookoo.pyt   addCollectDtmfc   s    c         K   s   |  j  t | |   S(   N(   R    t   Record(   R   t   filenameR   (    (    s!   /var/www/html/recognise/kookoo.pyt	   addRecordf   s    c         K   s   |  j  t | |   S(   N(   R    t   dial(   R   t
   dialnumberR   (    (    s!   /var/www/html/recognise/kookoo.pyt   addDiali   s    c         K   s   |  j  t | |   S(   N(   R    t
   Conference(   R   t   conferenceNumberR   (    (    s!   /var/www/html/recognise/kookoo.pyt   addConferencel   s    c         K   s   |  j  t |    S(   N(   R    t	   Recognize(   R   R   (    (    s!   /var/www/html/recognise/kookoo.pyt   addRecognizeo   s    c         K   s   |  j  t | |   S(   N(   R    t   Gotourl(   R   R)   R   (    (    s!   /var/www/html/recognise/kookoo.pyt   addGotor   s    (   R   R   t   __doc__R   R   R    R$   R'   R*   R,   R.   R1   R4   R7   R9   R;   (    (    (    s!   /var/www/html/recognise/kookoo.pyR   ,   s   													t   Responsec           B   s   e  Z d  Z d d  Z RS(   s   KooKoo response object.

    c      
   K   sA   t  j |  d | | d d d d d d d d	 d
 d g
 |  _ d  S(   Nt   versionR%   R:   R(   R-   R/   R+   t   SmsR5   R2   R8   (   R   R   R   (   R   R>   R   (    (    s!   /var/www/html/recognise/kookoo.pyR   y   s    N(   R   R   R<   R   R   (    (    (    s!   /var/www/html/recognise/kookoo.pyR=   u   s   R%   c           B   s   e  Z d  Z d   Z RS(   s)   PlayText text

    text: text to say
    c         K   s   t  j |  |  | |  _ d  S(   N(   R   R   R   (   R   R&   R   (    (    s!   /var/www/html/recognise/kookoo.pyR      s    (   R   R   R<   R   (    (    (    s!   /var/www/html/recognise/kookoo.pyR%   }   s   R:   c           B   s   e  Z d  Z d   Z RS(   s/   gotourl url

    url: url for next request
    c         K   s   t  j |  |  | |  _ d  S(   N(   R   R   R   (   R   R)   R   (    (    s!   /var/www/html/recognise/kookoo.pyR      s    (   R   R   R<   R   (    (    (    s!   /var/www/html/recognise/kookoo.pyR:      s   R5   c           B   s&   e  Z d  Z d d d d d d  Z RS(   sZ   Conference conferenceNumber

    conferenceNumber: The identifier for your conference
    c         K   s;   t  j |  d | d | d | d | d | | | |  _ d  S(   Nt   caller_onhold_musict   recordt	   caller_idt   timeoutR>   (   R   R   R   (   R   R6   R@   RA   RB   RC   R>   R   (    (    s!   /var/www/html/recognise/kookoo.pyR      s    $
N(   R   R   R<   R   R   (    (    (    s!   /var/www/html/recognise/kookoo.pyR5      s   R(   c           B   s   e  Z d  Z d   Z RS(   sb   Play audio file at a URL

    url: url of audio file, MIME type on file must be set correctly
    c         K   s   t  j |  |  | |  _ d  S(   N(   R   R   R   (   R   R)   R   (    (    s!   /var/www/html/recognise/kookoo.pyR   ¢   s    (   R   R   R<   R   (    (    (    s!   /var/www/html/recognise/kookoo.pyR(      s   R+   c           B   s   e  Z d  Z d   Z RS(   s   Hangup the call
    c         K   s   t  j |   d  S(   N(   R   R   (   R   R   (    (    s!   /var/www/html/recognise/kookoo.pyR   «   s    (   R   R   R<   R   (    (    (    s!   /var/www/html/recognise/kookoo.pyR+   š   s   R-   c           B   s,   e  Z d  Z d Z d Z d d d d  Z RS(   sÛ   Collect digits from the caller's keypad

    maxDigits: how many digits to gather before returning
    timeout: wait for this many seconds before returning
    finishOnKey: key that triggers the end of caller input
    t   GETt   POSTc      	   K   s5   t  j |  d | d | d | | d d g |  _ d  S(   NR   t   ot   tR%   R(   (   R   R   R   (   R   t	   maxDigitsRC   t   termcharR   (    (    s!   /var/www/html/recognise/kookoo.pyR   ž   s    N(   R   R   R<   RD   RE   R   R   (    (    (    s!   /var/www/html/recognise/kookoo.pyR-   ®   s
   R2   c           B   s/   e  Z d  Z d Z d d d d d d d  Z RS(   RD   RE   c   	      K   sA   t  j |  d | d | d | d | d | d | | | |  _ d  S(   NRA   t	   limittimeRC   t   moht   promptToCalledNumberRB   (   R   R   R   (	   R   R3   RA   RJ   RC   RK   RL   RB   R   (    (    s!   /var/www/html/recognise/kookoo.pyR   Ä   s    *
N(   R   R   RD   RE   R   R   (    (    (    s!   /var/www/html/recognise/kookoo.pyR2   À   s   R/   c           B   s)   e  Z d  Z d Z d Z d d d  Z RS(   sÆ   Record audio from caller
	filename: File name of file to be recorded
    maxLength: maximum number of seconds to record
    timeout: seconds of silence before considering the recording complete
    RD   RE   c         K   s)   t  j |  d | d | | | |  _ d  S(   Nt   maxdurationt   silence(   R   R   R   (   R   R0   t   maxDurationRN   R   (    (    s!   /var/www/html/recognise/kookoo.pyR   Ô   s    
N(   R   R   R<   RD   RE   R   R   (    (    (    s!   /var/www/html/recognise/kookoo.pyR/   Ë   s
   R8   c           B   s/   e  Z d  Z d Z d d d d d d d  Z RS(   RD   RE   c   	      K   s>   t  j |  d | d | d | d | d | d | d | | d  S(   Nt   typeRC   RN   t   langt   lengtht   grammart   success_file(   R   R   (	   R   RP   RC   RN   RQ   RR   RS   RT   R   (    (    s!   /var/www/html/recognise/kookoo.pyR   ß   s    N(   R   R   RD   RE   R   R   (    (    (    s!   /var/www/html/recognise/kookoo.pyR8   Ú   s   N(   R<   t   __VERSION__t   xml.sax.saxutilsR    R   t   google.appengine.apiR   t   Truet	   APPENGINEt   Falset	   ExceptionR   t   objectR   R=   R%   R:   R5   R(   R+   R-   R2   R/   R8   (    (    (    s!   /var/www/html/recognise/kookoo.pyt   <module>   s&   

I

