prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  AZ Legislator with the following id has an invalid phone number AZL000372
  State: AZ  (be sure to include in ticket title)
  
  This repository is for issues with state data, for feature requests, etc.
  please visit the contributor guide (see above message) to file the issue in the correct place.
  
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `openstates/az/legislators.py`
  Content:
  ```
  1 from billy.scrape import NoDataForPeriod
  2 from billy.scrape.legislators import LegislatorScraper, Legislator
  3 from lxml import html
  4 
  5 import re, datetime
  6 
  7 class AZLegislatorScraper(LegislatorScraper):
  8     jurisdiction = 'az'
  9     parties = {
  10         'R': 'Republican',
  11         'D': 'Democratic',
  12         'L': 'Libertarian',
  13         'I': 'Independent',
  14         'G': 'Green'
  15     }
  16 
  17     def get_party(self, abbr):
  18         return self.parties[abbr]
  19 
  20     def scrape(self, chamber, term):
  21         # TODO: old AZ scraper allowed old sessions, they seem to be gone?
  22         self.validate_term(term, latest_only=True)
  23 
  24         body = {'lower': 'H', 'upper': 'S'}[chamber]
  25         url = 'http://www.azleg.gov/MemberRoster/?body=' + body
  26         page = self.get(url).text
  27 
  28         # there is a bad comment closing tag on this page
  29         page = page.replace('--!>', '-->')
  30 
  31         root = html.fromstring(page)
  32 
  33         path = '//table//tr'
  34         roster = root.xpath(path)[1:]
  35         for row in roster:
  36             position = ''
  37             name, district, party, email, room, phone, = row.xpath('td')
  38 
  39             if email.attrib.get('class') == 'vacantmember':
  40                 continue  # Skip any vacant members.
  41 
  42             link = name.xpath('string(a/@href)')
  43             if len(name) == 1:
  44                 name = name.text_content().strip()
  45             else:
  46                 position = name.tail.strip()
  47                 name = name[0].text_content().strip()
  48             if '--' in name:
  49                 name = name.split('--')[0].strip()
  50 
  51             linkpage = self.get(link).text
  52             linkpage = linkpage.replace('--!>', '-->')
  53             linkroot = html.fromstring(linkpage)
  54             linkroot.make_links_absolute(link)
  55 
  56             photos = linkroot.xpath("//img[contains(@src, 'MemberPhoto')]")
  57 
  58             if len(photos) != 1:
  59                 self.warning('no photo on ' + link)
  60                 photo_url = ''
  61             else:
  62                 photo_url = photos[0].attrib['src']
  63 
  64             district = district.text_content()
  65             party = party.text_content().strip()
  66             email = email.text_content().strip()
  67 
  68             if email.startswith('Email: '):
  69                 email = email.replace('Email: ', '').lower() + '@azleg.gov'
  70             else:
  71                 email = ''
  72 
  73             party = self.get_party(party)
  74             room = room.text_content().strip()
  75             if chamber == 'lower':
  76                 address = "House of Representatives\n"
  77             else:
  78                 address = "Senate\n"
  79             address = address + "1700 West Washington\n Room " + room  \
  80                               + "\nPhoenix, AZ 85007"
  81 
  82             phone = phone.text_content().strip()
  83             if not phone.startswith('602'):
  84                 phone = "602-" + phone
  85 
  86             leg = Legislator(term, chamber, district, full_name=name,
  87                                 party=party, url=link,
  88                                 photo_url=photo_url)
  89 
  90             leg.add_office('capitol', 'Capitol Office', address=address,
  91                            phone=phone, email=email)
  92 
  93             if position:
  94                 leg.add_role( position, term, chamber=chamber,
  95                              district=district, party=party)
  96 
  97             leg.add_source(url)
  98 
  99             #Probably just get this from the committee scraper
  100             #self.scrape_member_page(link, session, chamber, leg)
  101             self.save_legislator(leg)
  102 
  103     def scrape_member_page(self, url, session, chamber, leg):
  104         html = self.get(url).text
  105         root = html.fromstring(html)
  106         #get the committee membership
  107         c = root.xpath('//td/div/strong[contains(text(), "Committee")]')
  108         for row in c.xpath('ancestor::table[1]')[1:]:
  109             name = row[0].text_content().strip()
  110             role = row[1].text_content().strip()
  111             leg.add_role(role, session, chamber=chamber, committee=name)
  112 
  113         leg.add_source(url)
  114
  ```
  --- END FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
