lxml.html.diff module — lxml documentation

# lxml.html.diff module

class lxml.html.diff.DEL_END

  Bases: `object`

class lxml.html.diff.DEL_START

  Bases: `object`

class lxml.html.diff.InsensitiveSequenceMatcher

  Bases: `SequenceMatcher`

  Acts like SequenceMatcher, but tries not to find very small equal blocks amidst large spans of changes

  get_grouped_opcodes(n=3)

    Isolate change clusters by eliminating ranges with no changes.

    Return a generator of groups with up to n lines of context. Each group is in the same format as returned by get_opcodes().

        >>> from pprint import pprint
        >>> a = list(map(str, range(1,40)))
        >>> b = a[:]
        >>> b[8:8] = ['i']     # Make an insertion
        >>> b[20] += 'x'       # Make a replacement
        >>> b[23:28] = []      # Make a deletion
        >>> b[30] += 'y'       # Make another replacement
        >>> pprint(list(SequenceMatcher(None,a,b).get_grouped_opcodes()))
        [[('equal', 5, 8, 5, 8), ('insert', 8, 8, 8, 9), ('equal', 8, 11, 9, 12)],
         [('equal', 16, 19, 17, 20),
          ('replace', 19, 20, 20, 21),
          ('equal', 20, 22, 21, 23),
          ('delete', 22, 27, 23, 23),
          ('equal', 27, 30, 23, 26)],
         [('equal', 31, 34, 27, 30),
          ('replace', 34, 35, 30, 31),
          ('equal', 35, 38, 31, 34)]]

  ratio()

    Return a measure of the sequences’ similarity (float in [0,1]).

    Where T is the total number of elements in both sequences, and M is the number of matches, this is 2.0*M / T. Note that this is 1 if the sequences are identical, and 0 if they have nothing in common.

    .ratio() is expensive to compute if you haven’t already computed .get_matching_blocks() or .get_opcodes(), in which case you may want to try .quick_ratio() or .real_quick_ratio() first to get an upper bound.

        >>> s = SequenceMatcher(None, "abcd", "bcde")
        >>> s.ratio()
        0.75
        >>> s.quick_ratio()
        0.75
        >>> s.real_quick_ratio()
        1.0

  set_seq1(a)

    Set the first sequence to be compared.

    The second sequence to be compared is not changed.

        >>> s = SequenceMatcher(None, "abcd", "bcde")
        >>> s.ratio()
        0.75
        >>> s.set_seq1("bcde")
        >>> s.ratio()
        1.0
        >>>

    SequenceMatcher computes and caches detailed information about the second sequence, so if you want to compare one sequence S against many sequences, use .set_seq2(S) once and call .set_seq1(x) repeatedly for each of the other sequences.

    See also set_seqs() and set_seq2().

  set_seq2(b)

    Set the second sequence to be compared.

    The first sequence to be compared is not changed.

        >>> s = SequenceMatcher(None, "abcd", "bcde")
        >>> s.ratio()
        0.75
        >>> s.set_seq2("abcd")
        >>> s.ratio()
        1.0
        >>>

    SequenceMatcher computes and caches detailed information about the second sequence, so if you want to compare one sequence S against many sequences, use .set_seq2(S) once and call .set_seq1(x) repeatedly for each of the other sequences.

    See also set_seqs() and set_seq1().

  set_seqs(a, b)

    Set the two sequences to be compared.

        >>> s = SequenceMatcher()
        >>> s.set_seqs("abcd", "bcde")
        >>> s.ratio()
        0.75

  a
  b
  threshold = 2

