def _handle_empty_response_body(self, state):
        # Enforce HTTP 204 for responses which contain no body
        if state.response.status_int == 200:
            # If the response is a generator...
            if isinstance(state.response.app_iter, types.GeneratorType):
                # Split the generator into two so we can peek at one of them
                # and determine if there is any response body content
                a, b = tee(state.response.app_iter)
                try:
                    next(a)
                except StopIteration:
                    # If we hit StopIteration, the body is empty
                    state.response.status = 204
                finally:
                    state.response.app_iter = b
            else:
                text = None
                if state.response.charset:
                    # `response.text` cannot be accessed without a valid
                    # charset (because we don't know which encoding to use)
                    try:
                        text = state.response.text
                    except __HOLE__:
                        # If a valid charset is not specified, don't bother
                        # trying to guess it (because there's obviously
                        # content, so we know this shouldn't be a 204)
                        pass
                if not any((state.response.body, text)):
                    state.response.status = 204

        if state.response.status_int in (204, 304):
            state.response.content_type = None
dataset/ETHPy150Open pecan/pecan/pecan/core.py/PecanBase._handle_empty_response_body