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    
Size: Mime:
ó
¨‹EYc@s‹dZddlmZmZddlmZddlmZdgZde	fd„ƒYZ
de	fd„ƒYZd	e	fd
„ƒYZdS(sÜ
Decorators to wrap functions to make them WSGI applications.

The main decorator :class:`wsgify` turns a function into a WSGI
application (while also allowing normal calling of the method with an
instantiated request).
iÿÿÿÿ(tbytes_t	text_type(tRequest(t
HTTPExceptiontwsgifycBs¡eZdZeZddd
ddd„Zd„Zdd„Zd„Z	d„Z
dd„Zd„Zd„Z
dd	„Zed
„ƒZeddd„ƒZRS(sÃTurns a request-taking, response-returning function into a WSGI
    app

    You can use this like::

        @wsgify
        def myfunc(req):
            return webob.Response('hey there')

    With that ``myfunc`` will be a WSGI application, callable like
    ``app_iter = myfunc(environ, start_response)``.  You can also call
    it like normal, e.g., ``resp = myfunc(req)``.  (You can also wrap
    methods, like ``def myfunc(self, req)``.)

    If you raise exceptions from :mod:`webob.exc` they will be turned
    into WSGI responses.

    There are also several parameters you can use to customize the
    decorator.  Most notably, you can use a :class:`webob.Request`
    subclass, like::

        class MyRequest(webob.Request):
            @property
            def is_local(self):
                return self.remote_addr == '127.0.0.1'
        @wsgify(RequestClass=MyRequest)
        def myfunc(req):
            if req.is_local:
                return Response('hi!')
            else:
                raise webob.exc.HTTPForbidden

    Another customization you can add is to add `args` (positional
    arguments) or `kwargs` (of course, keyword arguments).  While
    generally not that useful, you can use this to create multiple
    WSGI apps from one function, like::

        import simplejson
        def serve_json(req, json_obj):
            return Response(json.dumps(json_obj),
                            content_type='application/json')

        serve_ob1 = wsgify(serve_json, args=(ob1,))
        serve_ob2 = wsgify(serve_json, args=(ob2,))

    You can return several things from a function:

    * A :class:`webob.Response` object (or subclass)
    * *Any* WSGI application
    * None, and then ``req.response`` will be used (a pre-instantiated
      Response object)
    * A string, which will be written to ``req.response`` and then that
      response will be used.
    * Raise an exception from :mod:`webob.exc`

    Also see :func:`wsgify.middleware` for a way to make middleware.

    You can also subclass this decorator; the most useful things to do
    in a subclass would be to change `RequestClass` or override
    `call_func` (e.g., to add ``req.urlvars`` as keyword arguments to
    the function).
    cCsj||_|dk	r0||jk	r0||_nt|ƒ|_|dkrTi}n||_||_dS(N(tfunctNonetRequestClassttupletargstkwargstmiddleware_wraps(tselfRRR	R
R((s>/home/tvault/.virtenv/lib/python2.7/site-packages/webob/dec.pyt__init__Us			cCs d|jjt|ƒ|jfS(Ns<%s at %s wrapping %r>(t	__class__t__name__tidR(R((s>/home/tvault/.virtenv/lib/python2.7/site-packages/webob/dec.pyt__repr__ascCs6t|jdƒr.|j|jj||ƒƒS|SdS(Nt__get__(thasattrRtcloneR(Rtobjttype((s>/home/tvault/.virtenv/lib/python2.7/site-packages/webob/dec.pyResc
Osã|j}|dkrM|s!|r:td|jjƒ‚n|}|j|ƒSt|tƒr°t|ƒdkst|rŠtd|jƒ‚n|}|d}|j	|ƒ}|j
ƒ|_yA|j}|j
rà|j
f|}n|j|||jŽ}Wntk
r}|}nX|dkr-|j}nt|tƒrQt||jƒ}nt|tƒr|}	|j}|j|	ƒn||jk	r£|jj|ƒ}n|||ƒS|j
rÌ|j
f|}n|j|||ŽSdS(s1Call this as a WSGI application or with a requests<Unbound %s can only be called with the function it will wrapis1Calling %r as a WSGI app with the wrong signatureiN(RRt	TypeErrorRRRt
isinstancetdicttlenRt
ResponseClasstresponseR	Rt	call_funcR
RRRtcharsettbytestwritet
merge_cookies(
RtreqR	tkwRtenvirontstart_responsetresptexctbody((s>/home/tvault/.virtenv/lib/python2.7/site-packages/webob/dec.pyt__call__lsL	

		
	
	cKs/|jddƒ|jj||}||ƒS(s5Run a GET request on this application, returning a Response.

        This creates a request object using the given URL, and any
        other keyword arguments are set on the request object (e.g.,
        ``last_modified=datetime.now()``).

        ::

            resp = myapp.get('/article?id=10')
        tmethodtGET(t
setdefaultRtblank(RturlR#R"((s>/home/tvault/.virtenv/lib/python2.7/site-packages/webob/dec.pytget—scKs5|jddƒ|jj|d||}||ƒS(sŽRun a POST request on this application, returning a Response.

        The second argument (`POST`) can be the request body (a
        string), or a dictionary or list of two-tuples, that give the
        POST body.

        ::

            resp = myapp.post('/article/new',
                              dict(title='My Day',
                                   content='I ate a sandwich'))
        R*tPOST(R,RR-(RR.R0R#R"((s>/home/tvault/.virtenv/lib/python2.7/site-packages/webob/dec.pytpost¦s
cKs|jj||}||ƒS(sÔRun a request on this application, returning a Response.

        This can be used for DELETE, PUT, etc requests.  E.g.::

            resp = myapp.request('/article/1', method='PUT', body='New article')
        (RR-(RR.R#R"((s>/home/tvault/.virtenv/lib/python2.7/site-packages/webob/dec.pytrequest·scOs|j|||ŽS(sdCall the wrapped function; override this in a subclass to
        change how the function is called.(R(RR"R	R
((s>/home/tvault/.virtenv/lib/python2.7/site-packages/webob/dec.pyRÁscKsi}|dk	r||d<n|j|jjk	rD|j|d<n|jr]|j|d<n|jrv|j|d<n|j|ƒ|j|S(sVCreates a copy/clone of this object, but with some
        parameters rebound
        RRR	R
N(RRRR	R
tupdate(RRR#R
((s>/home/tvault/.virtenv/lib/python2.7/site-packages/webob/dec.pyRÆs
		
cCs|jS(N(R(R((s>/home/tvault/.virtenv/lib/python2.7/site-packages/webob/dec.pytundecorated×scKsN|dkrt|||ƒS|dkr8t|||ƒS||d|d|ƒS(sCreates middleware

        Use this like::

            @wsgify.middleware
            def restrict_ip(req, app, ips):
                if req.remote_addr not in ips:
                    raise webob.exc.HTTPForbidden('Bad IP: %s' % req.remote_addr)
                return app

            @wsgify
            def app(req):
                return 'hi'

            wrapped = restrict_ip(app, ips=['127.0.0.1'])

        Or as a decorator::

            @restrict_ip(ips=['127.0.0.1'])
            @wsgify
            def wrapped_app(req):
                return 'hi'

        Or if you want to write output-rewriting middleware::

            @wsgify.middleware
            def all_caps(req, app):
                resp = req.get_response(app)
                resp.body = resp.body.upper()
                return resp

            wrapped = all_caps(app)

        Note that you must call ``req.get_response(app)`` to get a WebOb
        response object.  If you are not modifying the output, you can just
        return the app.

        As you can see, this method doesn't actually create an application, but
        creates "middleware" that can be bound to an application, along with
        "configuration" (that is, any other keyword arguments you pass when
        binding the application).

        RR
N(Rt_UnboundMiddlewaret_MiddlewareFactory(tclstmiddle_functappR#((s>/home/tvault/.virtenv/lib/python2.7/site-packages/webob/dec.pyt
middlewareÛs
-N((Rt
__module__t__doc__RRRR
RRR)R/R1R2RRtpropertyR4tclassmethodR:(((s>/home/tvault/.virtenv/lib/python2.7/site-packages/webob/dec.pyRs>		+		
	R5cBs,eZdZd„Zd„Zdd„ZRS(s¹A `wsgify.middleware` invocation that has not yet wrapped a
    middleware function; the intermediate object when you do
    something like ``@wsgify.middleware(RequestClass=Foo)``
    cCs||_||_||_dS(N(t
wrapper_classR9R#(RR?R9R#((s>/home/tvault/.virtenv/lib/python2.7/site-packages/webob/dec.pyR
s		cCs d|jjt|ƒ|jfS(Ns<%s at %s wrapping %r>(RRRR9(R((s>/home/tvault/.virtenv/lib/python2.7/site-packages/webob/dec.pyRscCs4|dkr|j}n|jj|d||jS(NR9(RR9R?R:R#(RRR9((s>/home/tvault/.virtenv/lib/python2.7/site-packages/webob/dec.pyR)sN(RR;R<R
RRR)(((s>/home/tvault/.virtenv/lib/python2.7/site-packages/webob/dec.pyR5s		R6cBs,eZdZd„Zd„Zdd„ZRS(sRA middleware that has not yet been bound to an application or
    configured.
    cCs||_||_||_dS(N(R?R:R#(RR?R:R#((s>/home/tvault/.virtenv/lib/python2.7/site-packages/webob/dec.pyR
's		cCs d|jjt|ƒ|jfS(Ns<%s at %s wrapping %r>(RRRR:(R((s>/home/tvault/.virtenv/lib/python2.7/site-packages/webob/dec.pyR,scKs5|jjƒ}|j|ƒ|jj|j||S(N(R#tcopyR3R?R:(RR9tconfigR#((s>/home/tvault/.virtenv/lib/python2.7/site-packages/webob/dec.pyR)0s
N(RR;R<R
RRR)(((s>/home/tvault/.virtenv/lib/python2.7/site-packages/webob/dec.pyR6"s		N(
R<twebob.compatRRt
webob.requestRt	webob.excRt__all__tobjectRR5R6(((s>/home/tvault/.virtenv/lib/python2.7/site-packages/webob/dec.pyt<module>s	û