class lxml.html.diff.href_token(text, pre_tags=None, post_tags=None, trailing_whitespace='')

  Bases: `token`

  Represents the href in an anchor tag. Unlike other words, we only show the href when it changes.

  static maketrans()

    Return a translation table usable for str.translate().

    If there is only one argument, it must be a dictionary mapping Unicode ordinals (integers) or characters to Unicode ordinals, strings or None. Character keys will be then converted to ordinals. If there are two arguments, they must be strings of equal length, and in the resulting dictionary, each character in x will be mapped to the character at the same position in y. If there is a third argument, it must be a string, whose characters will be mapped to None in the result.

  capitalize()

    Return a capitalized version of the string.

    More specifically, make the first character have upper case and the rest lower case.

  casefold()

    Return a version of the string suitable for caseless comparisons.

  center(width, fillchar=' ', /)

    Return a centered string of length width.

    Padding is done using the specified fill character (default is a space).

  count()

    Return the number of non-overlapping occurrences of substring sub in string S[start:end].

    Optional arguments start and end are interpreted as in slice notation.

  encode(encoding='utf-8', errors='strict')

    Encode the string using the codec registered for encoding.

    encoding

      The encoding in which to encode the string.

    errors

      The error handling scheme to use for encoding errors. The default is ‘strict’ meaning that encoding errors raise a UnicodeEncodeError. Other possible values are ‘ignore’, ‘replace’ and ‘xmlcharrefreplace’ as well as any other name registered with codecs.register_error that can handle UnicodeEncodeErrors.

  endswith()

    Return True if the string ends with the specified suffix, False otherwise.

    suffix

      A string or a tuple of strings to try.

    start

      Optional start position. Default: start of the string.

    end

      Optional stop position. Default: end of the string.

  expandtabs(tabsize=8)

    Return a copy where all tab characters are expanded using spaces.

    If tabsize is not given, a tab size of 8 characters is assumed.

  find()

    Return the lowest index in S where substring sub is found, such that sub is contained within S[start:end].

    Optional arguments start and end are interpreted as in slice notation. Return -1 on failure.

  format(*args, **kwargs)

    Return a formatted version of the string, using substitutions from args and kwargs. The substitutions are identified by braces (‘{’ and ‘}’).

  format_map(mapping, /)

    Return a formatted version of the string, using substitutions from mapping. The substitutions are identified by braces (‘{’ and ‘}’).

  html()
  index()

    Return the lowest index in S where substring sub is found, such that sub is contained within S[start:end].

    Optional arguments start and end are interpreted as in slice notation. Raises ValueError when the substring is not found.

  isalnum()

    Return True if the string is an alpha-numeric string, False otherwise.

    A string is alpha-numeric if all characters in the string are alpha-numeric and there is at least one character in the string.

  isalpha()

    Return True if the string is an alphabetic string, False otherwise.

    A string is alphabetic if all characters in the string are alphabetic and there is at least one character in the string.

  isascii()

    Return True if all characters in the string are ASCII, False otherwise.

    ASCII characters have code points in the range U+0000-U+007F. Empty string is ASCII too.

  isdecimal()

    Return True if the string is a decimal string, False otherwise.

    A string is a decimal string if all characters in the string are decimal and there is at least one character in the string.

  isdigit()

    Return True if the string is a digit string, False otherwise.

    A string is a digit string if all characters in the string are digits and there is at least one character in the string.

  isidentifier()

    Return True if the string is a valid Python identifier, False otherwise.

    Call keyword.iskeyword(s) to test whether string s is a reserved identifier, such as “def” or “class”.

  islower()

    Return True if the string is a lowercase string, False otherwise.

    A string is lowercase if all cased characters in the string are lowercase and there is at least one cased character in the string.

  isnumeric()

    Return True if the string is a numeric string, False otherwise.

    A string is numeric if all characters in the string are numeric and there is at least one character in the string.

  isprintable()

    Return True if all characters in the string are printable, False otherwise.

    A character is printable if repr() may use it in its output.

  isspace()

    Return True if the string is a whitespace string, False otherwise.

    A string is whitespace if all characters in the string are whitespace and there is at least one character in the string.

  istitle()

    Return True if the string is a title-cased string, False otherwise.

    In a title-cased string, upper- and title-case characters may only follow uncased characters and lowercase characters only cased ones.

  isupper()

    Return True if the string is an uppercase string, False otherwise.

    A string is uppercase if all cased characters in the string are uppercase and there is at least one cased character in the string.

  join(iterable, /)

    Concatenate any number of strings.

    The string whose method is called is inserted in between each given string. The result is returned as a new string.

    Example: ‘.’.join([‘ab’, ‘pq’, ‘rs’]) -> ‘ab.pq.rs’

  ljust(width, fillchar=' ', /)

    Return a left-justified string of length width.

    Padding is done using the specified fill character (default is a space).

  lower()

    Return a copy of the string converted to lowercase.

  lstrip(chars=None, /)

    Return a copy of the string with leading whitespace removed.

    If chars is given and not None, remove characters in chars instead.

  partition(sep, /)

    Partition the string into three parts using the given separator.

    This will search for the separator in the string. If the separator is found, returns a 3-tuple containing the part before the separator, the separator itself, and the part after it.

    If the separator is not found, returns a 3-tuple containing the original string and two empty strings.

  removeprefix(prefix, /)

    Return a str with the given prefix string removed if present.

    If the string starts with the prefix string, return string[len(prefix):]. Otherwise, return a copy of the original string.

  removesuffix(suffix, /)

    Return a str with the given suffix string removed if present.

    If the string ends with the suffix string and that suffix is not empty, return string[:-len(suffix)]. Otherwise, return a copy of the original string.

  replace(old, new, /, count=-1)

    Return a copy with all occurrences of substring old replaced by new.

    > count

    >   Maximum number of occurrences to replace. -1 (the default value) means replace all occurrences.

    If the optional argument count is given, only the first count occurrences are replaced.

  rfind()

    Return the highest index in S where substring sub is found, such that sub is contained within S[start:end].

    Optional arguments start and end are interpreted as in slice notation. Return -1 on failure.

  rindex()

    Return the highest index in S where substring sub is found, such that sub is contained within S[start:end].

    Optional arguments start and end are interpreted as in slice notation. Raises ValueError when the substring is not found.

  rjust(width, fillchar=' ', /)

    Return a right-justified string of length width.

    Padding is done using the specified fill character (default is a space).

  rpartition(sep, /)

    Partition the string into three parts using the given separator.

    This will search for the separator in the string, starting at the end. If the separator is found, returns a 3-tuple containing the part before the separator, the separator itself, and the part after it.

    If the separator is not found, returns a 3-tuple containing two empty strings and the original string.

  rsplit(sep=None, maxsplit=-1)

    Return a list of the substrings in the string, using sep as the separator string.

    > sep

    >   The separator used to split the string.

    >   When set to None (the default value), will split on any whitespace character (including n r t f and spaces) and will discard empty strings from the result.

    > maxsplit

    >   Maximum number of splits. -1 (the default value) means no limit.

    Splitting starts at the end of the string and works to the front.

  rstrip(chars=None, /)

    Return a copy of the string with trailing whitespace removed.

    If chars is given and not None, remove characters in chars instead.

  split(sep=None, maxsplit=-1)

    Return a list of the substrings in the string, using sep as the separator string.

    > sep

    >   The separator used to split the string.

    >   When set to None (the default value), will split on any whitespace character (including n r t f and spaces) and will discard empty strings from the result.

    > maxsplit

    >   Maximum number of splits. -1 (the default value) means no limit.

    Splitting starts at the front of the string and works to the end.

    Note, str.split() is mainly useful for data that has been intentionally delimited. With natural text that includes punctuation, consider using the regular expression module.

  splitlines(keepends=False)

    Return a list of the lines in the string, breaking at line boundaries.

    Line breaks are not included in the resulting list unless keepends is given and true.

  startswith()

    Return True if the string starts with the specified prefix, False otherwise.

    prefix

      A string or a tuple of strings to try.

    start

      Optional start position. Default: start of the string.

    end

      Optional stop position. Default: end of the string.

  strip(chars=None, /)

    Return a copy of the string with leading and trailing whitespace removed.

    If chars is given and not None, remove characters in chars instead.

  swapcase()

    Convert uppercase characters to lowercase and lowercase characters to uppercase.

  title()

    Return a version of the string where each word is titlecased.

    More specifically, words start with uppercased characters and all remaining cased characters have lower case.

  translate(table, /)

    Replace each character in the string using the given translation table.

    > table

    >   Translation table, which must be a mapping of Unicode ordinals to Unicode ordinals, strings, or None.

    The table must implement lookup/indexing via __getitem__, for instance a dictionary or list. If this operation raises LookupError, the character is left untouched. Characters mapped to None are deleted.

  upper()

    Return a copy of the string converted to uppercase.

  zfill(width, /)

    Pad a numeric string with zeros on the left, to fill a field of the given width.

    The string is never truncated.

  hide_when_equal = True

