Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
python3-dmapi / usr / lib / python3.6 / site-packages / dmapi / __pycache__ / wsgi.cpython-36.pyc
Size: Mime:
3

ÿn‚a¹@ã@sJdZddlZddlZddlZddlZddlZddlZddlZddl	m
Zddlm
Z
ddlmZddlmZddlZddlZddlZddlZddlZddlmZddlmZmZmZdd	lmZej j!Z!ej"e#ƒZ$Gd
d„de
j%ƒZ&Gdd
„d
ej'ƒZ'Gdd„de(ƒZ)Gdd„de)ƒZ*Gdd„de*ƒZ+Gdd„de(ƒZ,Gdd„de(ƒZ-dS)z.Utility methods for working with WSGI servers.éN)Úlog)Úservice)Úexcutils)Údeploy)Ú	exception)Ú_Ú_LEÚ_LI)Úutilsc@sTeZdZdZejjZdddejjdddfdd„Z	d	d
„Z
dd„Zd
d„Zdd„Z
dS)ÚServerzAServer class to manage a WSGI server, serving a WSGI application.z0.0.0.0rNé€Fc

Cs\tjjtj_||_||_d|_||_|p,|j	|_
tj|j
ƒ|_t
jd|jƒ|_||_|	|_tjjpfd|_|dkr‚tjtdƒd‚||f}
y4tj|
d|
dtjtjƒd}|d}|d
}
Wntk
rØtj}YnXytj|
||d|_Wn.tk
rtj t!dƒ||d	œƒ‚YnX|jj"ƒdd
…\|_#|_$tj%t&dƒ|j|j#|j$dœƒdS)aInitialize, but do not start, a WSGI server.

        :param name: Pretty name for logging.
        :param app: The WSGI application to serve.
        :param host: IP address to serve the application.
        :param port: Port number to server the application.
        :param pool_size: Maximum number of eventlets to spawn concurrently.
        :param backlog: Maximum number of queued connections.
        :param max_url_len: Maximum length of permitted URLs.
        :returns: None
        :raises: dmapi.exception.InvalidInput
        Nzdmapi.%s.wsgi.serverézThe backlog must be more than 0)Úreasonr)Úbacklogz#Could not bind to %(host)s:%(port)s)ÚhostÚportéz'%(name)s listening on %(host)s:%(port)s)Únamerréÿÿÿÿ)'ÚCONFÚwsgiZmax_header_lineÚeventletZMAX_HEADER_LINErÚappÚ_serverÚ	_protocolÚdefault_pool_sizeÚ	pool_sizeZ	GreenPoolÚ_poolÚloggingÚ	getLoggerÚ_loggerÚ_use_sslÚ_max_url_lenÚclient_socket_timeoutrZInvalidInputrÚsocketZgetaddrinfoZ	AF_UNSPECZSOCK_STREAMÚ	ExceptionZAF_INETZlistenÚ_socketÚEnvironmentErrorÚLOGÚerrorrZgetsocknamerrÚinfor	)
ÚselfrrrrrÚprotocolrZuse_sslZmax_url_lenZ	bind_addrr*Zfamily©r-ú/usr/lib/python3.6/wsgi.pyÚ__init__(sB


zServer.__init__cCsÎ|jjƒ}|jtjtjdƒ|jtjtjdƒttdƒrN|jtjtj	t
jjƒ|j
rzyÚt
jj}t
jj}t
jj}|r’tjj|ƒr’ttdƒ|ƒ‚|r´tjj|ƒr´ttdƒ|ƒ‚|rÖtjj|ƒrÖttdƒ|ƒ‚|j
rô|sè|rôttdƒƒ‚d||tjdœ}t
jjr ||d	<tj|d
<tj|f|Ž}WnHtk
rxtjƒ$tjt dƒ|j!|j"|j#dœƒWd
QRXYnXtjj$||j%|j&|j'|j(t
jj)dt
jj*|j+dœ
}|j,r¼|j,|d<t-j.f|Ž|_/d
S)zBStart serving a WSGI application.

        :returns: None
        r
