mò
«m}Gc           @   s­   d  Z  d Z d Z d Z d Z d Z d Z d k l Z d k	 l
 Z
 l Z d	 k Z d	 k Z d
 e
 f d „  ƒ  YZ d e f d „  ƒ  YZ d „  Z e d j o e ƒ  n d	 S(   sº   HTTP wrapper around Emacspeak speech server.

Speech server is launched on HTTP server startup.

Speech commands are invoked via URLs:

http://host:port/cmd?arg

calls speaker.cmd(arg)

s;   $Id: HTTPSpeaker.py 5413 2007-12-28 14:15:06Z tv.raman.tv $s   $Author: tv.raman.tv $s   $Revision: 5413 $s5   $Date: 2007-12-28 06:15:06 -0800 (Fri, 28 Dec 2007) $s   Copyright (c) 2005 T. V. Ramant   LGPL(   s   Speaker(   s
   HTTPServers   BaseHTTPRequestHandlerNt   HTTPSpeakerc           B   s   t  Z d  Z d d d „ Z RS(   s   Speech server via HTTP.t   outloudiK   c         C   s>   t  i |  | | ƒ t | d h  d d <d | <ƒ |  _ d S(   s   Initialize HTTP listener.t	   localhostt   punctuationst   somet   rateN(	   t
   HTTPServert   __init__t   selft   addresst   handlert   Speakert   engineR   t   speaker(   R	   R
   R   R   R   (    (    t   HTTPSpeaker.pyR       s
     (   t   __name__t
   __module__t   __doc__R   (    (    (    R   R      s    t   SpeakHTTPRequestHandlerc           B   sS   t  Z d  Z d d d d d d d d d	 d
 d d d d d g Z d „  Z d „  Z RS(   s   Handle HTTP Speak requests.t   sayt   speakt   lettert   addTextt   silencet   tonet   stopt   punctuationR   t   allcapst
   capitalizet	   splitcapst   resett   shutdownt   versionc         C   s   d } d } t |  i i | ƒ oW t |  i i | ƒ } | d j o | ƒ  n | t	 i
 | ƒ ƒ |  i d |  i ƒ n |  i d d ƒ d S(   s   Produce speech.iÈ   iõ  s   Speaker errorN(   t   Nonet   cmdt   argt   hasattrR	   t   serverR   t   getattrt   methodt   urllibt   unquotet   send_responset   patht
   send_error(   R	   R#   R$   R(   (    (    R   t   do_GET=   s      c         C   s(  |  i i d ƒ } | ot | ƒ } |  i i | ƒ } | i d ƒ oI | d } t
 | d ƒ i d ƒ } |  i i i | ƒ |  i d d ƒ q$| d j o$ |  i i i ƒ  |  i d d ƒ q$| d	 j o> |  i d d ƒ |  i d
 d ƒ |  i ƒ  |  i i d ƒ q$|  i d d | ƒ n d S(   s)   Handle speech request in a POST message. s   content-lengths   speak:i   s   utf-8s	   iso8859-1iÈ   t   OKR   t
   isSpeakings   Content-types	   text/htmlt   0iõ  s   Unknown POST message N(   R	   t   headerst	   getheadert   contentLengtht   intt   rfilet   readt	   inputBodyt
   startswitht   textt   unicodet   encodeR&   R   R   R+   R   t   send_headert   end_headerst   wfilet   writeR-   (   R	   R:   R8   R4   (    (    R   t   do_POSTM   s&     

(   R   R   R   t   handlersR.   RA   (    (    (    R   R   *   s    3	c          C   s¶   t  i d o t  i d }  n d }  t  i d o t t  i d ƒ } n d } t  i d o t t  i d ƒ } n d } d | f } d | f } t | t |  | ƒ } | i
 ƒ  d  S(   Ni   R   i   i@  i   iK   t    (   t   syst   argvR   R5   t   portR   t   server_addressR   R   t   httpdt   serve_forever(   R   RH   RG   R   RF   (    (    R   t   startc   s    t   __main__(   R   t   __id__t
   __author__t   __version__t   __date__t   __copyright__t   __license__R   R   t   BaseHTTPServerR   t   BaseHTTPRequestHandlerRD   R)   R   R   RJ   R   (   RD   RP   R   RQ   RJ   R)   RM   RO   R   R   R   RL   RS   RN   (    (    R   t   ?   s   		9	