class lxml.html.diff.tag_token(tag, data, html_repr, pre_tags=None, post_tags=None, trailing_whitespace='')

  Bases: `token`

  Represents a token that is actually a tag. Currently this is just the <img> tag, which takes up visible space just like a word but is only represented in a document by a tag.

  static maketrans()

    Return a translation table usable for str.translate().

    If there is only one argument, it must be a dictionary mapping Unicode ordinals (integers) or characters to Unicode ordinals, strings or None. Character keys will be then converted to ordinals. If there are two arguments, they must be strings of equal length, and in the resulting dictionary, each character in x will be mapped to the character at the same position in y. If there is a third argument, it must be a string, whose characters will be mapped to None in the result.

  capitalize()

    Return a capitalized version of the string.

    More specifically, make the first character have upper case and the rest lower case.

  casefold()

    Return a version of the string suitable for caseless comparisons.

  center(width, fillchar=' ', /)

    Return a centered string of length width.

    Padding is done using the specified fill character (default is a space).

  count()

    Return the number of non-overlapping occurrences of substring sub in string S[start:end].

    Optional arguments start and end are interpreted as in slice notation.

  encode(encoding='utf-8', errors='strict')

    Encode the string using the codec registered for encoding.

    encoding

      The encoding in which to encode the string.

    errors

      The error handling scheme to use for encoding errors. The default is ‘strict’ meaning that encoding errors raise a UnicodeEncodeError. Other possible values are ‘ignore’, ‘replace’ and ‘xmlcharrefreplace’ as well as any other name registered with codecs.register_error that can handle UnicodeEncodeErrors.

  endswith()

    Return True if the string ends with the specified suffix, False otherwise.

    suffix

      A string or a tuple of strings to try.

    start

      Optional start position. Default: start of the string.

    end

      Optional stop position. Default: end of the string.

  expandtabs(tabsize=8)

    Return a copy where all tab characters are expanded using spaces.

    If tabsize is not given, a tab size of 8 characters is assumed.

  find()

    Return the lowest index in S where substring sub is found, such that sub is contained within S[start:end].

    Optional arguments start and end are interpreted as in slice notation. Return -1 on failure.

  format(*args, **kwargs)

    Return a formatted version of the string, using substitutions from args and kwargs. The substitutions are identified by braces (‘{’ and ‘}’).

  format_map(mapping, /)

    Return a formatted version of the string, using substitutions from mapping. The substitutions are identified by braces (‘{’ and ‘}’).

  html()
  index()

    Return the lowest index in S where substring sub is found, such that sub is contained within S[start:end].

    Optional arguments start and end are interpreted as in slice notation. Raises ValueError when the substring is not found.

  isalnum()

    Return True if the string is an alpha-numeric string, False otherwise.

    A string is alpha-numeric if all characters in the string are alpha-numeric and there is at least one character in the string.

  isalpha()

    Return True if the string is an alphabetic string, False otherwise.

    A string is alphabetic if all characters in the string are alphabetic and there is at least one character in the string.

  isascii()

    Return True if all characters in the string are ASCII, False otherwise.

    ASCII characters have code points in the range U+0000-U+007F. Empty string is ASCII too.

  isdecimal()

    Return True if the string is a decimal string, False otherwise.

    A string is a decimal string if all characters in the string are decimal and there is at least one character in the string.

  isdigit()

    Return True if the string is a digit string, False otherwise.

    A string is a digit string if all characters in the string are digits and there is at least one character in the string.

  isidentifier()

    Return True if the string is a valid Python identifier, False otherwise.

    Call keyword.iskeyword(s) to test whether string s is a reserved identifier, such as “def” or “class”.

  islower()

    Return True if the string is a lowercase string, False otherwise.

    A string is lowercase if all cased characters in the string are lowercase and there is at least one cased character in the string.

  isnumeric()

    Return True if the string is a numeric string, False otherwise.

    A string is numeric if all characters in the string are numeric and there is at least one character in the string.

  isprintable()

    Return True if all characters in the string are printable, False otherwise.

    A character is printable if repr() may use it in its output.

  isspace()

    Return True if the string is a whitespace string, False otherwise.

    A string is whitespace if all characters in the string are whitespace and there is at least one character in the string.

  istitle()

    Return True if the string is a title-cased string, False otherwise.

    In a title-cased string, upper- and title-case characters may only follow uncased characters and lowercase characters only cased ones.

  isupper()

    Return True if the string is an uppercase string, False otherwise.

    A string is uppercase if all cased characters in the string are uppercase and there is at least one cased character in the string.

  join(iterable, /)

    Concatenate any number of strings.

    The string whose method is called is inserted in between each given string. The result is returned as a new string.

    Example: ‘.’.join([‘ab’, ‘pq’, ‘rs’]) -> ‘ab.pq.rs’

  ljust(width, fillchar=' ', /)

    Return a left-justified string of length width.

    Padding is done using the specified fill character (default is a space).

  lower()

    Return a copy of the string converted to lowercase.

  lstrip(chars=None, /)

    Return a copy of the string with leading whitespace removed.

    If chars is given and not None, remove characters in chars instead.

  partition(sep, /)

    Partition the string into three parts using the given separator.

    This will search for the separator in the string. If the separator is found, returns a 3-tuple containing the part before the separator, the separator itself, and the part after it.

    If the separator is not found, returns a 3-tuple containing the original string and two empty strings.

  removeprefix(prefix, /)

    Return a str with the given prefix string removed if present.

    If the string starts with the prefix string, return string[len(prefix):]. Otherwise, return a copy of the original string.

  removesuffix(suffix, /)

    Return a str with the given suffix string removed if present.

    If the string ends with the suffix string and that suffix is not empty, return string[:-len(suffix)]. Otherwise, return a copy of the original string.

  replace(old, new, /, count=-1)

    Return a copy with all occurrences of substring old replaced by new.

    > count

    >   Maximum number of occurrences to replace. -1 (the default value) means replace all occurrences.

    If the optional argument count is given, only the first count occurrences are replaced.

  rfind()

    Return the highest index in S where substring sub is found, such that sub is contained within S[start:end].

    Optional arguments start and end are interpreted as in slice notation. Return -1 on failure.

  rindex()

    Return the highest index in S where substring sub is found, such that sub is contained within S[start:end].

    Optional arguments start and end are interpreted as in slice notation. Raises ValueError when the substring is not found.

  rjust(width, fillchar=' ', /)

    Return a right-justified string of length width.

    Padding is done using the specified fill character (default is a space).

  rpartition(sep, /)

    Partition the string into three parts using the given separator.

    This will search for the separator in the string, starting at the end. If the separator is found, returns a 3-tuple containing the part before the separator, the separator itself, and the part after it.

    If the separator is not found, returns a 3-tuple containing two empty strings and the original string.

  rsplit(sep=None, maxsplit=-1)

    Return a list of the substrings in the string, using sep as the separator string.

    > sep

    >   The separator used to split the string.

    >   When set to None (the default value), will split on any whitespace character (including n r t f and spaces) and will discard empty strings from the result.

    > maxsplit

    >   Maximum number of splits. -1 (the default value) means no limit.

    Splitting starts at the end of the string and works to the front.

  rstrip(chars=None, /)

    Return a copy of the string with trailing whitespace removed.

    If chars is given and not None, remove characters in chars instead.

  split(sep=None, maxsplit=-1)

    Return a list of the substrings in the string, using sep as the separator string.

    > sep

    >   The separator used to split the string.

    >   When set to None (the default value), will split on any whitespace character (including n r t f and spaces) and will discard empty strings from the result.

    > maxsplit

    >   Maximum number of splits. -1 (the default value) means no limit.

    Splitting starts at the front of the string and works to the end.

    Note, str.split() is mainly useful for data that has been intentionally delimited. With natural text that includes punctuation, consider using the regular expression module.

  splitlines(keepends=False)

    Return a list of the lines in the string, breaking at line boundaries.

    Line breaks are not included in the resulting list unless keepends is given and true.

  startswith()

    Return True if the string starts with the specified prefix, False otherwise.

    prefix

      A string or a tuple of strings to try.

    start

      Optional start position. Default: start of the string.

    end

      Optional stop position. Default: end of the string.

  strip(chars=None, /)

    Return a copy of the string with leading and trailing whitespace removed.

    If chars is given and not None, remove characters in chars instead.

  swapcase()

    Convert uppercase characters to lowercase and lowercase characters to uppercase.

  title()

    Return a version of the string where each word is titlecased.

    More specifically, words start with uppercased characters and all remaining cased characters have lower case.

  translate(table, /)

    Replace each character in the string using the given translation table.

    > table

    >   Translation table, which must be a mapping of Unicode ordinals to Unicode ordinals, strings, or None.

    The table must implement lookup/indexing via __getitem__, for instance a dictionary or list. If this operation raises LookupError, the character is left untouched. Characters mapped to None are deleted.

  upper()

    Return a copy of the string converted to uppercase.

  zfill(width, /)

    Pad a numeric string with zeros on the left, to fill a field of the given width.

    The string is never truncated.

  hide_when_equal = False

