prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  Provide length of TableOfContents
  Currently, you can only iter over `TableOfContents`. I would like to know the length of it.
  
  </issue>
  <code>
  [start of mkdocs/toc.py]
  1 # coding: utf-8
  2 
  3 """
  4 Deals with generating the per-page table of contents.
  5 
  6 For the sake of simplicity we use an existing markdown extension to generate
  7 an HTML table of contents, and then parse that into the underlying data.
  8 
  9 The steps we take to generate a table of contents are:
  10 
  11 * Pre-process the markdown, injecting a [TOC] marker.
  12 * Generate HTML from markdown.
  13 * Post-process the HTML, spliting the content and the table of contents.
  14 * Parse table of contents HTML into the underlying data structure.
  15 """
  16 
  17 from __future__ import unicode_literals
  18 
  19 try:                                    # pragma: no cover
  20     from html.parser import HTMLParser  # noqa
  21 except ImportError:                     # pragma: no cover
  22     from HTMLParser import HTMLParser   # noqa
  23 
  24 
  25 class TableOfContents(object):
  26     """
  27     Represents the table of contents for a given page.
  28     """
  29     def __init__(self, html):
  30         self.items = _parse_html_table_of_contents(html)
  31 
  32     def __iter__(self):
  33         return iter(self.items)
  34 
  35     def __str__(self):
  36         return ''.join([str(item) for item in self])
  37 
  38 
  39 class AnchorLink(object):
  40     """
  41     A single entry in the table of contents.
  42     """
  43     def __init__(self, title, url):
  44         self.title, self.url = title, url
  45         self.children = []
  46 
  47     def __str__(self):
  48         return self.indent_print()
  49 
  50     def indent_print(self, depth=0):
  51         indent = '    ' * depth
  52         ret = '%s%s - %s\n' % (indent, self.title, self.url)
  53         for item in self.children:
  54             ret += item.indent_print(depth + 1)
  55         return ret
  56 
  57 
  58 class TOCParser(HTMLParser):
  59 
  60     def __init__(self):
  61         HTMLParser.__init__(self)
  62         self.links = []
  63 
  64         self.in_anchor = False
  65         self.attrs = None
  66         self.title = ''
  67 
  68         # Prior to Python3.4 no convert_charrefs keyword existed.
  69         # However, in Python3.5 the default was changed to True.
  70         # We need the False behavior in all versions but can only
  71         # set it if it exists.
  72         if hasattr(self, 'convert_charrefs'):
  73             self.convert_charrefs = False
  74 
  75     def handle_starttag(self, tag, attrs):
  76 
  77         if not self.in_anchor:
  78             if tag == 'a':
  79                 self.in_anchor = True
  80                 self.attrs = dict(attrs)
  81 
  82     def handle_endtag(self, tag):
  83         if tag == 'a':
  84             self.in_anchor = False
  85 
  86     def handle_data(self, data):
  87 
  88         if self.in_anchor:
  89             self.title += data
  90 
  91     def handle_charref(self, ref):
  92         self.handle_entityref("#" + ref)
  93 
  94     def handle_entityref(self, ref):
  95         self.handle_data("&%s;" % ref)
  96 
  97 
  98 def _parse_html_table_of_contents(html):
  99     """
  100     Given a table of contents string that has been automatically generated by
  101     the markdown library, parse it into a tree of AnchorLink instances.
  102 
  103     Returns a list of all the parent AnchorLink instances.
  104     """
  105     lines = html.splitlines()[2:-2]
  106     parents = []
  107     ret = []
  108     for line in lines:
  109         parser = TOCParser()
  110         parser.feed(line)
  111         if parser.title:
  112             try:
  113                 href = parser.attrs['href']
  114             except KeyError:
  115                 continue
  116             title = parser.title
  117             nav = AnchorLink(title, href)
  118             # Add the item to its parent if required.  If it is a topmost
  119             # item then instead append it to our return value.
  120             if parents:
  121                 parents[-1].children.append(nav)
  122             else:
  123                 ret.append(nav)
  124             # If this item has children, store it as the current parent
  125             if line.endswith('<ul>'):
  126                 parents.append(nav)
  127         elif line.startswith('</ul>'):
  128             if parents:
  129                 parents.pop()
  130 
  131     # For the table of contents, always mark the first element as active
  132     if ret:
  133         ret[0].active = True
  134 
  135     return ret
  136
  [end of mkdocs/toc.py]
  </code>
  
  I need you to solve this issue by generating a single patch file that I can apply directly to this repository using git apply. Please respond with a single patch file in the following format.
  <patch>
  diff --git a/file.py b/file.py
  --- a/file.py
  +++ b/file.py
  @@ -1,27 +1,35 @@
   def euclidean(a, b):
  -    while b:
  -        a, b = b, a % b
  -    return a
  +    if b == 0:
  +        return a
  +    return euclidean(b, a % b)
   
   
   def bresenham(x0, y0, x1, y1):
       points = []
       dx = abs(x1 - x0)
       dy = abs(y1 - y0)
  -    sx = 1 if x0 < x1 else -1
  -    sy = 1 if y0 < y1 else -1
  -    err = dx - dy
  +    x, y = x0, y0
  +    sx = -1 if x0 > x1 else 1
  +    sy = -1 if y0 > y1 else 1
   
  -    while True:
  -        points.append((x0, y0))
  -        if x0 == x1 and y0 == y1:
  -            break
  -        e2 = 2 * err
  -        if e2 > -dy:
  -            err -= dy
  -            x0 += sx
  -        if e2 < dx:
  -            err += dx
  -            y0 += sy
  +    if dx > dy:
  +        err = dx / 2.0
  +        while x != x1:
  +            points.append((x, y))
  +            err -= dy
  +            if err < 0:
  +                y += sy
  +                err += dx
  +            x += sx
  +    else:
  +        err = dy / 2.0
  +        while y != y1:
  +            points.append((x, y))
  +            err -= dx
  +            if err < 0:
  +                x += sx
  +                err += dy
  +            y += sy
  +
  +    points.append((x, y))
       return points
  
  </patch>