ÚTCP_KEEPIDLEzUnable to find cert_file : %szUnable to find ca_file : %szUnable to find key_file : %szwWhen running server in SSL mode, you must specify both a cert_file and key_file option value in your configuration fileT)Zserver_sideZcertfileZkeyfileÚ	cert_reqsZca_certsr1z>Failed to start %(name)s on %(host)s:%(port)s with SSL support)rrrNF)
ÚfuncZsockZsiter,Zcustom_poolrZ
log_formatÚdebugZ	keepaliveZsocket_timeoutZurl_length_limit)0r&ÚdupZ
setsockoptr$Z
SOL_SOCKETZSO_REUSEADDRZSO_KEEPALIVEÚhasattrZIPPROTO_TCPr0rrZtcp_keepidler!Zssl_ca_fileZ
ssl_cert_fileZssl_key_fileÚosÚpathÚexistsÚRuntimeErrorrÚsslZ	CERT_NONEZ
CERT_REQUIREDrZwrap_sslr%rZsave_and_reraise_exceptionr(r)rrrrZserverrrrr Zwsgi_log_formatZ
keep_aliver#r"r
Zspawnr)r+Z
dup_socketZca_fileZ	cert_fileZkey_fileZ
ssl_kwargsZwsgi_kwargsr-r-r.Ústartasj














zServer.startcCs|jj|jƒdS)zIReset server greenpool size to default.

        :returns: None

        N)rÚresizer)r+r-r-r.Úreset´szServer.resetcCs2tjtdƒƒ|jdk	r.|jjdƒ|jjƒdS)zµStop this server.

        This is not a very nice action, as currently the method by which a
        server is stopped is by killing its eventlet.

        :returns: None

        zStopping WSGI server.Nr)r(r*r	rrr<Úkill)r+r-r-r.Ústop¼s	
zServer.stopcCsLy"|jdk	r |jjƒ|jjƒWn$tjk
rFtjtdƒƒYnXdS)z‡Block, until the server has stopped.

        Waits on the server's eventlet to finish, then returns.

        :returns: None

        NzWSGI server has stopped.)	rrZwaitallÚwaitÚgreenletZGreenletExitr(r*r	)r+r-r-r.r@Ìs

zServer.wait)Ú__name__Ú
__module__Ú__qualname__Ú__doc__rrrrZHttpProtocolr/r;r=r?r@r-r-r-r.r#s7SrcseZdZ‡fdd„Z‡ZS)ÚRequestcs>tjjr"|jtjjƒ}|r"||d<tt|ƒj|f|ž|ŽdS)Nzwsgi.url_scheme)rrZsecure_proxy_ssl_headerÚgetÚsuperrFr/)r+ÚenvironÚargsÚkwargsÚscheme)Ú	__class__r-r.r/Ýs
zRequest.__init__)rBrCrDr/Ú
__classcell__r-r-)rMr.rFÜsrFc@s$eZdZdZedd„ƒZdd„ZdS)ÚApplicationzEBase WSGI application wrapper. Subclasses need to implement __call__.cKs
|f|ŽS)aÄUsed for paste app factories in paste.deploy config files.

        Any local configuration (that is, values under the [app:APPNAME]
        section of the paste config) will be passed into the `__init__` method
        as kwargs.

        A hypothetical configuration would look like:

            [app:wadl]
            latest_version = 1.3
            paste.app_factory = dmapi.api.fancy_api:Wadl.factory

        which would result in a call to the `Wadl` class as

            import dmapi.api.fancy_api
            fancy_api.Wadl(latest_version='1.3')

        You could of course re-implement the `factory` method in subclasses,
        but using the kwarg passing it shouldn't be necessary.

        r-)ÚclsÚ