class lxml.html.diff.token(text, pre_tags=None, post_tags=None, trailing_whitespace='')

  Bases: `str`

  Represents a diffable token, generally a word that is displayed to the user. Opening tags are attached to this token when they are adjacent (pre_tags) and closing tags that follow the word (post_tags). Some exceptions occur when there are empty tags adjacent to a word, so there may be close tags in pre_tags, or open tags in post_tags.

  We also keep track of whether the word was originally followed by whitespace, even though we do not want to treat the word as equivalent to a similar word that does not have a trailing space.

  static maketrans()

    Return a translation table usable for str.translate().

    If there is only one argument, it must be a dictionary mapping Unicode ordinals (integers) or characters to Unicode ordinals, strings or None. Character keys will be then converted to ordinals. If there are two arguments, they must be strings of equal length, and in the resulting dictionary, each character in x will be mapped to the character at the same position in y. If there is a third argument, it must be a string, whose characters will be mapped to None in the result.

  capitalize()

    Return a capitalized version of the string.

    More specifically, make the first character have upper case and the rest lower case.

  casefold()

    Return a version of the string suitable for caseless comparisons.

  center(width, fillchar=' ', /)

    Return a centered string of length width.

    Padding is done using the specified fill character (default is a space).

  count()

    Return the number of non-overlapping occurrences of substring sub in string S[start:end].

    Optional arguments start and end are interpreted as in slice notation.

  encode(encoding='utf-8', errors='strict')

    Encode the string using the codec registered for encoding.

    encoding

      The encoding in which to encode the string.

    errors

      The error handling scheme to use for encoding errors. The default is ‘strict’ meaning that encoding errors raise a UnicodeEncodeError. Other possible values are ‘ignore’, ‘replace’ and ‘xmlcharrefreplace’ as well as any other name registered with codecs.register_error that can handle UnicodeEncodeErrors.

  endswith()

    Return True if the string ends with the specified suffix, False otherwise.

    suffix

      A string or a tuple of strings to try.

    start

      Optional start position. Default: start of the string.

    end

      Optional stop position. Default: end of the string.

  expandtabs(tabsize=8)

    Return a copy where all tab characters are expanded using spaces.

    If tabsize is not given, a tab size of 8 characters is assumed.

  find()

    Return the lowest index in S where substring sub is found, such that sub is contained within S[start:end].

    Optional arguments start and end are interpreted as in slice notation. Return -1 on failure.

  format(*args, **kwargs)

    Return a formatted version of the string, using substitutions from args and kwargs. The substitutions are identified by braces (‘{’ and ‘}’).

  format_map(mapping, /)

    Return a formatted version of the string, using substitutions from mapping. The substitutions are identified by braces (‘{’ and ‘}’).

  html()
  index()

    Return the lowest index in S where substring sub is found, such that sub is contained within S[start:end].

    Optional arguments start and end are interpreted as in slice notation. Raises ValueError when the substring is not found.

  isalnum()

    Return True if the string is an alpha-numeric string, False otherwise.

    A string is alpha-numeric if all characters in the string are alpha-numeric and there is at least one character in the string.

  isalpha()

    Return True if the string is an alphabetic string, False otherwise.

    A string is alphabetic if all characters in the string are alphabetic and there is at least one character in the string.

  isascii()

    Return True if all characters in the string are ASCII, False otherwise.

    ASCII characters have code points in the range U+0000-U+007F. Empty string is ASCII too.

  isdecimal()

    Return True if the string is a decimal string, False otherwise.

    A string is a decimal string if all characters in the string are decimal and there is at least one character in the string.

  isdigit()

    Return True if the string is a digit string, False otherwise.

    A string is a digit string if all characters in the string are digits and there is at least one character in the string.

  isidentifier()

    Return True if the string is a valid Python identifier, False otherwise.

    Call keyword.iskeyword(s) to test whether string s is a reserved identifier, such as “def” or “class”.

  islower()

    Return True if the string is a lowercase string, False otherwise.

    A string is lowercase if all cased characters in the string are lowercase and there is at least one cased character in the string.

  isnumeric()

    Return True if the string is a numeric string, False otherwise.

    A string is numeric if all characters in the string are numeric and there is at least one character in the string.

  isprintable()

    Return True if all characters in the string are printable, False otherwise.

    A character is printable if repr() may use it in its output.

  isspace()

    Return True if the string is a whitespace string, False otherwise.

    A string is whitespace if all characters in the string are whitespace and there is at least one character in the string.

  istitle()

    Return True if the string is a title-cased string, False otherwise.

    In a title-cased string, upper- and title-case characters may only follow uncased characters and lowercase characters only cased ones.

  isupper()

    Return True if the string is an uppercase string, False otherwise.

    A string is uppercase if all cased characters in the string are uppercase and there is at least one cased character in the string.

  join(iterable, /)

    Concatenate any number of strings.

    The string whose method is called is inserted in between each given string. The result is returned as a new string.

    Example: ‘.’.join([‘ab’, ‘pq’, ‘rs’]) -> ‘ab.pq.rs’

  ljust(width, fillchar=' ', /)

    Return a left-justified string of length width.

    Padding is done using the specified fill character (default is a space).

  lower()

    Return a copy of the string converted to lowercase.

  lstrip(chars=None, /)

    Return a copy of the string with leading whitespace removed.

    If chars is given and not None, remove characters in chars instead.

  partition(sep, /)

    Partition the string into three parts using the given separator.

    This will search for the separator in the string. If the separator is found, returns a 3-tuple containing the part before the separator, the separator itself, and the part after it.

    If the separator is not found, returns a 3-tuple containing the original string and two empty strings.

  removeprefix(prefix, /)

    Return a str with the given prefix string removed if present.

    If the string starts with the prefix string, return string[len(prefix):]. Otherwise, return a copy of the original string.

  removesuffix(suffix, /)

    Return a str with the given suffix string removed if present.

    If the string ends with the suffix string and that suffix is not empty, return string[:-len(suffix)]. Otherwise, return a copy of the original string.

  replace(old, new, /, count=-1)

    Return a copy with all occurrences of substring old replaced by new.

    > count

    >   Maximum number of occurrences to replace. -1 (the default value) means replace all occurrences.

    If the optional argument count is given, only the first count occurrences are replaced.

  rfind()

    Return the highest index in S where substring sub is found, such that sub is contained within S[start:end].

    Optional arguments start and end are interpreted as in slice notation. Return -1 on failure.

  rindex()

    Return the highest index in S where substring sub is found, such that sub is contained within S[start:end].

    Optional arguments start and end are interpreted as in slice notation. Raises ValueError when the substring is not found.

  rjust(width, fillchar=' ', /)

    Return a right-justified string of length width.

    Padding is done using the specified fill character (default is a space).

  rpartition(sep, /)

    Partition the string into three parts using the given separator.

    This will search for the separator in the string, starting at the end. If the separator is found, returns a 3-tuple containing the part before the separator, the separator itself, and the part after it.

    If the separator is not found, returns a 3-tuple containing two empty strings and the original string.

  rsplit(sep=None, maxsplit=-1)

    Return a list of the substrings in the string, using sep as the separator string.

    > sep

    >   The separator used to split the string.

    >   When set to None (the default value), will split on any whitespace character (including n r t f and spaces) and will discard empty strings from the result.

    > maxsplit

    >   Maximum number of splits. -1 (the default value) means no limit.

    Splitting starts at the end of the string and works to the front.

  rstrip(chars=None, /)

    Return a copy of the string with trailing whitespace removed.

    If chars is given and not None, remove characters in chars instead.

  split(sep=None, maxsplit=-1)

    Return a list of the substrings in the string, using sep as the separator string.

    > sep

    >   The separator used to split the string.

    >   When set to None (the default value), will split on any whitespace character (including n r t f and spaces) and will discard empty strings from the result.

    > maxsplit

    >   Maximum number of splits. -1 (the default value) means no limit.

    Splitting starts at the front of the string and works to the end.

    Note, str.split() is mainly useful for data that has been intentionally delimited. With natural text that includes punctuation, consider using the regular expression module.

  splitlines(keepends=False)

    Return a list of the lines in the string, breaking at line boundaries.

    Line breaks are not included in the resulting list unless keepends is given and true.

  startswith()

    Return True if the string starts with the specified prefix, False otherwise.

    prefix

      A string or a tuple of strings to try.

    start

      Optional start position. Default: start of the string.

    end

      Optional stop position. Default: end of the string.

  strip(chars=None, /)

    Return a copy of the string with leading and trailing whitespace removed.

    If chars is given and not None, remove characters in chars instead.

  swapcase()

    Convert uppercase characters to lowercase and lowercase characters to uppercase.

  title()

    Return a version of the string where each word is titlecased.

    More specifically, words start with uppercased characters and all remaining cased characters have lower case.

  translate(table, /)

    Replace each character in the string using the given translation table.

    > table

    >   Translation table, which must be a mapping of Unicode ordinals to Unicode ordinals, strings, or None.

    The table must implement lookup/indexing via __getitem__, for instance a dictionary or list. If this operation raises LookupError, the character is left untouched. Characters mapped to None are deleted.

  upper()

    Return a copy of the string converted to uppercase.

  zfill(width, /)

    Pad a numeric string with zeros on the left, to fill a field of the given width.

    The string is never truncated.

  hide_when_equal = False

