def build_response(request, data, code, encoding): response = Response() response.encoding = encoding # Fill in some useful fields. raw = StringIO() raw.write(data) raw.seek(0) response.raw = raw response.url = request.url response.request = request response.status_code = code # Run the response hook. response = dispatch_hook('response', request.hooks, response) return response
def build_response(request, data, code, encoding): '''Builds a response object from the data returned by ftplib, using the specified encoding.''' response = Response() response.encoding = encoding # Fill in some useful fields. raw = StringIO() raw.write(data) raw.seek(0) response.raw = raw response.url = request.url response.request = request response.status_code = code # Run the response hook. response = dispatch_hook('response', request.hooks, response) return response
def requests_adapters_process_request(request, **kwargs): with flask_current_app.app_context(): environ = {'SERVER_NAME':'localhost'} environ['wsgi.url_scheme'] = 'http' environ['SERVER_PORT'] = '80' environ['PATH_INFO'] = request.path_url environ['REQUEST_METHOD'] = request.method environ['CONTENT_LENGTH'] = request.headers.get('Content-Length') environ['CONTENT_TYPE'] = request.headers.get('Content-Type') body = StringIO() body.write(request.body) body.seek(0) environ['wsgi.input'] = body context_request = flask_current_app.request_context(environ) context_request.push() flask_current_app.dispatch_request()
def _encode_identity(iter): data = StringIO() for item in iter: data.write(item) data.write('\n') return data.getvalue()