Bytes representation of the HTML content.
        (`learn more <http://www.diveintopython3.net/strings.html>`_).
556463
def raw_html(self) -> _RawHTML:
        
        if self._html:
            return self._html
        else:
            return etree.tostring(self.element, encoding='unicode').strip().encode(self.encoding)
142204
function (bytes) {
                var str = '';
                for (var i = 0, l = bytes.length; i < l; i += 2) {
                    str += String.fromCharCode((bytes[i] << 8) + bytes[i + 1]);
                }
                return str;
            }
930795
def html_result(html: str,
                extraheaders: TYPE_WSGI_RESPONSE_HEADERS = None) \
        -> WSGI_TUPLE_TYPE:
    
    extraheaders = extraheaders or []
    return 'text/html; charset=utf-8', extraheaders, html.encode("utf-8")
451008
def to_bytes(s):
    
    if bytes != str:
        if type(s) == str:
            return s.encode('utf-8')
    return s
865017
def text(self):
        
        data = self.content
        return data.decode(self.encoding or 'utf-8') if data else ''
764128
def encoding(self) -> _Encoding:
        
        if self._encoding:
            return self._encoding

        # Scan meta tags for charset.
        if self._html:
            self._encoding = html_to_unicode(self.default_encoding, self._html)[0]
            # Fall back to requests' detected encoding if decode fails.
            try:
                self.raw_html.decode(self.encoding, errors='replace')
            except UnicodeDecodeError:
                self._encoding = self.default_encoding


        return self._encoding if self._encoding else self.default_encoding
724148
def content(self):
        """"""

        if self.payload:
            message_bytes = mime_to_bytes(
                self.payload, 0).replace(b'\n', b'\r\n')
            boundary = b'--' + self.payload.get_boundary().encode('utf-8')
            temp = message_bytes.split(boundary)
            temp.pop(0)
            return boundary + boundary.join(temp)
        else:
            return ''
830817
def serialize_bytes(data):
        """"""
        if not isinstance(data, bytes):
            if isinstance(data, str):
                data = data.encode('utf-8')
            else:
                raise TypeError(
                    'bytes or str expected, not {}'.format(type(data)))

        r = []
        if len(data) < 254:
            padding = (len(data) + 1) % 4
            if padding != 0:
                padding = 4 - padding

            r.append(bytes([len(data)]))
            r.append(data)

        else:
            padding = len(data) % 4
            if padding != 0:
                padding = 4 - padding

            r.append(bytes([
                254,
                len(data) % 256,
                (len(data) >> 8) % 256,
                (len(data) >> 16) % 256
            ]))
            r.append(data)

        r.append(bytes(padding))
        return b''.join(r)
542112
def serialiseString(self, s):
        
        if type(s) is unicode:
            s = self.context.getBytesForString(s)

        self.serialiseBytes(s)
67
def get_html_content(self):
        

        # Extract full element node content (including subelements)
        html_content = ''
        if hasattr(self, 'xml_element'):
            xml = self.xml_element
            content_list = ["" if xml.text is None else xml.text]

            def to_string(xml):
                if isinstance(xml, _Comment):
                    return str(xml)
                else:
                    return ElementTree.tostring(xml).decode('utf-8')

            content_list += [to_string(e) for e in xml.getchildren()]

            full_xml_content = "".join(content_list)

            # Parse tags to generate HTML valid content
            first_regex = r'html:'
            second_regex = r' xmlns:html=(["\'])(?:(?=(\\?))\2.)*?\1'
            html_content = re.sub(first_regex, '',
                                  re.sub(second_regex, '', full_xml_content))

        return html_content
940221
def to_html(self):
        
        if self.text is None:
            return
        else:
            return '<p%s>%s%s</p>' % (
                self.html_attributes(), self.html_icon(), self.text.to_html())
244872
function (bytes) {

    var str = "";
    var code, b1, b2, b3, b4, upper, lower;
    var i = 0;

    while (i < bytes.length) {

        b1 = bytes[i++];

        if (b1 < 0x80) {
            // 1 byte
            code = b1;
        } else if ((b1 >> 5) === 0x06) {
            // 2 bytes
            b2 = bytes[i++];
            code = ((b1 & 0x1f) << 6) | (b2 & 0x3f);
        } else if ((b1 >> 4) === 0x0e) {
            // 3 bytes
            b2 = bytes[i++];
            b3 = bytes[i++];
            code = ((b1 & 0x0f) << 12) | ((b2 & 0x3f) << 6) | (b3 & 0x3f);
        } else {
            // 4 bytes
            b2 = bytes[i++];
            b3 = bytes[i++];
            b4 = bytes[i++];
            code = ((b1 & 0x07) << 18) | ((b2 & 0x3f) << 12) | ((b3 & 0x3f) << 6) | (b4 & 0x3f);
        }

        if (code < 0x10000) {
            str += String.fromCharCode(code);
        } else {
            // surrogate pair
            code -= 0x10000;
            upper = (0xD800 | (code >> 10));
            lower = (0xDC00 | (code & 0x3FF));
            str += String.fromCharCode(upper, lower);
        }
    }

    return str;
}
975414
async def text(self, *, encoding: Optional[str]=None) -> str:
        """"""
        data = await self.read(decode=True)
        # see https://www.w3.org/TR/html5/forms.html#multipart/form-data-encoding-algorithm # NOQA
        # and https://dvcs.w3.org/hg/xhr/raw-file/tip/Overview.html#dom-xmlhttprequest-send # NOQA
        encoding = encoding or self.get_charset(default='utf-8')
        return data.decode(encoding)
74366
def encode_bytes(self):
        
        with io.StringIO() as buf:
            for char in self.data:
                if not isinstance(char, int):
                    buf.write('{{0:0{0}b}}'.format(8).format(ord(char)))
                else:
                    buf.write('{{0:0{0}b}}'.format(8).format(char))
            return buf.getvalue()
196756
def encoding(self) -> _Encoding:
        
        if self._encoding:
            return self._encoding

        # Scan meta tags for charset.
        if self._xml:
            self._encoding = html_to_unicode(self.default_encoding, self._xml)[0]

        return self._encoding if self._encoding else self.default_encoding
1050100
def readBytes(self):
        
        length, is_reference = self._readLength()

        if is_reference:
            return self.context.getString(length)

        if length == 0:
            return ''

        result = self.stream.read(length)
        self.context.addString(result)

        return result
377630
def html_to_text(html_string):
    
    # create a valid html document from string
    # beware that it inserts <hmtl> <body> and <p> tags
    # where needed
    html_tree = html.document_fromstring(html_string)

    # handle header tags
    for h in html_tree.cssselect("h1, h2, h3, h4, h5, h6"):
        # add two newlines after a header tag
        h.text = h.text + '\n\n'

    # handle links
    # find all a tags starting from the root of the document //
    # and replace the link with (link)
    for a in html_tree.xpath("//a"):
        href = a.attrib['href']
        a.text = a.text + " (" + href + ")"

    # handle paragraphs
    for p in html_tree.xpath("//p"):
        # keep the tail if there is one
        # or add two newlines after the text if there is no tail
        p.tail = p.tail if p.tail else "\n\n"

    # handle breaks
    for br in html_tree.xpath("//br"):
        # add a newline and then the tail (remaining text after the <br/> tag)
        # or add a newline only if there is no tail
        # http://stackoverflow.com/questions/18660382/how-can-i-preserve-br-as-newlines-with-lxml-html-text-content-or-equivalent?rq=1
        br.tail = "\n" + br.tail if br.tail else "\n"

    return html_tree.text_content()