def _encodeValue(self, value):
        """
        Encode a single header value to a UTF-8 encoded bytestring if required.

        @param value: A single HTTP header value.
        @type value: L{bytes} or L{unicode}

        @return: C{value}, encoded if required
        @rtype: L{bytes}
        """
        if isinstance(value, unicode):
            return value.encode('utf8')
        return value

        Encode a single header value to a UTF-8 encoded bytestring if required.

        @param value: A single HTTP header value.
        @type value: L{bytes} or L{unicode}

        @return: C{value}, encoded if required
        @rtype: L{bytes}
        
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/http_headers.py