global_configÚlocal_configr-r-r.ÚfactoryèszApplication.factorycCsttdƒƒ‚dS)a\Subclasses will probably want to implement __call__ like this:

        @webob.dec.wsgify(RequestClass=Request)
        def __call__(self, req):
          # Any of the following objects work as responses:

          # Option 1: simple string
          res = 'message\n'

          # Option 2: a nicely formatted HTTP exception page
          res = exc.HTTPForbidden(explanation='Nice try')

          # Option 3: a webob Response object (in case you need to play with
          # headers, or you want to be treated like an iterable, or ...)
          res = Response()
          res.app_iter = open('somefile')

          # Option 4: any wsgi app to be run next
          res = self.application

          # Option 5: you can get a Response object for a wsgi app, too, to
          # play with headers etc
          res = req.get_response(self.application)

          # You can then just return your response...
          return res
          # ... or set req.response and return None.
          req.response = res

        See the end of http://pythonpaste.org/webob/modules/dec.html
        for more info.

        zYou must implement __call__N)ÚNotImplementedErrorr)r+rIZstart_responser-r-r.Ú__call__s"zApplication.__call__N)rBrCrDrEÚclassmethodrSrUr-r-r-r.rOåsrOc@sJeZdZdZedd„ƒZdd„Zdd„Zdd	„Ze	j
jed
dd„ƒZ
d
S)Ú
MiddlewarezòBase WSGI middleware.

    These classes require an application to be
    initialized that will be called next.  By default the middleware will
    simply call its wrapped app, or you can override __call__ to customize its
    behavior.

    cs‡‡fdd„}|S)aõUsed for paste app factories in paste.deploy config files.

        Any local configuration (that is, values under the [filter:APPNAME]
        section of the paste config) will be passed into the `__init__` method
        as kwargs.

        A hypothetical configuration would look like:

            [filter:analytics]
            redis_host = 127.0.0.1
            paste.filter_factory = dmapi.api.analytics:Analytics.factory

        which would result in a call to the `Analytics` class as

            import dmapi.api.analytics
            analytics.Analytics(app_from_paste, redis_host='127.0.0.1')

        You could of course re-implement the `factory` method in subclasses,
        but using the kwarg passing it shouldn't be necessary.

        csˆ|fˆŽS)Nr-)r)rPrRr-r.Ú_factoryGsz$Middleware.factory.<locals>._factoryr-)rPrQrRrXr-)rPrRr.rS0szMiddleware.factorycCs
||_dS)N)Úapplication)r+rYr-r-r.r/KszMiddleware.__init__cCsdS)záCalled on each request.

        If this returns None, the next application down the stack will be
        executed. If it returns a response then that response will be returned
        and execution will stop here.

        Nr-)r+Úreqr-r-r.Úprocess_requestNszMiddleware.process_requestcCs|S)z'Do whatever you'd like to the response.r-)r+Úresponser-r-r.Úprocess_responseXszMiddleware.process_response)ÚRequestClasscCs(|j|ƒ}|r|S|j|jƒ}|j|ƒS)N)r[Úget_responserYr])r+rZr\r-r-r.rU\s

zMiddleware.__call__N)rBrCrDrErVrSr/r[r]ÚwebobÚdecÚwsgifyrFrUr-r-r-r.rW&s
rWc@s2eZdZdZejjeddd„ƒZe	dd„ƒZ
dS)ÚDebugz Helper class for debugging a WSGI application.

    Can be inserted into any WSGI application chain to get information
    about the request and response.

    )r^cCsštdddƒx&t|jjƒƒD]\}}t|d|ƒq Wtƒ|j|jƒ}tdddƒx&t|jjƒƒD]\}}t|d|ƒqjWtƒ|j|jƒ|_|S)NÚ*é(z REQUEST ENVIRONú=z RESPONSE HEADERS)	ÚprintÚlistrIÚitemsr_rYZheadersÚprint_generatorÚapp_iter)r+rZÚkeyÚvalueZrespr-r-r.rUmszDebug.__call__ccsJtdddƒx.|D]&}tjjtj|ƒƒtjjƒ|VqWtƒdS)z6Iterator that prints the contents of a wrapper string.rdrez BODYN)rgÚsysÚstdoutÚwriteÚsixZ	text_typeÚflush)rkÚpartr-r-r.rj~s


