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-el9 / usr / lib / python3.9 / site-packages / dmapi / __pycache__ / wsgi.cpython-39.pyc
Size: Mime:
a

[r`e³@ã@sJdZddlZddlZddlZddlZddlZddlZddlZddl	m
Zddlm
Z
ddlmZddlmZddlZddlZddlZddlZddlZddlmZddlmZmZmZdd	lmZej j!Z!e "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

	CsXtjjtj_||_||_d|_||_|p,|j	|_
t |j
¡|_t
 d|j¡|_||_|	|_tjjpfd|_|dkr‚tjtdƒd‚||f}
z4t |
d|
dtjtj¡d}|d}|d}
WntyÖtj}Yn0ztj|
||d|_Wn,tyt  t!d	ƒ||d
œ¡‚Yn0|j "¡dd…\|_#|_$t %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.9/site-packages/dmapi/wsgi.pyÚ__init__(sNÿ
ýý
ÿ
ÿzServer.__init__cCsà|j ¡}| tjtjd¡| tjtjd¡ttdƒrN| tjtj	t
jj¡|j
rˆzÔt
jj}t
jj}t
jj}|rtj |¡sttdƒ|ƒ‚|r°tj |¡s°ttdƒ|ƒ‚|rÐtj |¡sÐttdƒ|ƒ‚|j
rê|rÞ|sêttdƒƒ‚d||tjdœ}t
jjr||d	<tj|d
<tj|fi|¤Ž}Wn\ty†t ¡.t t dƒ|j!|j"|j#dœ¡Wd
ƒn1sx0YYn0tjj$||j%|j&|j'|j(t
jj)dt
jj*|j+dœ
}|j,rÊ|j,|d<t-j.fi|¤Ž|_/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_certsr2z>Failed to start %(name)s on %(host)s:%(port)s with SSL supportrNF)
ÚfuncZsockZsiter-Zcustom_poolrZ
log_formatÚdebugZ	keepaliveZsocket_timeoutZurl_length_limit)0r'ÚdupZ
setsockoptr%Z
SOL_SOCKETZSO_REUSEADDRZSO_KEEPALIVEÚhasattrZIPPROTO_TCPr1rrZ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/Ústartas‚

ÿÿ
þ
ÿ
ÿ
ÿÿü


ÿ


ÿþ*ö

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

        :returns: None

        N)rÚresizer©r,r.r.r/Úreset´szServer.resetcCs2t tdƒ¡|jdur.|j d¡|j ¡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=Úkillr>r.r.r/Ústop¼s	
zServer.stopcCsJz"|jdur |j ¡|j ¡Wn"tjyDt tdƒ¡Yn0dS)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/rBÌs

zServer.wait)Ú__name__Ú
__module__Ú__qualname__Ú__doc__rrrrZHttpProtocolr0r<r?rArBr.r.r.r/r#sþ
9SrcseZdZ‡fdd„Z‡ZS)ÚRequestcsDtjjr"| tjj¡}|r"||d<tt|ƒj|g|¢Ri|¤ŽdS)Nzwsgi.url_scheme)rrZsecure_proxy_ssl_headerÚgetÚsuperrHr0)r,ÚenvironÚargsÚkwargsÚscheme©Ú	__class__r.r/r0Ýs
zRequest.__init__)rDrErFr0Ú
__classcell__r.r.rOr/rHÜsrHc@s$eZdZdZedd„ƒZdd„ZdS)ÚApplicationzEBase WSGI application wrapper. Subclasses need to implement __call__.cKs|fi|¤Ž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,rKZstart_responser.r.r/Ú__call__s"zApplication.__call__N)rDrErFrGÚclassmethodrVrXr.r.r.r/rRås
rRc@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ˆ|fiˆ¤ŽS©Nr.)r©rSrUr.r/Ú_factoryGsz$Middleware.factory.<locals>._factoryr.)rSrTrUr]r.r\r/rV0szMiddleware.factorycCs
||_dSr[)Úapplication)r,r^r.r.r/r0KszMiddleware.__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©ZRequestClasscCs(| |¡}|r|S| |j¡}| |¡Sr[)raÚget_responser^rc)r,r`rbr.r.r/rX\s

zMiddleware.__call__N)rDrErFrGrYrVr0rarcÚwebobÚdecÚwsgifyrHrXr.r.r.r/rZ&s	

rZc@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.

    rdcCs‚tdƒt|j ¡ƒD]\}}t|d|ƒqtƒ| |j¡}tdƒt|j ¡ƒD]\}}t|d|ƒqTtƒ| |j¡|_|S)Nz8**************************************** REQUEST ENVIRONú=z9**************************************** RESPONSE HEADERS)	ÚprintÚlistrKÚitemsrer^ZheadersÚprint_generatorÚapp_iter)r,r`ÚkeyÚvalueZrespr.r.r/rXmszDebug.__call__ccs>tdƒ|D]&}tj t |¡¡tj ¡|VqtƒdS)z6Iterator that prints the contents of a wrapper string.z-**************************************** BODYN)rkÚsysÚstdoutÚwriteÚsixZ	text_typeÚflush)roÚpartr.r.r/rn~s
zDebug.print_generatorN)rDrErFrGrfrgrhrHrXÚstaticmethodrnr.r.r.r/ries

ric@sHeZdZdZdd„Zejjeddd„ƒZ	e
ejjeddd„ƒƒZd	S)
ÚRouterz9WSGI middleware that maps incoming requests to WSGI apps.cCs||_tj |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/r0Œs
ÿzRouter.__init__rdcCs|jS)zkRoute the incoming request to a controller based on self.map.

        If no match, return a 404.

        )r}r_r.r.r/rX¨szRouter.__call__cCs(|jdd}|stj ¡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)rKrfÚexcZHTTPNotFound)r`Úmatchrr.r.r/r|±s


zRouter._dispatchN)rDrErFrGr0rfrgrhrHrXrxr|r.r.r.r/ry‰s
ryc@s"eZdZdZddd„Zdd„ZdS)ÚLoaderz9Used to load WSGI applications from paste configurations.NcCsTd|_|ptjj}tj |¡s,t |¡|_ntj |¡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)r8)Úconfig_pathrrZapi_paste_configr7r8ÚisabsZ	find_filer9rZConfigNotFound)r,rr.r.r/r0ÅszLoader.__init__cCsbz*t d||jdœ¡tjd|j|dWSty\t tdƒ|¡tj||jd‚Yn0dS)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)rr8z	config:%s)rzCouldn't lookup app: %sN)	r)r4rrZloadappÚLookupErrorrrZPasteAppNotFound)r,rr.r.r/Úload_app×s
ÿzLoader.load_app)N)rDrErFrGr0r„r.r.r.r/r€Âs
r€).rGZos.pathr7r%r;rrrZ
eventlet.wsgirCZoslo_logrrZoslo_servicerZ
oslo_utilsrZpasterZroutes.middlewarer{ruZ	webob.decrfZ	webob.excZ
dmapi.confZdmapirZ
dmapi.i18nrrr	r
Zconfrr rDr)ZServiceBaserrHÚobjectrRrZriryr€r.r.r.r/Ú<module>s:
:	A?$9