def _cast(self, out, request, response, peek=None):
<EOL>if not out:<EOL><INDENT>response['<STR_LIT>'] = <NUM_LIT:0><EOL>return []<EOL><DEDENT>if isinstance(out, (tuple, list))and isinstance(out[<NUM_LIT:0>], (bytes, str)):<EOL><INDENT>out = out[<NUM_LIT:0>][<NUM_LIT:0>:<NUM_LIT:0>].join(out) <EOL><DEDENT>if isinstance(out, str):<EOL><INDENT>out = out.encode(response.charset)<EOL><DEDENT>if isinstance(out, bytes):<EOL><INDENT>response['<STR_LIT>'] = len(out)<EOL>return [out]<EOL><DEDENT>if isinstance(out, HTTPError):<EOL><INDENT>out.apply(response)<EOL>out = self.error_handler.get(out.status, repr)(out)<EOL>if isinstance(out, HTTPResponse):<EOL><INDENT>depr('<STR_LIT>') <EOL><DEDENT>return self._cast(out, request, response)<EOL><DEDENT>if isinstance(out, HTTPResponse):<EOL><INDENT>out.apply(response)<EOL>return self._cast(out.output, request, response)<EOL><DEDENT>if hasattr(out, '<STR_LIT>'):<EOL><INDENT>if '<STR_LIT>' in request.environ:<EOL><INDENT>return request.environ['<STR_LIT>'](out)<EOL><DEDENT>elif hasattr(out, '<STR_LIT>') or not hasattr(out, '<STR_LIT>'):<EOL><INDENT>return WSGIFileWrapper(out)<EOL><DEDENT><DEDENT>try:<EOL><INDENT>out = iter(out)<EOL>first = next(out)<EOL>while not first:<EOL><INDENT>first = next(out)<EOL><DEDENT><DEDENT>except StopIteration:<EOL><INDENT>return self._cast('<STR_LIT>', request, response)<EOL><DEDENT>except HTTPResponse as e:<EOL><INDENT>first = e<EOL><DEDENT>except Exception as e:<EOL><INDENT>first = HTTPError(<NUM_LIT>, '<STR_LIT>', e, format_exc(<NUM_LIT:10>))<EOL>if isinstance(e, (KeyboardInterrupt, SystemExit, MemoryError))or not self.catchall:<EOL><INDENT>raise<EOL><DEDENT><DEDENT>if isinstance(first, HTTPResponse):<EOL><INDENT>return self._cast(first, request, response)<EOL><DEDENT>if isinstance(first, bytes):<EOL><INDENT>return itertools.chain([first], out)<EOL><DEDENT>if isinstance(first, str):<EOL><INDENT>return map(lambda x: x.encode(response.charset),<EOL>itertools.chain([first], out))<EOL><DEDENT>return self._cast(HTTPError(<NUM_LIT>, '<STR_LIT>'% type(first)), request, response)<EOL>
Try to convert the parameter into something WSGI compatible and set
        correct HTTP headers when possible.
        Support: False, str, unicode, dict, HTTPResponse, HTTPError, file-like,
        iterable of strings and iterable of unicodes