
9^c           @  s*  d  d l  m Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l	 m
 Z
 d  d l m Z d  d l m Z m Z d  d l m Z d  d l m Z y d  d l m Z Wn* e k
 r d  d	 l m Z d
   Z n Xyr d e
 j k re Z nV d e
 j k r>d  d l m Z e Z n. d e
 j k rfd  d l m Z e Z n e Z Wn e k
 re Z n Xd  d l m  Z  d  d l! m" Z" m# Z# m$ Z$ m% Z% e j& d e j'  Z( d Z) e* e
 d d  Z+ e* e
 d d  Z, e j- e.  Z/ d e f d     YZ0 d   Z1 d S(   i(   t   print_functionN(   t   settings(   t   ImproperlyConfigured(   t   BaseCommandt   CommandError(   t   get_internal_wsgi_application(   t   utils(   t   gen_filenames(   t   get_reloaderc           C  s   t    j   S(   N(   R   t   watched_files(    (    (    sV   /tmp/pip-unpacked-wheel-a0M10Y/django_extensions/management/commands/runserver_plus.pyR      s    s   whitenoise.runserver_nostatics   django.contrib.staticfiles(   t   StaticFilesHandlert   staticfiles(   t   null_technical_500_response(   t   RedirectHandlert   has_ipdbt   setup_loggert   signalcommands   ^(?:
(?P<addr>
    (?P<ipv4>\d{1,3}(?:\.\d{1,3}){3}) |         # IPv4 address
    (?P<ipv6>\[[a-fA-F0-9:]+\]) |               # IPv6 address
    (?P<fqdn>[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*) # FQDN
):)?(?P<port>\d+)$t   8000t&   RUNSERVERPLUS_POLLER_RELOADER_INTERVALi   t"   RUNSERVERPLUS_POLLER_RELOADER_TYPEt   autot   Commandc           B  s   e  Z d  Z e Z d Z d Z d   Z e d    Z	 d   Z
 e d    Z e d    Z e d    Z e d	    Z e d
    Z e d    Z RS(   s0   Starts a lightweight Web server for development.s   .crts   .keyc         C  sS  t  t |   j |  | j d d d d d | j d d d d	 d
 d d t d d | j d d d d
 d d t d d | j d d d	 d
 d d d | j d d d d
 d d d | j d d d	 d
 d d d | j d d
 d d d  d d | j d d d	 d t d d | j   } | j d d
 d  d d! d" t d d# | j d$ d
 d  d d! d" t d d% | j d& d
 d' d d! d" t d d( | j d) d
 d* d d+ d" t d g  d d, | j d- d
 d. d d! d" t	 d t
 d d/ t
 | j d0 d
 d1 d d! d" t d t d d2 t | j d3 d d	 d
 d4 d t d d5 | j d6 d d	 d
 d7 d t d d8 | j d9 d d	 d
 d: d t d d; | j d< d
 d= d d! d d> d d? | j d@ d
 dA d d	 d t d dB | j dC d
 dD d d	 d t d dE f t rO| j dF d d d
 dG d t d dH | j dI d d	 d
 dJ d t d dK n  d  S(L   Nt   addrportt   nargst   ?t   helps$   Optional port number, or ipaddr:ports   --ipv6s   -6t   actiont
   store_truet   destt   use_ipv6t   defaults#   Tells Django to use a IPv6 address.s
   --noreloadt   store_falset   use_reloaders*   Tells Django to NOT use the auto-reloader.s	   --browsert   open_browsers   Tells Django to open a browser.s   --nothreadingt   threadeds!   Do not run in multithreaded mode.s
   --threadeds   Run in multithreaded mode.s   --outputt   output_filesR   Specifies an output file to send a copy of all messages (not flushed immediately).s   --print-sqls%   Print SQL queries as they're executeds   --certt	   cert_patht   storet   types(   Deprecated alias for --cert-file option.s   --cert-files   SSL .crt file path. If not provided path from --key-file will be selected. Either --cert-file or --key-file must be provided to use SSL.s
   --key-filet   key_file_paths   SSL .key file path. If not provided path from --cert-file will be selected. Either --cert-file or --key-file must be provided to use SSL.s   --extra-filet   extra_filest   appendsQ   auto-reload whenever the given file changes too (can be specified multiple times)s   --reloader-intervalt   reloader_intervalsV   After how many seconds auto-reload should scan for updates in poller-mode [default=%s]s   --reloader-typet   reloader_typesH   Werkzeug reloader type [options are auto, watchdog, or stat, default=%s]s   --pdbt   pdbs-   Drop into pdb shell at the start of any view.s   --ipdbt   ipdbs.   Drop into ipdb shell at the start of any view.s   --pmt   pms;   Drop into (i)pdb shell if an exception is raised in a view.s   --startup-messagest   startup_messagest   reloadsE   When to show startup messages: reload [default], once, always, never.s   --keep-meta-shutdownt   keep_meta_shutdown_funcs   Keep request.META['werkzeug.server.shutdown'] function which is automatically removed because Django debug pages tries to call the function and unintentionally shuts down the Werkzeug server.s   --nopint   nopins+   Disable the PIN in werkzeug. USE IT WISELY!s
   --nostatict   use_static_handlersC   Tells Django to NOT automatically serve static files at STATIC_URL.s
   --insecuret   insecure_servings3   Allows serving static files even if DEBUG is False.(   t   superR   t   add_argumentst   add_argumentt   Falset   Truet   Nonet   add_mutually_exclusive_groupt   strt   intt    DEFAULT_POLLER_RELOADER_INTERVALt   DEFAULT_POLLER_RELOADER_TYPEt   USE_STATICFILES(   t   selft   parsert
   cert_group(    (    sV   /tmp/pip-unpacked-wheel-a0M10Y/django_extensions/management/commands/runserver_plus.pyR6   @   s^    !$$$
c           sy  | d } | d } | d k r8 t  j j d  |  _ nF | d k r] t  j j d  |  _ n! | d k ru t |  _ n	 t |  _ d t  j d <t |  j d  r d  |  j _	 n  t
 t |  j d	 | d
 t t  } t j d  } | j t j  | j |  t | _ | d ry d d  l  Wn t k
 r:d   n Xy d d  l   d d  l   Wn t k
 rpd    n Xt t d d   d t j f     f d     Y} | t _ n  | d } | d }	 | d }
 y d d l m } Wn8 t k
 r | s|	 s|
 rt d   n  t }
 n X| s6|	 s6t j rd } t t d d   pTt j  } | | k rt! | t"  r| | f 7} q| | g 7} qn  | rd | _# n |	 rd | _# n  d   } d d l$ m% } |
 r| n t& | _' | d |  _( |  j( rt) j* rt d   n  t |  _+ | sIy t j, } WqIt- k
 rEqIXn  | sdd |  _. t/ |  _0 n t1 j2 t3 |  } | d  k rt d |   n  | j4   \ |  _. } } } |  _0 |  j0 j5   st d |  j0   n  |  j. r;| r|  j. d  d !|  _. t |  _( t |  _+ q;|  j( r;| r;t d! |  j.   q;n  |  j. sh|  j( rSd" n d# |  _. t |  _+ n  |  j6 |  d  S($   NR   R/   R0   t   RUNSERVER_PLUS_SHOW_MESSAGESt   oncet   nevert   1t   endingt   filenameR#   t   werkzeugt	   print_sqlit!   RUNSERVER_PLUS_PRINT_SQL_TRUNCATEi  t   PrintQueryWrapperc             s    e  Z d     f d   Z RS(   c      	     s  t  j    } z t j j |  | |  SWd  t  j    | } |  j j j |  j | |  }  r |   }  j | d t	 d d } n    r   j
 |   j j d    j j    } n  t j |  t j d  t j d | |  j j f  t j d  Xd  S(   Nt   reindent_alignedt   truncate_stringsi  t   sqlt    s&   [Execution time: %.6fs] [Database: %s](   t   timeR   t   CursorWrappert   executet   dbt   opst   last_executed_queryt   cursort   formatR9   t	   highlightt   lexerst   get_lexer_by_namet
   formatterst   TerminalFormattert   loggert   infot   alias(   RA   RP   t   paramst	   starttimet   execution_timet   raw_sql(   t   pygmentst   sqlparset   truncate(    sV   /tmp/pip-unpacked-wheel-a0M10Y/django_extensions/management/commands/runserver_plus.pyRT      s"    
(    (   t   __name__t
   __module__RT   (    (   Rf   Rg   Rh   (    sV   /tmp/pip-unpacked-wheel-a0M10Y/django_extensions/management/commands/runserver_plus.pyRM      s   R,   R-   R.   (   t   PdbMiddlewares   django-pdb is required for --pdb, --ipdb and --pm options. Please visit https://pypi.python.org/pypi/django-pdb or install via pip. (pip install django-pdb)s#   django_pdb.middleware.PdbMiddlewaret
   MIDDLEWAREc         S  s^   t    r d d  l } | } n d d  l } | } t d | | f d t j | j |  d  S(   Nis   Exception occured: %s, %st   file(   R   R-   R,   t   printt   syst   stderrt   post_mortem(   t   requestt   exc_typet	   exc_valuet   tbR-   t   pR,   (    (    sV   /tmp/pip-unpacked-wheel-a0M10Y/django_extensions/management/commands/runserver_plus.pyt
   postmortem   s    		(   t   debugR   s"   Your Python does not support IPv6.RQ   s5   "%s" is not a valid port number or address:port pair.s   %r is not a valid port number.i   s!   "%s" is not a valid IPv6 address.s   ::1s	   127.0.0.1(7   t   ost   environt   gett   show_startup_messagesR8   R9   t   hasattrRp   R:   RH   R   R_   R   Ri   t   loggingt	   getLoggert   setLevelt   INFOt
   addHandlert	   propagateRg   t   ImportErrort   pygments.lexerst   pygments.formatterst   getattrR   R   t   CursorDebugWrappert   django_pdb.middlewareRk   R   t   DEBUGt   MIDDLEWARE_CLASSESt
   isinstancet   tuplet   always_breakt   django.viewsRx   R   t   technical_500_responseR   t   sockett   has_ipv6t	   _raw_ipv6t!   RUNSERVERPLUS_SERVER_ADDRESS_PORTt   AttributeErrort   addrt   DEFAULT_PORTt   portt   ret   matcht
   naiveip_ret   groupst   isdigitt	   inner_run(   RA   t   argst   optionsR   R/   t   logredirectt
   werkloggerRM   t
   pdb_optiont   ipdb_optionR.   Rk   t
   middlewaret   settings_middlewareRw   Rx   t   mt   _ipv4t   _ipv6t   _fqdn(    (   Rf   Rg   Rh   sV   /tmp/pip-unpacked-wheel-a0M10Y/django_extensions/management/commands/runserver_plus.pyt   handlev   s    

		


%



			!			c           sx  yk d d l  m } m } d d l m } t j rj y t   Wqj t k
 rf |  j	 rg t
 d  qg qj Xn  Wn t k
 r t d   n Xd | f    f d     Y   d }  d	 }  d
 } t j d k r d p d }  d }	  d }
  d }  d |  _ |  j	 r$t
 d  n  t |  d  rI|  j d |  j	  n |  j d |  j	  y |  j   Wn t k
 r}n Xt   } t r d }  d } | rt j s| rt |  } qn   d s d ry d d  l } Wn t k
 rt d   n X|  j   \ } } t j j |  \ } } t j j |  \ } } yh d d l m } t j j |  rt j j |  r| | f } n! | t j j  | |  d d } Wqt k
 r|  j	 rt
 d  n  d } qXn d  } d | rd  n d! |  j" s|  j# n
 d" |  j# |  j$ f } |  j	 rt
 d# t% j&   t j' f  t
 d$ | f  t
 d%  t
 d& |  n  | rd d  l( } | j) |  n  | rt j* r|	 j+ t, d'   t-     n  | sd( t j. d) <n  t j. j/ d)  d( k r(|  j rd* t j. d+ <n  | | t0  } n  | |  j# t1 |  j$  | d	 | d, t0 d |	 d |
 d | d | d-   d. | d  S(/   Ni(   t
   run_simplet   DebuggedApplication(   t   WSGIRequestHandlersD   Wrapping internal werkzeug logger for color highlighting has failed!s   Werkzeug is required to use runserver_plus.  Please visit http://werkzeug.pocoo.org/ or install via pip. (pip install Werkzeug)R   c             s   e  Z    f d    Z RS(   c           s-   t    |   j   }  d s) | d =n  | S(   NR1   s   werkzeug.server.shutdown(   R5   t   make_environ(   RA   Rz   (   R   R   (    sV   /tmp/pip-unpacked-wheel-a0M10Y/django_extensions/management/commands/runserver_plus.pyR     s    

(   Ri   Rj   R   (    (   R   R   (    sV   /tmp/pip-unpacked-wheel-a0M10Y/django_extensions/management/commands/runserver_plus.pyR     s   R"   R    R!   t   win32s
   CTRL-BREAKs	   CONTROL-CR(   R*   R+   R2   s   Performing system checks...
t   checkt   display_num_errorsR3   R4   R$   R'   ss   Python OpenSSL Library is required to use runserver_plus with ssl support. Install via pip (pip install pyOpenSSL).(   t   make_ssl_devcertt   hostt	   localhosts<   Werkzeug version is less than 0.9, trying adhoc certificate.t   adhocs   %s://%s:%s/t   httpst   https   [%s]s%   
Django version %s, using settings %rs#   Development server is running at %ss8   Using the Werkzeug debugger (http://werkzeug.pocoo.org/)s   Quit the server with %s.c         S  s   t  |   j d  S(   Ns   .mo(   R<   t   endswith(   RI   (    (    sV   /tmp/pip-unpacked-wheel-a0M10Y/django_extensions/management/commands/runserver_plus.pyt   <lambda>j  RQ   t   truet   WERKZEUG_RUN_MAINt   offt   WERKZEUG_DEBUG_PINt   use_debuggert   request_handlert   ssl_context(2   RJ   R   R   t   werkzeug.servingR   R   R   t   set_werkzeug_log_colort	   ExceptionR|   Rn   R   R   Ro   t   platformR2   R}   R   t   validatet   check_migrationsR   R   R@   R
   t   OpenSSLt   determine_ssl_files_pathsRy   t   patht   splitt   splitextR   t   existst   joinR:   R   R   R   t   djangot   get_versiont   SETTINGS_MODULEt
   webbrowsert   opent   USE_I18Nt   extendt   filterR   Rz   R{   R9   R=   (   RA   R   R   R   t   _WSGIRequestHandlerR"   R    R!   t   quit_commandR(   R*   R+   t   handlerR3   R4   R   t   certfilet   keyfilet   dir_patht   roott   _R   R   t   bind_urlR   (    (   R   R   sV   /tmp/pip-unpacked-wheel-a0M10Y/django_extensions/management/commands/runserver_plus.pyR     s    		





		


$%	8	
	c         C  sd   | j  d  p d } | j  d  p' d } |  j | | |  j  } |  j | | |  j  } | | f S(   NR'   RQ   R$   (   R{   t   _determine_path_for_filet   DEFAULT_CRT_EXTENSIONt   DEFAULT_KEY_EXTENSION(   t   clsR   R'   R$   t	   cert_filet   key_file(    (    sV   /tmp/pip-unpacked-wheel-a0M10Y/django_extensions/management/commands/runserver_plus.pyR     s
    c         C  s\   |  j  | |  } |  j |  p- |  j |  } |  j |  pB | } t j j | | |  S(   N(   t#   _get_directory_basing_on_file_pathst   _get_file_namet   _get_extensionRy   R   R   (   R   t   current_file_patht   other_file_patht   expected_extensiont	   directoryt	   file_namet	   extension(    (    sV   /tmp/pip-unpacked-wheel-a0M10Y/django_extensions/management/commands/runserver_plus.pyR     s    c         C  s(   |  j  |  p' |  j  |  p' t j   S(   N(   t   _get_directoryRy   t   getcwd(   R   R   R   (    (    sV   /tmp/pip-unpacked-wheel-a0M10Y/django_extensions/management/commands/runserver_plus.pyR     s    c         C  s   t  j j |  d S(   Ni    (   Ry   R   R   (   R   t	   file_path(    (    sV   /tmp/pip-unpacked-wheel-a0M10Y/django_extensions/management/commands/runserver_plus.pyR     s    c         C  s$   t  j j t  j j |  d  d S(   Ni   i    (   Ry   R   R   R   (   R   R   (    (    sV   /tmp/pip-unpacked-wheel-a0M10Y/django_extensions/management/commands/runserver_plus.pyR     s    c         C  s   t  j j |  d S(   Ni   (   Ry   R   R   (   R   R   (    (    sV   /tmp/pip-unpacked-wheel-a0M10Y/django_extensions/management/commands/runserver_plus.pyR     s    (   Ri   Rj   R   R8   t   requires_system_checksR   R   R6   R   R   R   t   classmethodR   R   R   R   R   R   (    (    (    sV   /tmp/pip-unpacked-wheel-a0M10Y/django_extensions/management/commands/runserver_plus.pyR   8   s   	6	c            sd   d d l  m }  d d l m } d d l m   |     | j      f d   } | | _ d S(   s%   Try to set color to the werkzeug log.i(   t   color_style(   R   (   t   _logc           s<  y7 d |  j    |  j   | | f } t | d  } Wn t k
 rW  | | |  SX| d d k rz  j |  } n | d d k r  j |  } n | d k r  j |  } nq | d d k r  j |  } nO | d k r  j |  } n1 | d d	 k r j	 |  } n  j
 |  }   | |  d  S(
   Ns   %s - - [%s] %si   i    t   2RG   t   304t   3t   404t   4(   t   address_stringt   log_date_time_stringR<   R   t   HTTP_SUCCESSt	   HTTP_INFOt   HTTP_NOT_MODIFIEDt   HTTP_REDIRECTt   HTTP_NOT_FOUNDt   HTTP_BAD_REQUESTt   HTTP_SERVER_ERROR(   RA   R&   t   messageR   t   msgt	   http_code(   R   t	   _orig_logt   _style(    sV   /tmp/pip-unpacked-wheel-a0M10Y/django_extensions/management/commands/runserver_plus.pyt   werk_log  s,    		N(   t   django.core.management.colorR   R   R   t   werkzeug._internalR   t   log(   R   R   R	  (    (   R   R  R  sV   /tmp/pip-unpacked-wheel-a0M10Y/django_extensions/management/commands/runserver_plus.pyR     s    		(2   t
   __future__R    R~   Ry   R   R   Ro   RR   R   t   django.confR   t   django.core.exceptionsR   t   django.core.management.baseR   R   t   django.core.servers.basehttpR   t   django.db.backendsR   t   django.utils.autoreloadR   R   R   t   INSTALLED_APPSR8   R@   t#   django.contrib.staticfiles.handlersR
   R9   t   staticfiles.handlerst/   django_extensions.management.technical_responseR   t"   django_extensions.management.utilsR   R   R   R   t   compilet   XR   R   R   R>   R?   R   Ri   R_   R   R   (    (    (    sV   /tmp/pip-unpacked-wheel-a0M10Y/django_extensions/management/commands/runserver_plus.pyt   <module>   sP   			

" p