
v^                 @   s   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 m Z m Z d  d l m Z e j d e j  Z Gd d	   d	 e	  Z e Z d S)
    N)datetime)settings)BaseCommandCommandError)
WSGIServerget_internal_wsgi_applicationrun)
autoreloadz^(?:
(?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+)$c                   s   e  Z d  Z d Z d Z d Z d Z d Z d Z d Z	 e
 Z d d	   Z   f d
 d   Z d d   Z d d   Z d d   Z d d   Z   S)Commandz0Starts a lightweight Web server for development.Fshutdown_messagez	127.0.0.1z::1Z8000httpc          	   C   s}   | j  d d d d d | j  d d d d	 d
 d d d | j  d d d d
 d d d | j  d d d d
 d d d d  S)Naddrportnargs?helpz$Optional port number, or ipaddr:portz--ipv6z-6action
store_truedestuse_ipv6z$Tells Django to use an IPv6 address.z--nothreadingstore_falseuse_threadingz"Tells Django to NOT use threading.z
--noreloaduse_reloaderz*Tells Django to NOT use the auto-reloader.)add_argument)selfparser r   K/tmp/pip-build-8lau8j11/django/django/core/management/commands/runserver.pyadd_arguments$   s    zCommand.add_argumentsc                s.   | d r d t  j d <t   j | |   d  S)NZno_colorZnocolorZDJANGO_COLORS)osenvironsuperexecute)r   argsoptions)	__class__r   r   r!   6   s    
zCommand.executec             O   s   t    S)z/Return the default WSGI handler for the runner.)r   )r   r"   r#   r   r   r   get_handler>   s    zCommand.get_handlerc             O   s  t  j r  t  j r  t d   | d |  _ |  j rL t j rL t d   d |  _ | d sw d |  _ |  j	 |  _
 n t j t | d  } | d  k r t d | d   | j   \ |  _ } } } |  _
 |  j
 j   s t d |  j
   |  j rM| r*|  j d	 d  |  _ d
 |  _ d
 |  _ n# |  j rM| rMt d |  j   |  j s|  j rh|  j n |  j |  _ |  j |  _ |  j |   d  S)Nz6You must set settings.ALLOWED_HOSTS if DEBUG is False.r   z"Your Python does not support IPv6.Fr    z5"%s" is not a valid port number or address:port pair.z%r is not a valid port number.   Tz!"%s" is not a valid IPv6 address.)r   DEBUGZALLOWED_HOSTSr   r   sockethas_ipv6	_raw_ipv6addrdefault_portportrematch
naiveip_regroupsisdigitdefault_addr_ipv6default_addrr   )r   r"   r#   mZ_ipv4Z_ipv6Z_fqdnr   r   r   handleB   s6    	
	!			zCommand.handlec             K   s:   | d } | r& t  j |  j |  n |  j d |  d S)z1Run the server, using the autoreloader if needed.r   N)r	   Zrun_with_reloader	inner_run)r   r#   r   r   r   r   r   a   s    
zCommand.runc             O   s  t  j   | d } | j d d  } t j d k r; d n d } |  j j d  |  j d d	  |  j   t	 j
   j d
  } |  j j |  |  j j d d |  j   d t j d |  j d |  j r d |  j n |  j d |  j d | i  yJ |  j | |   } t |  j t |  j  | d |  j d | d |  j Wn t k
 r} zs t j d t j d t j d i }	 y |	 | j }
 Wn t k
 r| }
 Yn X|  j j d |
  t j  d  WYd  d  } ~ Xn5 t! k
 r| r|  j j |  t j" d  Yn Xd  S)Nr   r   r&   win32z
CTRL-BREAKz	CONTROL-CzPerforming system checks...

Zdisplay_num_errorsTz%B %d, %Y - %XzDjango version %(version)s, using settings %(settings)r
Starting development server at %(protocol)s://%(addr)s:%(port)s/
Quit the server with %(quit_command)s.
versionr   protocolr-   z[%s]r/   quit_commandZipv6	threading
server_clsz.You don't have permission to access that port.zThat port is already in use.z%That IP address can't be assigned to.z	Error: %sr'   r   )#r	   Zraise_last_exceptiongetsysplatformstdoutwritecheckZcheck_migrationsr   nowstrftimeget_versionr   ZSETTINGS_MODULEr<   r,   r-   r/   r%   r   intr   r?   OSErrorerrnoZEACCESZ
EADDRINUSEZEADDRNOTAVAILKeyErrorstderrr   _exitKeyboardInterruptexit)r   r"   r#   r>   r   r=   rF   handlereZERRORSZ
error_textr   r   r   r9   j   sF    


						zCommand.inner_run)zshutdown_message)__name__
__module____qualname__r   Zrequires_system_checksZstealth_optionsr6   r5   r.   r<   r   r?   r   r!   r%   r8   r   r9   r   r   )r$   r   r
      s   	r
   )rK   r   r0   r*   rA   r   Zdjango.confr   Zdjango.core.management.baser   r   Zdjango.core.servers.basehttpr   r   r   Zdjango.utilsr	   compileXr2   r
   ZBaseRunserverCommandr   r   r   r   <module>   s   