lxml.html.diff.__pyx_unpickle_InsensitiveSequenceMatcher(__pyx_type, __pyx_checksum, __pyx_state)

lxml.html.diff._find_words(string, pos=0, endpos=9223372036854775807)

  Return a list of all non-overlapping matches of pattern in string.

lxml.html.diff._has_start_whitespace(string, pos=0, endpos=9223372036854775807)

  Matches zero or more characters at the beginning of the string.

lxml.html.diff._merge_element_contents(el)

  Removes an element, but merges its contents into its place, e.g., given <p>Hi <i>there!</i></p>, if you remove the <i> element you get <p>Hi there!</p>

lxml.html.diff._replace_ins_del(repl, string, count=0)

  Return the string obtained by replacing the leftmost non-overlapping occurrences of pattern in string by the replacement repl.

lxml.html.diff._search_body(string, pos=0, endpos=9223372036854775807)

  Scan through string looking for a match, and return a corresponding match object instance.

  Return None if no position in the string matches.

lxml.html.diff._search_end_body(string, pos=0, endpos=9223372036854775807)

  Scan through string looking for a match, and return a corresponding match object instance.

  Return None if no position in the string matches.

lxml.html.diff.cleanup_delete(chunks: list)

  Cleans up any DEL_START/DEL_END markers in the document, replacing them with <del></del>. To do this while keeping the document valid, it may need to drop some tags (either start or end tags).

  It may also move the del into adjacent tags to try to move it to a similar location where it was originally located (e.g., moving a delete into preceding <div> tag, if the del looks like (DEL_START, ‘Text</div>’, DEL_END)

lxml.html.diff.cleanup_html(html)

  This ‘cleans’ the HTML, meaning that any page structure is removed (only the contents of <body> are used, if there is any <body). Also <ins> and <del> tags are removed.

lxml.html.diff.compress_tokens(tokens)

  Combine adjacent tokens when there is no HTML between the tokens, and they share an annotation

lxml.html.diff.copy_annotations(src, dest)

  Copy annotations from the tokens listed in src to the tokens in dest

lxml.html.diff.default_markup(text, version)

lxml.html.diff.end_tag(el)

  The text representation of an end tag for a tag. Includes trailing whitespace when appropriate.

lxml.html.diff.expand_tokens(tokens, equal=False)

  Given a list of tokens, return a generator of the chunks of text for the data in the tokens.

lxml.html.diff.fixup_chunks(chunks)

  This function takes a list of chunks and produces a list of tokens.

lxml.html.diff.fixup_ins_del_tags(html)

  Given an html string, move any <ins> or <del> tags inside of any block-level elements, e.g. transform <ins><p>word</p></ins> to <p><ins>word</ins></p>

lxml.html.diff.flatten_el(el, include_hrefs, skip_tag=False)

  Takes an lxml element el, and generates all the text chunks for that tag. Each start tag is a chunk, each word is a chunk, and each end tag is a chunk.

  If skip_tag is true, then the outermost container tag is not returned (just its contents).

lxml.html.diff.html_annotate(doclist, markup=<cyfunction default_markup>)

  doclist should be ordered from oldest to newest, like:

      >>> version1 = 'Hello World'
      >>> version2 = 'Goodbye World'
      >>> print(html_annotate([(version1, 'version 1'),
      ...                      (version2, 'version 2')]))
      <span title="version 2">Goodbye</span> <span title="version 1">World</span>

  The documents must be fragments (str/UTF8 or unicode), not complete documents

  The markup argument is a function to markup the spans of words. This function is called like markup(‘Hello’, ‘version 2’), and returns HTML. The first argument is text and never includes any markup. The default uses a span with a title:

      >>> print(default_markup('Some Text', 'by Joe'))
      <span title="by Joe">Some Text</span>

lxml.html.diff.html_annotate_merge_annotations(tokens_old, tokens_new)

  Merge the annotations from tokens_old into tokens_new, when the tokens in the new document already existed in the old document.

lxml.html.diff.htmldiff(old_html, new_html)

  Do a diff of the old and new document. The documents are HTML fragments (str/UTF8 or unicode), they are not complete documents (i.e., no <html> tag).

  Returns HTML with <ins> and <del> tags added around the appropriate text.

  Markup is generally ignored, with the markup from new_html preserved, and possibly some markup from old_html (though it is considered acceptable to lose some of the old markup). Only the words in the HTML are diffed. The exception is <img> tags, which are treated like words, and the href attribute of <a> tags, which are noted inside the tag itself when there are changes.

lxml.html.diff.htmldiff_tokens(html1_tokens, html2_tokens)

  Does a diff on the tokens themselves, returning a list of text chunks (not tokens).

lxml.html.diff.is_end_tag(tok)

lxml.html.diff.is_start_tag(tok)

lxml.html.diff.is_word(tok)

lxml.html.diff.markup_serialize_tokens(tokens, markup_func)

  Serialize the list of tokens into a list of text chunks, calling markup_func around text to add annotations.

lxml.html.diff.merge_delete(del_chunks, doc: list)

  Adds the text chunks in del_chunks to the document doc (another list of text chunks) with marker to show it is a delete. cleanup_delete later resolves these markers into <del> tags.

lxml.html.diff.merge_insert(ins_chunks, doc: list)

  doc is the already-handled document (as a list of text chunks); here we add <ins>ins_chunks</ins> to the end of that.

lxml.html.diff.parse_html(html, cleanup=True)

  Parses an HTML fragment, returning an lxml element. Note that the HTML will be wrapped in a <div> tag that was not in the original document.

  If cleanup is true, make sure there’s no <head> or <body>, and get rid of any <ins> and <del> tags.

lxml.html.diff.serialize_html_fragment(el, skip_outer=False)

  Serialize a single lxml element as HTML. The serialized form includes the elements tail.

  If skip_outer is true, then don’t serialize the outermost tag

lxml.html.diff.split_trailing_whitespace(word)

  > This function takes a word, such as ‘test

  ‘ and returns (‘test’,’

  ‘)

lxml.html.diff.split_words(text)

  Splits some text into words. Includes trailing whitespace on each word when appropriate.

lxml.html.diff.start_tag(el)

  The text representation of the start tag for a tag.

lxml.html.diff.tokenize(html, include_hrefs=True)

  Parse the given HTML and returns token objects (words with attached tags).

  This parses only the content of a page; anything in the head is ignored, and the <head> and <body> elements are themselves optional. The content is then parsed by lxml, which ensures the validity of the resulting parsed document (though lxml may make incorrect guesses when the markup is particular bad).

  <ins> and <del> tags are also eliminated from the document, as that gets confusing.

  If include_hrefs is true, then the href attribute of <a> tags is included as a special kind of diffable token.

lxml.html.diff.tokenize_annotated(doc, annotation)

  Tokenize a document and add an annotation attribute to each token