prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  TN: 109th Session, Legislators, Upper - Senator name extraction fails for district 19
  Trying to run the scraper locally, I encountered the following exception for TN's [19th senate district in the 109th general assembly](http://www.capitol.tn.gov/senate/archives/109GA/members/s19.html) (Sen. Thelma Hale):
  
  ```
  File "/usr/local/bin/billy-update", line 9, in <module>
      load_entry_point('billy==1.8.4', 'console_scripts', 'billy-update')()
    File "/opt/sunlightfoundation.com/billy/billy/bin/update.py", line 377, in main
      run_record += _run_scraper(stype, args, metadata)
    File "/opt/sunlightfoundation.com/billy/billy/bin/update.py", line 101, in _run_scraper
      scraper.scrape(chamber, time)
    File "/srv/openstates-web/openstates/tn/legislators.py", line 81, in scrape
      name = member_page.xpath('//div[@id="membertitle"]/h2/text()')[0]
  IndexError: list index out of range
  ```
  
  </issue>
  <code>
  [start of openstates/tn/legislators.py]
  1 import HTMLParser
  2 
  3 from billy.scrape.legislators import LegislatorScraper, Legislator
  4 import lxml.html
  5 from scrapelib import HTTPError
  6 from openstates.utils import LXMLMixin
  7 
  8 class TNLegislatorScraper(LegislatorScraper, LXMLMixin):
  9     jurisdiction = 'tn'
  10 
  11     def scrape(self, chamber, term):
  12         self.validate_term(term, latest_only=False)
  13         root_url = 'http://www.capitol.tn.gov/'
  14         parties = {'D': 'Democratic', 'R': 'Republican',
  15                    'CCR': 'Carter County Republican',
  16                    'I': 'Independent'}
  17 
  18         #testing for chamber
  19         if chamber == 'upper':
  20             url_chamber_name = 'senate'
  21             abbr = 's'
  22         else:
  23             url_chamber_name = 'house'
  24             abbr = 'h'
  25         if term != self.metadata["terms"][-1]["sessions"][0]:
  26             chamber_url = root_url + url_chamber_name
  27             chamber_url += '/archives/' + term + 'GA/Members/index.html'
  28         else:
  29             chamber_url = root_url + url_chamber_name + '/members/'
  30 
  31         page = self.lxmlize(chamber_url)
  32 
  33         for row in page.xpath("//tr"):
  34 
  35             # Skip any a header row.
  36             if set(child.tag for child in row) == set(['th']):
  37                 continue
  38 
  39             vacancy_check = row.xpath('./td/text()')[1]
  40             if 'Vacant' in vacancy_check:
  41                 self.logger.warning("Vacant Seat")
  42                 continue
  43 
  44             partyInit = row.xpath('td[3]')[0].text.split()[0]
  45             party = parties[partyInit]
  46             district = row.xpath('td[5]/a')[0].text.split()[1]
  47             address = row.xpath('td[6]')[0].text_content()
  48             # 301 6th Avenue North Suite
  49             address = address.replace('LP',
  50                               'Legislative Plaza\nNashville, TN 37243')
  51             address = address.replace('WMB',
  52                               'War Memorial Building\nNashville, TN 37243')
  53             address = '301 6th Avenue North\nSuite ' + address
  54             phone = [
  55                     x.strip() for x in
  56                     row.xpath('td[7]//text()')
  57                     if x.strip()
  58                     ][0]
  59 
  60             email = HTMLParser.HTMLParser().unescape(
  61                     row.xpath('td[1]/a/@href')[0][len("mailto:"): ])
  62             member_url = (root_url + url_chamber_name + '/members/' + abbr +
  63                 district + '.html')
  64             member_photo_url = (root_url + url_chamber_name +
  65                 '/members/images/' + abbr + district + '.jpg')
  66 
  67             try:
  68                 member_page = self.get(member_url, allow_redirects=False).text
  69             except (TypeError, HTTPError):
  70                 try:
  71                     member_url = row.xpath('td[2]/a/@href')[0]
  72                     member_page = self.get(member_url, allow_redirects=False).text
  73                 except (TypeError, HTTPError):
  74                     self.logger.warning("Valid member page does not exist.")
  75                     continue
  76 
  77             member_page = lxml.html.fromstring(member_page)
  78             try:
  79                 name = member_page.xpath('body/div/div/h1/text()')[0]
  80             except IndexError:
  81                 name = member_page.xpath('//div[@id="membertitle"]/h2/text()')[0]
  82             
  83             if 'Speaker' in name:
  84                 full_name = name[8:len(name)]
  85             elif 'Lt.' in name:
  86                 full_name = name[13:len(name)]
  87             elif abbr == 'h':
  88                 full_name = name[len("Representative "): len(name)]
  89             else:
  90                 full_name = name[8:len(name)]
  91 
  92             leg = Legislator(term, chamber, district, full_name.strip(),
  93                              party=party, url=member_url,
  94                              photo_url=member_photo_url)
  95             leg.add_source(chamber_url)
  96             leg.add_source(member_url)
  97 
  98             # TODO: add district address from this page
  99 
  100             leg.add_office('capitol', 'Nashville Address',
  101                            address=address, phone=phone, email=email)
  102 
  103             self.save_legislator(leg)
  104
  [end of openstates/tn/legislators.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/openstates/tn/legislators.py b/openstates/tn/legislators.py
  --- a/openstates/tn/legislators.py
  +++ b/openstates/tn/legislators.py
  @@ -76,7 +76,7 @@
   
               member_page = lxml.html.fromstring(member_page)
               try:
  -                name = member_page.xpath('body/div/div/h1/text()')[0]
  +                name = member_page.xpath('//div/div/h1/text()')[0]
               except IndexError:
                   name = member_page.xpath('//div[@id="membertitle"]/h2/text()')[0]
  
verification_info: {"golden_diff": "diff --git a/openstates/tn/legislators.py b/openstates/tn/legislators.py\n--- a/openstates/tn/legislators.py\n+++ b/openstates/tn/legislators.py\n@@ -76,7 +76,7 @@\n \n             member_page = lxml.html.fromstring(member_page)\n             try:\n-                name = member_page.xpath('body/div/div/h1/text()')[0]\n+                name = member_page.xpath('//div/div/h1/text()')[0]\n             except IndexError:\n                 name = member_page.xpath('//div[@id=\"membertitle\"]/h2/text()')[0]\n", "issue": "TN: 109th Session, Legislators, Upper - Senator name extraction fails for district 19\nTrying to run the scraper locally, I encountered the following exception for TN's [19th senate district in the 109th general assembly](http://www.capitol.tn.gov/senate/archives/109GA/members/s19.html) (Sen. Thelma Hale):\r\n\r\n```\r\nFile \"/usr/local/bin/billy-update\", line 9, in <module>\r\n    load_entry_point('billy==1.8.4', 'console_scripts', 'billy-update')()\r\n  File \"/opt/sunlightfoundation.com/billy/billy/bin/update.py\", line 377, in main\r\n    run_record += _run_scraper(stype, args, metadata)\r\n  File \"/opt/sunlightfoundation.com/billy/billy/bin/update.py\", line 101, in _run_scraper\r\n    scraper.scrape(chamber, time)\r\n  File \"/srv/openstates-web/openstates/tn/legislators.py\", line 81, in scrape\r\n    name = member_page.xpath('//div[@id=\"membertitle\"]/h2/text()')[0]\r\nIndexError: list index out of range\r\n```\n", "before_files": [{"content": "import HTMLParser\n\nfrom billy.scrape.legislators import LegislatorScraper, Legislator\nimport lxml.html\nfrom scrapelib import HTTPError\nfrom openstates.utils import LXMLMixin\n\nclass TNLegislatorScraper(LegislatorScraper, LXMLMixin):\n    jurisdiction = 'tn'\n\n    def scrape(self, chamber, term):\n        self.validate_term(term, latest_only=False)\n        root_url = 'http://www.capitol.tn.gov/'\n        parties = {'D': 'Democratic', 'R': 'Republican',\n                   'CCR': 'Carter County Republican',\n                   'I': 'Independent'}\n\n        #testing for chamber\n        if chamber == 'upper':\n            url_chamber_name = 'senate'\n            abbr = 's'\n        else:\n            url_chamber_name = 'house'\n            abbr = 'h'\n        if term != self.metadata[\"terms\"][-1][\"sessions\"][0]:\n            chamber_url = root_url + url_chamber_name\n            chamber_url += '/archives/' + term + 'GA/Members/index.html'\n        else:\n            chamber_url = root_url + url_chamber_name + '/members/'\n\n        page = self.lxmlize(chamber_url)\n\n        for row in page.xpath(\"//tr\"):\n\n            # Skip any a header row.\n            if set(child.tag for child in row) == set(['th']):\n                continue\n\n            vacancy_check = row.xpath('./td/text()')[1]\n            if 'Vacant' in vacancy_check:\n                self.logger.warning(\"Vacant Seat\")\n                continue\n\n            partyInit = row.xpath('td[3]')[0].text.split()[0]\n            party = parties[partyInit]\n            district = row.xpath('td[5]/a')[0].text.split()[1]\n            address = row.xpath('td[6]')[0].text_content()\n            # 301 6th Avenue North Suite\n            address = address.replace('LP',\n                              'Legislative Plaza\\nNashville, TN 37243')\n            address = address.replace('WMB',\n                              'War Memorial Building\\nNashville, TN 37243')\n            address = '301 6th Avenue North\\nSuite ' + address\n            phone = [\n                    x.strip() for x in\n                    row.xpath('td[7]//text()')\n                    if x.strip()\n                    ][0]\n\n            email = HTMLParser.HTMLParser().unescape(\n                    row.xpath('td[1]/a/@href')[0][len(\"mailto:\"): ])\n            member_url = (root_url + url_chamber_name + '/members/' + abbr +\n                district + '.html')\n            member_photo_url = (root_url + url_chamber_name +\n                '/members/images/' + abbr + district + '.jpg')\n\n            try:\n                member_page = self.get(member_url, allow_redirects=False).text\n            except (TypeError, HTTPError):\n                try:\n                    member_url = row.xpath('td[2]/a/@href')[0]\n                    member_page = self.get(member_url, allow_redirects=False).text\n                except (TypeError, HTTPError):\n                    self.logger.warning(\"Valid member page does not exist.\")\n                    continue\n\n            member_page = lxml.html.fromstring(member_page)\n            try:\n                name = member_page.xpath('body/div/div/h1/text()')[0]\n            except IndexError:\n                name = member_page.xpath('//div[@id=\"membertitle\"]/h2/text()')[0]\n            \n            if 'Speaker' in name:\n                full_name = name[8:len(name)]\n            elif 'Lt.' in name:\n                full_name = name[13:len(name)]\n            elif abbr == 'h':\n                full_name = name[len(\"Representative \"): len(name)]\n            else:\n                full_name = name[8:len(name)]\n\n            leg = Legislator(term, chamber, district, full_name.strip(),\n                             party=party, url=member_url,\n                             photo_url=member_photo_url)\n            leg.add_source(chamber_url)\n            leg.add_source(member_url)\n\n            # TODO: add district address from this page\n\n            leg.add_office('capitol', 'Nashville Address',\n                           address=address, phone=phone, email=email)\n\n            self.save_legislator(leg)\n", "path": "openstates/tn/legislators.py"}]}