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 / dist-packages / dmapi / __pycache__ / wsgi.cpython-35.pyc
Size: Mime:


èáþ\¹@ã@sÑdZddlZddlZddlZddlZddlZddlZddlZddl	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	@syeZdZdZejjZdddejjddddd„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|_||_|pB|j	|_
tj|j
ƒ|_t
jd|jƒ|_||_|	|_tjjp—d|_|dkrÁtjdtdƒƒ‚||f}
yBtj|
d|
dtjtjƒd}|d}|d}
Wntk
r,tj}YnXytj|
|d|ƒ|_Wn7tk
r…tj t!dƒd	|d
|iƒ‚YnX|jj"ƒdd…\|_#|_$tj%t&dƒd
|jd	|j#d
|j$iƒ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éÚreasonzThe backlog must be more than 0rÚbacklogz#Could not bind to %(host)s:%(port)sÚhostÚportéz'%(name)s listening on %(host)s:%(port)sÚnameéÿÿÿÿ)'Ú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ÚsocketÚgetaddrinfoÚ	AF_UNSPECÚSOCK_STREAMÚ	ExceptionÚAF_INETÚlistenÚ_socketÚEnvironmentErrorÚLOGÚerrorrÚgetsocknamerrÚinfor	)
ÚselfrrrrrÚprotocolrZuse_sslZmax_url_lenZ	bind_addrr0Úfamily©r4ú,/usr/lib/python3/dist-packages/dmapi/wsgi.pyÚ__init__(sB							



%zServer.__init__c!Cs•|jjƒ}|jtjtjdƒ|jtjtjdƒttdƒro|jtjtj	t
jjƒ|j
ry4t
jj}t
jj}t
jj}|rÎtjj|ƒrÎttdƒ|ƒ‚|rýtjj|ƒrýttdƒ|ƒ‚|r,tjj|ƒr,ttdƒ|ƒ‚|j
rU|sC|rUttdƒƒ‚ddd	|d
|dtji}t
jjr™||d<tj|d<tj||}WnWtk
rtjƒ6tjt d
ƒd|j!d|j"d|j#iƒWdQRXYnXdtjj$d|d|j%d|j&d|j'd|j(dt
jj)dddt
jj*d|j+i
}|j,r|j,|d<t-j.||_/dS)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 fileÚserver_sideTÚcertfileÚkeyfileÚ	cert_reqsÚca_certsz>Failed to start %(name)s on %(host)s:%(port)s with SSL supportrrrNÚfuncÚsockÚsiter2Zcustom_poolrZ
log_formatÚdebugFÚ	keepaliveÚsocket_timeoutZurl_length_limit)0r+ÚdupÚ
setsockoptr$Ú
SOL_SOCKETÚSO_REUSEADDRÚSO_KEEPALIVEÚhasattrÚIPPROTO_TCPr7rrZtcp_keepidler!Zssl_ca_fileZ
ssl_cert_fileZssl_key_fileÚosÚpathÚexistsÚRuntimeErrorrÚsslÚ	CERT_NONEÚ
CERT_REQUIREDrZwrap_sslr(rZsave_and_reraise_exceptionr-r.rrrrÚserverrrrr Zwsgi_log_formatZ
keep_aliver#r"r
Úspawnr)r1Z
dup_socketZca_fileÚ	cert_fileÚkey_fileZ
ssl_kwargsZwsgi_kwargsr4r4r5Ústartasj



	

	


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

        :returns: None

        N)rÚresizer)r1r4r4r5Úreset´szServer.resetcCsCtjtdƒƒ|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-r0r	rrrVÚkill)r1r4r4r5Ústop¼s	zServer.stopcCs\y-|jdk	r,|jjƒ|jjƒWn(tjk
rWtjtdƒƒ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-r0r	)r1r4r4r5rZÌs
zServer.wait)Ú__name__Ú
__module__Ú__qualname__Ú__doc__rrrrZHttpProtocolr6rUrWrYrZr4r4r4r5r#s	7Srcs"eZdZ‡fdd†Z‡S)ÚRequestcsQtjjr1|jtjjƒ}|r1||d<tt|ƒj|||ŽdS)Nzwsgi.url_scheme)rrZsecure_proxy_ssl_headerÚgetÚsuperr`r6)r1ÚenvironÚargsÚkwargsÚscheme)Ú	__class__r4r5r6Ýs