golden_diff: diff --git a/openstates/az/legislators.py b/openstates/az/legislators.py
  --- a/openstates/az/legislators.py
  +++ b/openstates/az/legislators.py
  @@ -1,8 +1,7 @@
  -from billy.scrape import NoDataForPeriod
   from billy.scrape.legislators import LegislatorScraper, Legislator
   from lxml import html
  +import re
   
  -import re, datetime
   
   class AZLegislatorScraper(LegislatorScraper):
       jurisdiction = 'az'
  @@ -80,30 +79,30 @@
                                 + "\nPhoenix, AZ 85007"
   
               phone = phone.text_content().strip()
  -            if not phone.startswith('602'):
  +            if '602' not in re.findall(r'(\d+)', phone):
                   phone = "602-" + phone
   
               leg = Legislator(term, chamber, district, full_name=name,
  -                                party=party, url=link,
  -                                photo_url=photo_url)
  +                             party=party, url=link,
  +                             photo_url=photo_url)
   
               leg.add_office('capitol', 'Capitol Office', address=address,
                              phone=phone, email=email)
   
               if position:
  -                leg.add_role( position, term, chamber=chamber,
  +                leg.add_role(position, term, chamber=chamber,
                                district=district, party=party)
   
               leg.add_source(url)
   
  -            #Probably just get this from the committee scraper
  -            #self.scrape_member_page(link, session, chamber, leg)
  +            # Probably just get this from the committee scraper
  +            # self.scrape_member_page(link, session, chamber, leg)
               self.save_legislator(leg)
   
       def scrape_member_page(self, url, session, chamber, leg):
           html = self.get(url).text
           root = html.fromstring(html)
  -        #get the committee membership
  +        # get the committee membership
           c = root.xpath('//td/div/strong[contains(text(), "Committee")]')
           for row in c.xpath('ancestor::table[1]')[1:]:
               name = row[0].text_content().strip()
  
verification_info: {"golden_diff": "diff --git a/openstates/az/legislators.py b/openstates/az/legislators.py\n--- a/openstates/az/legislators.py\n+++ b/openstates/az/legislators.py\n@@ -1,8 +1,7 @@\n-from billy.scrape import NoDataForPeriod\n from billy.scrape.legislators import LegislatorScraper, Legislator\n from lxml import html\n+import re\n \n-import re, datetime\n \n class AZLegislatorScraper(LegislatorScraper):\n     jurisdiction = 'az'\n@@ -80,30 +79,30 @@\n                               + \"\\nPhoenix, AZ 85007\"\n \n             phone = phone.text_content().strip()\n-            if not phone.startswith('602'):\n+            if '602' not in re.findall(r'(\\d+)', phone):\n                 phone = \"602-\" + phone\n \n             leg = Legislator(term, chamber, district, full_name=name,\n-                                party=party, url=link,\n-                                photo_url=photo_url)\n+                             party=party, url=link,\n+                             photo_url=photo_url)\n \n             leg.add_office('capitol', 'Capitol Office', address=address,\n                            phone=phone, email=email)\n \n             if position:\n-                leg.add_role( position, term, chamber=chamber,\n+                leg.add_role(position, term, chamber=chamber,\n                              district=district, party=party)\n \n             leg.add_source(url)\n \n-            #Probably just get this from the committee scraper\n-            #self.scrape_member_page(link, session, chamber, leg)\n+            # Probably just get this from the committee scraper\n+            # self.scrape_member_page(link, session, chamber, leg)\n             self.save_legislator(leg)\n \n     def scrape_member_page(self, url, session, chamber, leg):\n         html = self.get(url).text\n         root = html.fromstring(html)\n-        #get the committee membership\n+        # get the committee membership\n         c = root.xpath('//td/div/strong[contains(text(), \"Committee\")]')\n         for row in c.xpath('ancestor::table[1]')[1:]:\n             name = row[0].text_content().strip()\n", "issue": "AZ Legislator with the following id has an invalid phone number AZL000372\nState: AZ  (be sure to include in ticket title)\r\n\r\nThis repository is for issues with state data, for feature requests, etc.\r\nplease visit the contributor guide (see above message) to file the issue in the correct place.\r\n\n", "before_files": [{"content": "from billy.scrape import NoDataForPeriod\nfrom billy.scrape.legislators import LegislatorScraper, Legislator\nfrom lxml import html\n\nimport re, datetime\n\nclass AZLegislatorScraper(LegislatorScraper):\n    jurisdiction = 'az'\n    parties = {\n        'R': 'Republican',\n        'D': 'Democratic',\n        'L': 'Libertarian',\n        'I': 'Independent',\n        'G': 'Green'\n    }\n\n    def get_party(self, abbr):\n        return self.parties[abbr]\n\n    def scrape(self, chamber, term):\n        # TODO: old AZ scraper allowed old sessions, they seem to be gone?\n        self.validate_term(term, latest_only=True)\n\n        body = {'lower': 'H', 'upper': 'S'}[chamber]\n        url = 'http://www.azleg.gov/MemberRoster/?body=' + body\n        page = self.get(url).text\n\n        # there is a bad comment closing tag on this page\n        page = page.replace('--!>', '-->')\n\n        root = html.fromstring(page)\n\n        path = '//table//tr'\n        roster = root.xpath(path)[1:]\n        for row in roster:\n            position = ''\n            name, district, party, email, room, phone, = row.xpath('td')\n\n            if email.attrib.get('class') == 'vacantmember':\n                continue  # Skip any vacant members.\n\n            link = name.xpath('string(a/@href)')\n            if len(name) == 1:\n                name = name.text_content().strip()\n            else:\n                position = name.tail.strip()\n                name = name[0].text_content().strip()\n            if '--' in name:\n                name = name.split('--')[0].strip()\n\n            linkpage = self.get(link).text\n            linkpage = linkpage.replace('--!>', '-->')\n            linkroot = html.fromstring(linkpage)\n            linkroot.make_links_absolute(link)\n\n            photos = linkroot.xpath(\"//img[contains(@src, 'MemberPhoto')]\")\n\n            if len(photos) != 1:\n                self.warning('no photo on ' + link)\n                photo_url = ''\n            else:\n                photo_url = photos[0].attrib['src']\n\n            district = district.text_content()\n            party = party.text_content().strip()\n            email = email.text_content().strip()\n\n            if email.startswith('Email: '):\n                email = email.replace('Email: ', '').lower() + '@azleg.gov'\n            else:\n                email = ''\n\n            party = self.get_party(party)\n            room = room.text_content().strip()\n            if chamber == 'lower':\n                address = \"House of Representatives\\n\"\n            else:\n                address = \"Senate\\n\"\n            address = address + \"1700 West Washington\\n Room \" + room  \\\n                              + \"\\nPhoenix, AZ 85007\"\n\n            phone = phone.text_content().strip()\n            if not phone.startswith('602'):\n                phone = \"602-\" + phone\n\n            leg = Legislator(term, chamber, district, full_name=name,\n                                party=party, url=link,\n                                photo_url=photo_url)\n\n            leg.add_office('capitol', 'Capitol Office', address=address,\n                           phone=phone, email=email)\n\n            if position:\n                leg.add_role( position, term, chamber=chamber,\n                             district=district, party=party)\n\n            leg.add_source(url)\n\n            #Probably just get this from the committee scraper\n            #self.scrape_member_page(link, session, chamber, leg)\n            self.save_legislator(leg)\n\n    def scrape_member_page(self, url, session, chamber, leg):\n        html = self.get(url).text\n        root = html.fromstring(html)\n        #get the committee membership\n        c = root.xpath('//td/div/strong[contains(text(), \"Committee\")]')\n        for row in c.xpath('ancestor::table[1]')[1:]:\n            name = row[0].text_content().strip()\n            role = row[1].text_content().strip()\n            leg.add_role(role, session, chamber=chamber, committee=name)\n\n        leg.add_source(url)\n", "path": "openstates/az/legislators.py"}], "after_files": [{"content": "from billy.scrape.legislators import LegislatorScraper, Legislator\nfrom lxml import html\nimport re\n\n\nclass AZLegislatorScraper(LegislatorScraper):\n    jurisdiction = 'az'\n    parties = {\n        'R': 'Republican',\n        'D': 'Democratic',\n        'L': 'Libertarian',\n        'I': 'Independent',\n        'G': 'Green'\n    }\n\n    def get_party(self, abbr):\n        return self.parties[abbr]\n\n    def scrape(self, chamber, term):\n        # TODO: old AZ scraper allowed old sessions, they seem to be gone?\n        self.validate_term(term, latest_only=True)\n\n        body = {'lower': 'H', 'upper': 'S'}[chamber]\n        url = 'http://www.azleg.gov/MemberRoster/?body=' + body\n        page = self.get(url).text\n\n        # there is a bad comment closing tag on this page\n        page = page.replace('--!>', '-->')\n\n        root = html.fromstring(page)\n\n        path = '//table//tr'\n        roster = root.xpath(path)[1:]\n        for row in roster:\n            position = ''\n            name, district, party, email, room, phone, = row.xpath('td')\n\n            if email.attrib.get('class') == 'vacantmember':\n                continue  # Skip any vacant members.\n\n            link = name.xpath('string(a/@href)')\n            if len(name) == 1:\n                name = name.text_content().strip()\n            else:\n                position = name.tail.strip()\n                name = name[0].text_content().strip()\n            if '--' in name:\n                name = name.split('--')[0].strip()\n\n            linkpage = self.get(link).text\n            linkpage = linkpage.replace('--!>', '-->')\n            linkroot = html.fromstring(linkpage)\n            linkroot.make_links_absolute(link)\n\n            photos = linkroot.xpath(\"//img[contains(@src, 'MemberPhoto')]\")\n\n            if len(photos) != 1:\n                self.warning('no photo on ' + link)\n                photo_url = ''\n            else:\n                photo_url = photos[0].attrib['src']\n\n            district = district.text_content()\n            party = party.text_content().strip()\n            email = email.text_content().strip()\n\n            if email.startswith('Email: '):\n                email = email.replace('Email: ', '').lower() + '@azleg.gov'\n            else:\n                email = ''\n\n            party = self.get_party(party)\n            room = room.text_content().strip()\n            if chamber == 'lower':\n                address = \"House of Representatives\\n\"\n            else:\n                address = \"Senate\\n\"\n            address = address + \"1700 West Washington\\n Room \" + room  \\\n                              + \"\\nPhoenix, AZ 85007\"\n\n            phone = phone.text_content().strip()\n            if '602' not in re.findall(r'(\\d+)', phone):\n                phone = \"602-\" + phone\n\n            leg = Legislator(term, chamber, district, full_name=name,\n                             party=party, url=link,\n                             photo_url=photo_url)\n\n            leg.add_office('capitol', 'Capitol Office', address=address,\n                           phone=phone, email=email)\n\n            if position:\n                leg.add_role(position, term, chamber=chamber,\n                             district=district, party=party)\n\n            leg.add_source(url)\n\n            # Probably just get this from the committee scraper\n            # self.scrape_member_page(link, session, chamber, leg)\n            self.save_legislator(leg)\n\n    def scrape_member_page(self, url, session, chamber, leg):\n        html = self.get(url).text\n        root = html.fromstring(html)\n        # get the committee membership\n        c = root.xpath('//td/div/strong[contains(text(), \"Committee\")]')\n        for row in c.xpath('ancestor::table[1]')[1:]:\n            name = row[0].text_content().strip()\n            role = row[1].text_content().strip()\n            leg.add_role(role, session, chamber=chamber, committee=name)\n\n        leg.add_source(url)\n", "path": "openstates/az/legislators.py"}]}