golden_diff: diff --git a/mkdocs/toc.py b/mkdocs/toc.py
  --- a/mkdocs/toc.py
  +++ b/mkdocs/toc.py
  @@ -32,6 +32,9 @@
       def __iter__(self):
           return iter(self.items)
   
  +    def __len__(self):
  +        return len(self.items)
  +
       def __str__(self):
           return ''.join([str(item) for item in self])
  
verification_info: {"golden_diff": "diff --git a/mkdocs/toc.py b/mkdocs/toc.py\n--- a/mkdocs/toc.py\n+++ b/mkdocs/toc.py\n@@ -32,6 +32,9 @@\n     def __iter__(self):\n         return iter(self.items)\n \n+    def __len__(self):\n+        return len(self.items)\n+\n     def __str__(self):\n         return ''.join([str(item) for item in self])\n", "issue": "Provide length of TableOfContents\nCurrently, you can only iter over `TableOfContents`. I would like to know the length of it.\n", "before_files": [{"content": "# coding: utf-8\n\n\"\"\"\nDeals with generating the per-page table of contents.\n\nFor the sake of simplicity we use an existing markdown extension to generate\nan HTML table of contents, and then parse that into the underlying data.\n\nThe steps we take to generate a table of contents are:\n\n* Pre-process the markdown, injecting a [TOC] marker.\n* Generate HTML from markdown.\n* Post-process the HTML, spliting the content and the table of contents.\n* Parse table of contents HTML into the underlying data structure.\n\"\"\"\n\nfrom __future__ import unicode_literals\n\ntry:                                    # pragma: no cover\n    from html.parser import HTMLParser  # noqa\nexcept ImportError:                     # pragma: no cover\n    from HTMLParser import HTMLParser   # noqa\n\n\nclass TableOfContents(object):\n    \"\"\"\n    Represents the table of contents for a given page.\n    \"\"\"\n    def __init__(self, html):\n        self.items = _parse_html_table_of_contents(html)\n\n    def __iter__(self):\n        return iter(self.items)\n\n    def __str__(self):\n        return ''.join([str(item) for item in self])\n\n\nclass AnchorLink(object):\n    \"\"\"\n    A single entry in the table of contents.\n    \"\"\"\n    def __init__(self, title, url):\n        self.title, self.url = title, url\n        self.children = []\n\n    def __str__(self):\n        return self.indent_print()\n\n    def indent_print(self, depth=0):\n        indent = '    ' * depth\n        ret = '%s%s - %s\\n' % (indent, self.title, self.url)\n        for item in self.children:\n            ret += item.indent_print(depth + 1)\n        return ret\n\n\nclass TOCParser(HTMLParser):\n\n    def __init__(self):\n        HTMLParser.__init__(self)\n        self.links = []\n\n        self.in_anchor = False\n        self.attrs = None\n        self.title = ''\n\n        # Prior to Python3.4 no convert_charrefs keyword existed.\n        # However, in Python3.5 the default was changed to True.\n        # We need the False behavior in all versions but can only\n        # set it if it exists.\n        if hasattr(self, 'convert_charrefs'):\n            self.convert_charrefs = False\n\n    def handle_starttag(self, tag, attrs):\n\n        if not self.in_anchor:\n            if tag == 'a':\n                self.in_anchor = True\n                self.attrs = dict(attrs)\n\n    def handle_endtag(self, tag):\n        if tag == 'a':\n            self.in_anchor = False\n\n    def handle_data(self, data):\n\n        if self.in_anchor:\n            self.title += data\n\n    def handle_charref(self, ref):\n        self.handle_entityref(\"#\" + ref)\n\n    def handle_entityref(self, ref):\n        self.handle_data(\"&%s;\" % ref)\n\n\ndef _parse_html_table_of_contents(html):\n    \"\"\"\n    Given a table of contents string that has been automatically generated by\n    the markdown library, parse it into a tree of AnchorLink instances.\n\n    Returns a list of all the parent AnchorLink instances.\n    \"\"\"\n    lines = html.splitlines()[2:-2]\n    parents = []\n    ret = []\n    for line in lines:\n        parser = TOCParser()\n        parser.feed(line)\n        if parser.title:\n            try:\n                href = parser.attrs['href']\n            except KeyError:\n                continue\n            title = parser.title\n            nav = AnchorLink(title, href)\n            # Add the item to its parent if required.  If it is a topmost\n            # item then instead append it to our return value.\n            if parents:\n                parents[-1].children.append(nav)\n            else:\n                ret.append(nav)\n            # If this item has children, store it as the current parent\n            if line.endswith('<ul>'):\n                parents.append(nav)\n        elif line.startswith('</ul>'):\n            if parents:\n                parents.pop()\n\n    # For the table of contents, always mark the first element as active\n    if ret:\n        ret[0].active = True\n\n    return ret\n", "path": "mkdocs/toc.py"}]}