ó
ßüÚ\c           @` s   d  d l  m Z m Z m Z d  d l m Z d  d l m Z d  d l m	 Z	 m
 Z
 m Z m Z d j ƒ  Z d „  Z d	 d	 d „ Z d „  Z d	 S(
   i    (   t   print_functiont   divisiont   absolute_import(   t   gen(   t   IOLoop(   t   parse_addresst   unparse_addresst   parse_host_portt   unparse_host_ports  
Warning: Your terminal does not set locales.

If you use unicode text inputs for command line options then this may cause
undesired behavior.  This is rare.

If you don't use unicode characters in command line options then you can safely
ignore this message.  This is the common case.

You can support unicode inputs by specifying encoding environment variables,
though exact solutions may depend on your system:

    $ export LC_ALL=C.UTF-8
    $ export LANG=C.UTF-8

For more information see: http://click.pocoo.org/5/python3/
c          C` sx   d d l  }  d „  |  j _ y d d l m } | j ƒ  Wn8 t t f k
 rs } d d l }  |  j t d t	 ƒn Xd S(   s=   Ensures that the environment is good for unicode on Python 3.i    Nc           S` s   d  S(   N(   t   None(    (    (    s4   lib/python2.7/site-packages/distributed/cli/utils.pyt   <lambda>&   t    (   t   _unicodefunt   err(
   t
   click.coret   coret   _verify_python3_envt   clickR   t	   TypeErrort   RuntimeErrort   echot   py3_err_msgt   True(   R   R   t   e(    (    s4   lib/python2.7/site-packages/distributed/cli/utils.pyt   check_python_3!   s    c         ` ss   d d l  ‰ ˆ p t j ƒ  ‰ i  ‰ ‡  ‡ ‡ ‡ f d †  } x0 ˆ j ˆ j g D] } ˆ j  | | ƒ ˆ | <qO Wd S(   sÓ   
    Install global signal handlers to halt the Tornado IOLoop in case of
    a SIGINT or SIGTERM.  *cleanup* is an optional callback called,
    before the loop stops, with a single signal number argument.
    i    Nc         ` sC   t  j ‡ ‡ ‡  f d †  ƒ } ˆ j | ƒ ˆ j ˆ  ˆ ˆ  ƒ d  S(   Nc           3` s0   z ˆ  d  k	 r ˆ  ˆ ƒ Vn  Wd  ˆ j ƒ  Xd  S(   N(   R	   t   stop(    (   t   cleanupt   loopt   sig(    s4   lib/python2.7/site-packages/distributed/cli/utils.pyt   cleanup_and_stop?   s    (   R   t	   coroutinet   add_callback_from_signalt   signal(   R   t   frameR   (   R   R   t   old_handlersR    (   R   s4   lib/python2.7/site-packages/distributed/cli/utils.pyt   handle_signal>   s    (   R    R   t   currentt   SIGINTt   SIGTERM(   R   R   R#   R   (    (   R   R   R"   R    s4   lib/python2.7/site-packages/distributed/cli/utils.pyt   install_signal_handlers2   s    c         C` sé   t  |  p d ƒ \ } } t | | d k	 r0 | n | ƒ \ } } | d k r` | d k r` | } n  | r‘ | r‘ | | k r‘ t d |  | f ƒ ‚ n  | d k r² | d k	 r² | } n  | d k rÇ | } n  t | | ƒ } t | | ƒ } | S(   sF   
    Process the *host* and *port* CLI options.
    Return a URI.
    R   s7   port number given twice in options: host %r and port %rN(   R   R   R	   t
   ValueErrorR   R   (   t   host_argt   port_argt   default_portt   schemet   loct   hostt   portt   addr(    (    s4   lib/python2.7/site-packages/distributed/cli/utils.pyt   uri_from_host_portP   s     $			N(   t
   __future__R    R   R   t   tornadoR   t   tornado.ioloopR   t   distributed.commR   R   R   R   t   lstripR   R   R	   R'   R1   (    (    (    s4   lib/python2.7/site-packages/distributed/cli/utils.pyt   <module>   s   "	