zDebug.print_generatorN)rBrCrDrEr`rarbrFrUÚstaticmethodrjr-r-r-r.rcesrcc@sHeZdZdZdd„Zejjeddd„ƒZ	e
ejjeddd„ƒƒZd	S)
ÚRouterz9WSGI middleware that maps incoming requests to WSGI apps.cCs||_tjj|j|jƒ|_dS)aCreate a router for the given routes.Mapper.

        Each route in `mapper` must specify a 'controller', which is a
        WSGI app to call.  You'll probably want to specify an 'action' as
        well and have your controller be an object that can route
        the request to the action-specific method.

        Examples:
          mapper = routes.Mapper()
          sc = ServerController()

          # Explicit mapping of one route to a controller+action
          mapper.connect(None, '/svrlist', controller=sc, action='list')

          # Actions are all implicitly defined
          mapper.resource('server', 'servers', controller=sc)

          # Pointing to an arbitrary WSGI app.  You can specify the
          # {path_info:.*} parameter so the target app can be handed just that
          # section of the URL.
          mapper.connect(None, '/v1.0/{path_info:.*}', controller=BlogApp())

        N)ÚmapÚroutesZ
middlewareZRoutesMiddlewareÚ	_dispatchÚ_router)r+Zmapperr-r-r.r/Œs
zRouter.__init__)r^cCs|jS)zkRoute the incoming request to a controller based on self.map.

        If no match, return a 404.

        )ry)r+rZr-r-r.rU¨szRouter.__call__cCs(|jdd}|stjjƒS|d}|S)aDispatch the request to the appropriate controller.

        Called by self._router after matching the incoming request to a route
        and putting the information into req.environ.  Either returns 404
        or the routed WSGI app's response.

        zwsgiorg.routing_argsr
Z
controller)rIr`ÚexcZHTTPNotFound)rZÚmatchrr-r-r.rx±s


zRouter._dispatchN)rBrCrDrEr/r`rarbrFrUrtrxr-r-r-r.ru‰s
	ruc@s"eZdZdZddd„Zdd„ZdS)ÚLoaderz9Used to load WSGI applications from paste configurations.NcCsTd|_|ptjj}tjj|ƒs,tj|ƒ|_ntjj|ƒr>||_|jsPt	j
|d‚dS)zŸInitialize the loader, and attempt to find the config.

        :param config_path: Full or relative path to the paste config.
        :returns: None

        N)r7)Úconfig_pathrrZdmapi_api_paste_configr6r7ÚisabsZ	find_filer8rZConfigNotFound)r+r}r-r-r.r/ÅszLoader.__init__cCsby(tjd||jdœƒtjd|j|dStk
r\tjtdƒ|ƒtj||jd‚YnXdS)zðReturn the paste URLMap wrapped WSGI application.

        :param name: Name of the application to load.
        :returns: Paste URLMap object wrapping the requested application.
        :raises: `dmapi.exception.PasteAppNotFound`

        z"Loading app %(name)s from %(path)s)rr7z	config:%s)rzCouldn't lookup app: %sN)	r(r3r}rZloadappÚLookupErrorrrZPasteAppNotFound)r+rr-r-r.Úload_app×szLoader.load_app)N)rBrCrDrEr/r€r-r-r-r.r|Âs
r|).rEZos.pathr6r$r:rnrZ
eventlet.wsgirAZoslo_logrrZoslo_servicerZ
oslo_utilsrZpasterZroutes.middlewarerwrqZ	webob.decr`Z	webob.excZ
dmapi.confZdmapirZ
dmapi.i18nrrr	r
ZconfrrrBr(ZServiceBaserrFÚobjectrOrWrcrur|r-r-r-r.Ú<module>s:
:	A?$9