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    
dmapi / usr / lib / python2.7 / dist-packages / dmapi / wsgi.pyc
Size: Mime:
ó
ÿ^¢`c@sÑdZddlZddlZddlZddlZddlZddlZddlZddl	m
Zddlm
Z
ddlmZddlmZddlZddlZddlZddlZddlZddlmZddlmZmZmZdd	lmZej j!Z!ej"e#ƒZ$d
e
j%fd„ƒYZ&dej'fd
„ƒYZ'de(fd„ƒYZ)de)fd„ƒYZ*de*fd„ƒYZ+de(fd„ƒYZ,de(fd„ƒYZ-dS(s.Utility methods for working with WSGI servers.iÿÿÿÿN(tlog(tservice(texcutils(tdeploy(t	exception(t_t_LEt_LI(tutilstServercBsbeZdZejjZddd	ejjde	d	d„Z
d„Zd„Zd„Z
d„ZRS(
sAServer class to manage a WSGI server, serving a WSGI application.s0.0.0.0ii€c

Csãtjjtj_||_||_d|_||_	|pB|j
|_tj|jƒ|_
tjd|jƒ|_||_|	|_tjjp—d|_|dkrÄtjdtdƒƒ‚n||f}
yBtj|
d|
dtjtjƒd}|d}|d}
Wntk
r.tj}nXytj|
|d|ƒ|_Wn8tk
rˆt j!t"dƒi|d	6|d
6ƒ‚nX|jj#ƒdd!\|_$|_%t j&t'dƒi|jd
6|j$d	6|j%d
6ƒdS(sInitialize, 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
        sdmapi.%s.wsgi.serveritreasonsThe backlog must be more than 0iiÿÿÿÿtbacklogs#Could not bind to %(host)s:%(port)sthosttportis'%(name)s listening on %(host)s:%(port)stnameN((tCONFtwsgitmax_header_lineteventlettMAX_HEADER_LINERtapptNonet_servert	_protocoltdefault_pool_sizet	pool_sizet	GreenPoolt_pooltloggingt	getLoggert_loggert_use_sslt_max_url_lentclient_socket_timeoutRtInvalidInputRtsockettgetaddrinfot	AF_UNSPECtSOCK_STREAMt	ExceptiontAF_INETtlistent_sockettEnvironmentErrortLOGterrorRtgetsocknameRR
tinfoR(
tselfRRRR
RtprotocolRtuse_ssltmax_url_lent	bind_addrR/tfamily((s./usr/lib/python2.7/dist-packages/dmapi/wsgi.pyt__init__(sB							




"c	Cs¼|jjƒ}|jtjtjdƒ|jtjtjdƒttdƒrr|jtjtj	t
jjƒn|j
r yGt
jj}t
jj}t
jj}|rÔtjj|ƒrÔttdƒ|ƒ‚n|rtjj|ƒrttdƒ|ƒ‚n|r8tjj|ƒr8ttdƒ|ƒ‚n|j
rd|sO|rdttdƒƒ‚nitd6|d6|d	6tjd
6}t
jjr¯||d<tj|d
<ntj||}Wq tk
rtjƒ9tj t!dƒi|j"d
6|j#d6|j$d6ƒWdQXq Xni
tjj%d6|d6|j&d6|j'd6|j(d6|j)d6t
jj*d6t+d6t
jj,d6|j-d6}|j.r¦|j.|d<nt/j0||_1dS(sBStart serving a WSGI application.

        :returns: None
        itTCP_KEEPIDLEsUnable to find cert_file : %ssUnable to find ca_file : %ssUnable to find key_file : %sswWhen running server in SSL mode, you must specify both a cert_file and key_file option value in your configuration filetserver_sidetcertfiletkeyfilet	cert_reqstca_certss>Failed to start %(name)s on %(host)s:%(port)s with SSL supportRRR
NtfunctsocktsiteR1tcustom_poolRt
log_formattdebugt	keepalivetsocket_timeoutturl_length_limit(2R*tdupt
setsockoptR#t
SOL_SOCKETtSO_REUSEADDRtSO_KEEPALIVEthasattrtIPPROTO_TCPR7RRttcp_keepidleRtssl_ca_filet
ssl_cert_filetssl_key_filetostpathtexiststRuntimeErrorRtTruetsslt	CERT_NONEt
CERT_REQUIREDRtwrap_sslR'Rtsave_and_reraise_exceptionR,R-RRRR
tserverRRRRtwsgi_log_formattFalset
keep_aliveR!R RtspawnR(R0t
dup_sockettca_filet	cert_filetkey_filet
ssl_kwargstwsgi_kwargs((s./usr/lib/python2.7/dist-packages/dmapi/wsgi.pytstartasn


	

	










	cCs|jj|jƒdS(sIReset server greenpool size to default.

        :returns: None

        N(RtresizeR(R0((s./usr/lib/python2.7/dist-packages/dmapi/wsgi.pytreset´scCsFtjtdƒƒ|jdk	rB|jjdƒ|jjƒndS(sµ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

        sStopping WSGI server.iN(R,R/RRRRRgtkill(R0((s./usr/lib/python2.7/dist-packages/dmapi/wsgi.pytstop¼s	cCs^y0|jdk	r/|jjƒ|jjƒnWn'tjk
rYtjt	dƒƒnXdS(s‡Block, until the server has stopped.

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

        :returns: None

        sWSGI server has stopped.N(
RRRtwaitalltwaittgreenlettGreenletExitR,R/R(R0((s./usr/lib/python2.7/dist-packages/dmapi/wsgi.pyRlÌs
N(t__name__t
__module__t__doc__RRRRRtHttpProtocolR]R6RfRhRjRl(((s./usr/lib/python2.7/dist-packages/dmapi/wsgi.pyR	#s	7	S		tRequestcBseZd„ZRS(cOsWtjjr7|jtjjƒ}|r7||d<q7ntt|ƒj|||ŽdS(Nswsgi.url_scheme(RRtsecure_proxy_ssl_headertgettsuperRsR6(R0tenvirontargstkwargstscheme((s./usr/lib/python2.7/dist-packages/dmapi/wsgi.pyR6Ýs
(RoRpR6(((s./usr/lib/python2.7/dist-packages/dmapi/wsgi.pyRsÜstApplicationcBs&eZdZed„ƒZd„ZRS(sEBase WSGI application wrapper. Subclasses need to implement __call__.cKs
||S(sÄ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.

        ((tclst
global_configtlocal_config((s./usr/lib/python2.7/dist-packages/dmapi/wsgi.pytfactoryèscCsttdƒƒ‚dS(s\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.

        sYou must implement __call__N(tNotImplementedErrorR(R0Rwtstart_response((s./usr/lib/python2.7/dist-packages/dmapi/wsgi.pyt__call__s"(RoRpRqtclassmethodRR‚(((s./usr/lib/python2.7/dist-packages/dmapi/wsgi.pyR{åst
MiddlewarecBsVeZdZed„ƒZd„Zd„Zd„Zej	j
deƒd„ƒZRS(sò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‡‡fd†}|S(sõ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(N((R(R|R~(s./usr/lib/python2.7/dist-packages/dmapi/wsgi.pyt_factoryGs((R|R}R~R…((R|R~s./usr/lib/python2.7/dist-packages/dmapi/wsgi.pyR0scCs
||_dS(N(tapplication(R0R†((s./usr/lib/python2.7/dist-packages/dmapi/wsgi.pyR6KscCsdS(sá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.

        N(R(R0treq((s./usr/lib/python2.7/dist-packages/dmapi/wsgi.pytprocess_requestNscCs|S(s'Do whatever you'd like to the response.((R0tresponse((s./usr/lib/python2.7/dist-packages/dmapi/wsgi.pytprocess_responseXstRequestClasscCs8|j|ƒ}|r|S|j|jƒ}|j|ƒS(N(Rˆtget_responseR†RŠ(R0R‡R‰((s./usr/lib/python2.7/dist-packages/dmapi/wsgi.pyR‚\s
(
RoRpRqRƒRR6RˆRŠtwebobtdectwsgifyRsR‚(((s./usr/lib/python2.7/dist-packages/dmapi/wsgi.pyR„&s		
	tDebugcBs;eZdZejjdeƒd„ƒZed„ƒZ	RS(s 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·dddGHx1t|jjƒƒD]\}}|d|fGHq#WdGH|j|jƒ}dddGHx1t|jjƒƒD]\}}|d|fGHq{WdGH|j|jƒ|_|S(Nt*i(s REQUEST ENVIRONt=s RESPONSE HEADERS(((tlistRwtitemsRŒR†theaderstprint_generatortapp_iter(R0R‡tkeytvaluetresp((s./usr/lib/python2.7/dist-packages/dmapi/wsgi.pyR‚ms
"
"ccsRdddGHx9|D]1}tjjtj|ƒƒtjjƒ|VqWdGHdS(s6Iterator that prints the contents of a wrapper string.R‘i(s BODYN((tsyststdouttwritetsixt	text_typetflush(R—tpart((s./usr/lib/python2.7/dist-packages/dmapi/wsgi.pyR–~s


	(
RoRpRqRRŽRRsR‚tstaticmethodR–(((s./usr/lib/python2.7/dist-packages/dmapi/wsgi.pyRestRoutercBsYeZdZd„Zejjdeƒd„ƒZe	ejjdeƒd„ƒƒZ
RS(s9WSGI middleware that maps incoming requests to WSGI apps.cCs+||_tjj|j|jƒ|_dS(s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(tmaptroutest
middlewaretRoutesMiddlewaret	_dispatcht_router(R0tmapper((s./usr/lib/python2.7/dist-packages/dmapi/wsgi.pyR6Œs	R‹cCs|jS(skRoute the incoming request to a controller based on self.map.

        If no match, return a 404.

        (R©(R0R‡((s./usr/lib/python2.7/dist-packages/dmapi/wsgi.pyR‚¨scCs2|jdd}|s$tjjƒS|d}|S(sDispatch 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.

        swsgiorg.routing_argsit
controller(RwRtexctHTTPNotFound(R‡tmatchR((s./usr/lib/python2.7/dist-packages/dmapi/wsgi.pyR¨±s



(RoRpRqR6RRŽRRsR‚R¢R¨(((s./usr/lib/python2.7/dist-packages/dmapi/wsgi.pyR£‰s
		tLoadercBs#eZdZdd„Zd„ZRS(s9Used to load WSGI applications from paste configurations.cCs‚d|_|ptjj}tjj|ƒsBtj|ƒ|_ntjj	|ƒr`||_n|js~t