zRequest.__init__)r\r]r^r6r4r4)rgr5r`Üsr`c@s4eZdZdZedd„ƒZdd„ZdS)ÚApplicationzEBase WSGI application wrapper. Subclasses need to implement __call__.cKs
||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.

        r4)ÚclsÚ
global_configÚlocal_configr4r4r5Ú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)r1rcZstart_responser4r4r5Ú__call__s"zApplication.__call__N)r\r]r^r_Úclassmethodrlrnr4r4r4r5rhåsrhc@smeZdZdZedd„ƒZdd„Zdd„Zdd	„Ze	j
jd
eƒ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
ˆ|ˆS)Nr4)r)rirkr4r5Ú_factoryGsz$Middleware.factory.<locals>._factoryr4)rirjrkrqr4)rirkr5rl0szMiddleware.factorycCs
||_dS)N)Úapplication)r1rrr4r4r5r6KszMiddleware.__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.

        Nr4)r1Úreqr4r4r5Úprocess_requestNszMiddleware.process_requestcCs|S)z'Do whatever you'd like to the response.r4)r1Úresponser4r4r5Úprocess_responseXszMiddleware.process_responseÚRequestClasscCs8|j|ƒ}|r|S|j|jƒ}|j|ƒS)N)rtÚget_responserrrv)r1rsrur4r4r5rn\s
zMiddleware.__call__N)r\r]r^r_rorlr6rtrvÚwebobÚdecÚwsgifyr`rnr4r4r4r5rp&s
rpc@sIeZdZdZejjdeƒ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.

    rwcCsÉtdddƒx3t|jjƒƒD]\}}t|d|ƒq(Wtƒ|j|jƒ}tdddƒx3t|jjƒƒD]\}}t|d|ƒq‰Wtƒ|j|jƒ|_|S)NÚ*é(z REQUEST ENVIRONú=z RESPONSE HEADERS)	ÚprintÚlistrcÚitemsrxrrÚheadersÚprint_generatorÚapp_iter)r1rsÚkeyÚvalueÚrespr4r4r5rnms""zDebug.__call__ccsYtdddƒx9|D]1}tjjtj|ƒƒtjjƒ|VqWtƒdS)z6Iterator that prints the contents of a wrapper string.r}r~z BODYN)r€ÚsysÚstdoutÚwriteÚsixÚ	text_typeÚflush)r…Úpartr4r4r5r„~s

	zDebug.print_generatorN)r\r]r^r_ryrzr{r`rnÚstaticmethodr„r4r4r4r5r|es!r|c@sjeZdZdZdd„Zejjdeƒdd„ƒZ	e
ejjdeƒ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)r1Zmapperr4r4r5r6Œs	zRouter.__init__rwcCs|jS)zkRoute the incoming request to a controller based on self.map.

        If no match, return a 404.

        )r•)r1rsr4r4r5rn¨szRouter.__call__cCs2|jdd}|s$tjjƒ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)rcryÚexcZHTTPNotFound)rsÚmatchrr4r4r5r”±s



zRouter._dispatchN)r\r]r^r_r6ryrzr{r`rnrr”r4r4r4r5r‘‰s
!	r‘c@s1eZdZdZddd„Zdd„ZdS)ÚLoaderz9Used to load WSGI applications from paste configurations.NcCs|d|_|ptjj}tjj|ƒsBtj|ƒ|_ntjj|ƒr]||_|jsxt	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

        NrK)Úconfig_pathrrZdmapi_api_paste_configrJrKÚisabsZ	find_filerLrZConfigNotFound)r1r™r4r4r5r6Ås			zLoader.__init__cCs‡y=tjdd|d|jiƒtjd|jd|ƒSWnCtk
r‚tjtdƒ|ƒtjd|d|jƒ‚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)srrKz	config:%szCouldn't lookup app: %sN)	r-r@r™rZloadappÚLookupErrorrrZPasteAppNotFound)r1rr4r4r5Úload_app×s	
zLoader.load_app)r\r]r^r_r6rœr4r4r4r5r˜Âsr˜).r_Úos.pathrJr$rNr‰rZ
eventlet.wsgir[Zoslo_logrrZoslo_servicerZ
oslo_utilsrZpasterZroutes.middlewarer“rŒZ	webob.decryZ	webob.excZ
dmapi.confÚdmapirZ
dmapi.i18nrrr	r
Úconfrrr\r-ZServiceBaserr`Úobjectrhrpr|r‘r˜r4r4r4r5Ú<module>s8¹	A?$9