MCPcopy Create free account
hub / github.com/Pylons/webtest / wrapper

Method wrapper

webtest/http.py:61–83  ·  view source on GitHub ↗

Wrap the wsgi application to override some path: ``/__application__``: allow to ping the server. ``/__file__?__file__={path}``: serve the file found at ``path``

(self, environ, start_response)

Source from the content-addressed store, hash-verified

59 self.application_url = f'http://{self.adj.host}:{self.adj.port}/'
60
61 def wrapper(self, environ, start_response):
62 """Wrap the wsgi application to override some path:
63
64 ``/__application__``: allow to ping the server.
65
66 ``/__file__?__file__={path}``: serve the file found at ``path``
67 """
68 if '__file__' in environ['PATH_INFO']:
69 req = webob.Request(environ)
70 resp = webob.Response()
71 resp.content_type = 'text/html; charset=UTF-8'
72 filename = req.params.get('__file__')
73 if os.path.isfile(filename):
74 body = open(filename, 'rb').read()
75 body = body.replace(b'http://localhost/',
76 bytes('http://%s/' % req.host, 'UTF-8'))
77 resp.body = body
78 else:
79 resp.status = '404 Not Found'
80 return resp(environ, start_response)
81 elif '__application__' in environ['PATH_INFO']:
82 return webob.Response('server started')(environ, start_response)
83 return self.test_app(environ, start_response)
84
85 def run(self):
86 """Run the server"""

Callers

nothing calls this directly

Calls 2

readMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected