Ñò
²têMc        
   @   s#  d  d k  Z  d  d k Z d  d k Z d  d k Z d „  Z d „  Z d e f d „  ƒ  YZ e d „ Z d „  Z	 d „  Z
 e	 d	 d
 „ Z e	 d „ Z d e  i f d „  ƒ  YZ e d d h  d „ Z e d d h  d	 d „ Z e	 d d d „ Z e d j o) d e ƒ  GHe d e e d ƒ ƒ ƒ n d S(   iÿÿÿÿNc           C   s   t  i t  i ƒ  ƒ S(   s   Returns the IP address.(   t   sockett   gethostbynamet   gethostname(    (    (    sU   G:\My Dropbox\My Dropbox\Chris\Shared Programs\Chris's Programs\Python\Done\server.pyt   IP   s    c         C   s/   |  i  ƒ  } d | |  i f GH|  i | ƒ d S(   s   Sends back what is recieved.s"   Recieved %s from %s. Echoing back.N(   t   get_datat   client_addresst   send(   t   selft   data(    (    sU   G:\My Dropbox\My Dropbox\Chris\Shared Programs\Chris's Programs\Python\Done\server.pyt   echo   s    t   BreakOutErrorc           B   s   e  Z d  Z RS(   s4   An error raised when one wants out of a server loop.(   t   __name__t
   __module__t   __doc__(    (    (    sU   G:\My Dropbox\My Dropbox\Chris\Shared Programs\Chris's Programs\Python\Done\server.pyR
      s   c            s#   d t  i f ‡  f d †  ƒ  Y} | S(   s!   Create a handler from a function.t   Handlerc              s:   e  Z d  ˆ  ‡  f d †  Z d „  Z d „  Z d „  Z RS(   s.   A handler which calls %s in the handle method.c            s   ˆ  |  ƒ d S(   s   Handle request.N(    (   R   (   t   handle_func(    sU   G:\My Dropbox\My Dropbox\Chris\Shared Programs\Chris's Programs\Python\Done\server.pyt   handle   s    c         S   s   |  i  i | ƒ d S(   s
   Send data.N(   t   requestR   (   R   R   (    (    sU   G:\My Dropbox\My Dropbox\Chris\Shared Programs\Chris's Programs\Python\Done\server.pyR      s    c         S   s   |  i  i d ƒ S(   s   Recieve data.i   (   R   t   recv(   R   (    (    sU   G:\My Dropbox\My Dropbox\Chris\Shared Programs\Chris's Programs\Python\Done\server.pyR      s    c         S   s   t  |  i _ t ‚ d S(   s   End server loopN(   t   Truet   servert   shut_self_downR
   (   R   (    (    sU   G:\My Dropbox\My Dropbox\Chris\Shared Programs\Chris's Programs\Python\Done\server.pyt	   shut_down   s    (   R   R   R   R   R   R   (    (   R   (    sU   G:\My Dropbox\My Dropbox\Chris\Shared Programs\Chris's Programs\Python\Done\server.pyR      s
   		(   t   SocketServert   BaseRequestHandler(   R   R   (    (   R   sU   G:\My Dropbox\My Dropbox\Chris\Shared Programs\Chris's Programs\Python\Done\server.pyt   create_handler   s    c         C   s8   |  i  ƒ  } d | t | ƒ |  i f GH|  i | ƒ d S(   s2   Like echo, but works with objects besides strings.s(   Recived %s, a %s, from %s. Echoing back.N(   R   t   typeR   R   (   R   R   (    (    sU   G:\My Dropbox\My Dropbox\Chris\Shared Programs\Chris's Programs\Python\Done\server.pyt   pickle_echo&   s    c         C   s8   |  i  ƒ  d j o! |  i |  i i d ƒ t ‚ n d  S(   Ns   length pleaset   length(   R   R   R   t	   data_dictR
   (   R   (    (    sU   G:\My Dropbox\My Dropbox\Chris\Shared Programs\Chris's Programs\Python\Done\server.pyt   Big_HC_send,   s    i  c            s2   t  ˆ  ƒ ‰ d ˆ f ‡  ‡ ‡ f d †  ƒ  Y} | S(   s0   Creates a handler that works with larger stringst   Big_Handlerc              s:   e  Z d  ˆ  ‡  f d †  Z ‡ ‡ f d †  Z d „  Z RS(   sX   A handler which call %s in the handle method and pickle/unpickles on the way in and out.c            s   ˆ  |  ƒ d S(   s   Handle a request.N(    (   R   (   R   (    sU   G:\My Dropbox\My Dropbox\Chris\Shared Programs\Chris's Programs\Python\Done\server.pyR   5   s    c            s4   t  t d ˆ  d h t | ƒ d 6ƒˆ i | ƒ d S(   s
   Send data.t   portR   R   N(   t   runR   t   lenR   (   R   R   (   t   big_portt   base(    sU   G:\My Dropbox\My Dropbox\Chris\Shared Programs\Chris's Programs\Python\Done\server.pyR   8   s    #c         S   s   d S(   s   Recieved data.N(    (   R   (    (    sU   G:\My Dropbox\My Dropbox\Chris\Shared Programs\Chris's Programs\Python\Done\server.pyR   <   s    (   R   R   R   R   R   (    (   R   R#   R$   (    sU   G:\My Dropbox\My Dropbox\Chris\Shared Programs\Chris's Programs\Python\Done\server.pyR   3   s   (   R   (   R   R#   R   (    (   R   R$   R#   sU   G:\My Dropbox\My Dropbox\Chris\Shared Programs\Chris's Programs\Python\Done\server.pyt   Big_HC0   s    "c            s/   t  ˆ  ƒ ‰ d ˆ f ‡  ‡ f d †  ƒ  Y} | S(   s:   Creates a handler that works with objects besides strings,t   pickle_Handlerc              s=   e  Z d  ˆ  ‡  f d †  Z ‡ f d †  Z ‡ f d †  Z RS(   sX   A handler which call %s in the handle method and pickle/unpickles on the way in and out.c            s   ˆ  |  ƒ d S(   s   Handle a request.N(    (   R   (   R   (    sU   G:\My Dropbox\My Dropbox\Chris\Shared Programs\Chris's Programs\Python\Done\server.pyR   G   s    c            s   ˆ  i  |  t i | ƒ ƒ d S(   s
   Send data.N(   R   t   cPicklet   dumps(   R   R   (   R$   (    sU   G:\My Dropbox\My Dropbox\Chris\Shared Programs\Chris's Programs\Python\Done\server.pyR   J   s    c            s   t  i ˆ  i |  ƒ ƒ S(   s   Recieved data.(   R'   t   loadsR   (   R   (   R$   (    sU   G:\My Dropbox\My Dropbox\Chris\Shared Programs\Chris's Programs\Python\Done\server.pyR   M   s    (   R   R   R   R   R   (    (   R   R$   (    sU   G:\My Dropbox\My Dropbox\Chris\Shared Programs\Chris's Programs\Python\Done\server.pyR&   E   s   (   R   (   R   R&   (    (   R   R$   sU   G:\My Dropbox\My Dropbox\Chris\Shared Programs\Chris's Programs\Python\Done\server.pyt	   pickle_HCB   s    t	   EB_Serverc           B   s    e  Z d  Z d „  Z d „  Z RS(   sá   Error Breakout Server
When you use server.shutdown, it waits for the handle to end, but this is the only place to do stuff.
So the error breakout server uses errors to break out of a server loop, which will be caught outside.c         C   s#   t  i i |  | | ƒ t |  _ d S(   s    Init, set self.shutdown to FalseN(   R   t	   TCPServert   __init__t   FalseR   (   R   t   addresst   handler(    (    sU   G:\My Dropbox\My Dropbox\Chris\Shared Programs\Chris's Programs\Python\Done\server.pyR-   W   s    c         C   s.   |  i  o
 t ‚ n t i i |  | | ƒ d S(   s   Test to see if shutting down.N(   R   R
   R   R,   t   handle_error(   R   R   R/   (    (    sU   G:\My Dropbox\My Dropbox\Chris\Shared Programs\Chris's Programs\Python\Done\server.pyR1   \   s    
 
(   R   R   R   R-   R1   (    (    (    sU   G:\My Dropbox\My Dropbox\Chris\Shared Programs\Chris's Programs\Python\Done\server.pyR+   R   s   	t    i   c         C   sL   y2 t  | | f t |  ƒ ƒ } | | _ | i ƒ  Wn t j
 o n Xd S(   s(   Create a server and make it run forever.N(   R+   R   R   t   serve_foreverR
   (   R   t   hostR    R   R   (    (    sU   G:\My Dropbox\My Dropbox\Chris\Shared Programs\Chris's Programs\Python\Done\server.pyR!   a   s    	 c         C   sO   y5 t  | | f t |  | ƒ ƒ } | | _ | i ƒ  Wn t j
 o n Xd  S(   N(   R+   R%   R   R3   R
   (   R   R4   R    R   R#   R   (    (    sU   G:\My Dropbox\My Dropbox\Chris\Shared Programs\Chris's Programs\Python\Done\server.pyt   big_runi   s    	 c         C   sL   y2 t  | | f t |  ƒ ƒ } t | _ | i ƒ  Wn t j
 o n Xd S(   s3   Run a server that can take objects besides strings.N(   R+   R*   R   R3   R
   (   R   R4   R    R   (    (    sU   G:\My Dropbox\My Dropbox\Chris\Shared Programs\Chris's Programs\Python\Done\server.pyt
   pickle_runp   s    	 t   __main__s   The IP is %s.R    s   What port? (   R   R'   R    t   timeR   R	   t	   ExceptionR
   R   R   R   R%   R*   R,   R+   R!   R5   R6   R   t   intt	   raw_input(    (    (    sU   G:\My Dropbox\My Dropbox\Chris\Shared Programs\Chris's Programs\Python\Done\server.pyt   <module>   s   0				