jd|ƒ‚ndS(sŸInitialize the loader, and attempt to find the config.

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

        RRN(Rtconfig_pathRRtdmapi_api_paste_configRQRRtisabst	find_fileRSRtConfigNotFound(R0R°((s./usr/lib/python2.7/dist-packages/dmapi/wsgi.pyR6Ås		cCsˆy?tjdi|d6|jd6ƒtjd|jd|ƒSWnBtk
rƒtjtdƒ|ƒtjd|d|jƒ‚nXdS(sð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`

        s"Loading app %(name)s from %(path)sRRRs	config:%ssCouldn't lookup app: %sN(	R,RBR°RtloadapptLookupErrorRRtPasteAppNotFound(R0R((s./usr/lib/python2.7/dist-packages/dmapi/wsgi.pytload_app×s	
N(RoRpRqRR6R¸(((s./usr/lib/python2.7/dist-packages/dmapi/wsgi.pyR¯Âs(.Rqtos.pathRQR#RVR›Rt
eventlet.wsgiRmtoslo_logRRtoslo_serviceRt
oslo_utilsRtpasteRtroutes.middlewareR¥Ržt	webob.decRt	webob.exct
dmapi.conftdmapiRt
dmapi.i18nRRRRtconfRRRoR,tServiceBaseR	RstobjectR{R„RR£R¯(((s./usr/lib/python2.7/dist-packages/dmapi/wsgi.pyt<module>s8¹	A?$9