prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  Tracker for `RolesFromDomain`
  This is to track the implementation of `RolesFromDomain`, which implements role setting depending on the email domain of the user.
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `master/buildbot/www/authz/roles.py`
  Content:
  ```
  1 # This file is part of Buildbot.  Buildbot is free software: you can
  2 # redistribute it and/or modify it under the terms of the GNU General Public
  3 # License as published by the Free Software Foundation, version 2.
  4 #
  5 # This program is distributed in the hope that it will be useful, but WITHOUT
  6 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  7 # FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
  8 # details.
  9 #
  10 # You should have received a copy of the GNU General Public License along with
  11 # this program; if not, write to the Free Software Foundation, Inc., 51
  12 # Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  13 #
  14 # Copyright Buildbot Team Members
  15 
  16 from __future__ import absolute_import
  17 from __future__ import print_function
  18 from future.utils import iteritems
  19 
  20 
  21 class RolesFromBase(object):
  22 
  23     def __init__(self):
  24         pass
  25 
  26     def getRolesFromUser(self, userDetails):
  27         return []
  28 
  29     def setAuthz(self, authz):
  30         self.authz = authz
  31         self.master = authz.master
  32 
  33 
  34 class RolesFromGroups(RolesFromBase):
  35 
  36     def __init__(self, groupPrefix=""):
  37         RolesFromBase.__init__(self)
  38         self.groupPrefix = groupPrefix
  39 
  40     def getRolesFromUser(self, userDetails):
  41         roles = []
  42         if 'groups' in userDetails:
  43             for group in userDetails['groups']:
  44                 if group.startswith(self.groupPrefix):
  45                     roles.append(group[len(self.groupPrefix):])
  46         return roles
  47 
  48 
  49 class RolesFromEmails(RolesFromBase):
  50 
  51     def __init__(self, **kwargs):
  52         RolesFromBase.__init__(self)
  53         self.roles = {}
  54         for role, emails in iteritems(kwargs):
  55             for email in emails:
  56                 self.roles.setdefault(email, []).append(role)
  57 
  58     def getRolesFromUser(self, userDetails):
  59         if 'email' in userDetails:
  60             return self.roles.get(userDetails['email'], [])
  61         return []
  62 
  63 
  64 class RolesFromOwner(RolesFromBase):
  65 
  66     def __init__(self, role):
  67         RolesFromBase.__init__(self)
  68         self.role = role
  69 
  70     def getRolesFromUser(self, userDetails, owner):
  71         if 'email' in userDetails:
  72             if userDetails['email'] == owner and owner is not None:
  73                 return [self.role]
  74         return []
  75 
  76 
  77 class RolesFromUsername(RolesFromBase):
  78     def __init__(self, roles, usernames):
  79         self.roles = roles
  80         if None in usernames:
  81             from buildbot import config
  82             config.error('Usernames cannot be None')
  83         self.usernames = usernames
  84 
  85     def getRolesFromUser(self, userDetails):
  86         if userDetails.get('username') in self.usernames:
  87             return self.roles
  88         return []
  89
  ```
  --- 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/master/buildbot/www/authz/roles.py b/master/buildbot/www/authz/roles.py
  --- a/master/buildbot/www/authz/roles.py
  +++ b/master/buildbot/www/authz/roles.py
  @@ -61,6 +61,24 @@
           return []
   
   
  +class RolesFromDomain(RolesFromEmails):
  +
  +    def __init__(self, **kwargs):
  +        RolesFromBase.__init__(self)
  +
  +        self.domain_roles = {}
  +        for role, domains in iteritems(kwargs):
  +            for domain in domains:
  +                self.domain_roles.setdefault(domain, []).append(role)
  +
  +    def getRolesFromUser(self, userDetails):
  +        if 'email' in userDetails:
  +            email = userDetails['email']
  +            edomain = email.split('@')[-1]
  +            return self.domain_roles.get(edomain, [])
  +        return []
  +
  +
   class RolesFromOwner(RolesFromBase):
   
       def __init__(self, role):
  
verification_info: {"golden_diff": "diff --git a/master/buildbot/www/authz/roles.py b/master/buildbot/www/authz/roles.py\n--- a/master/buildbot/www/authz/roles.py\n+++ b/master/buildbot/www/authz/roles.py\n@@ -61,6 +61,24 @@\n         return []\n \n \n+class RolesFromDomain(RolesFromEmails):\n+\n+    def __init__(self, **kwargs):\n+        RolesFromBase.__init__(self)\n+\n+        self.domain_roles = {}\n+        for role, domains in iteritems(kwargs):\n+            for domain in domains:\n+                self.domain_roles.setdefault(domain, []).append(role)\n+\n+    def getRolesFromUser(self, userDetails):\n+        if 'email' in userDetails:\n+            email = userDetails['email']\n+            edomain = email.split('@')[-1]\n+            return self.domain_roles.get(edomain, [])\n+        return []\n+\n+\n class RolesFromOwner(RolesFromBase):\n \n     def __init__(self, role):\n", "issue": "Tracker for `RolesFromDomain`\nThis is to track the implementation of `RolesFromDomain`, which implements role setting depending on the email domain of the user.\n", "before_files": [{"content": "# This file is part of Buildbot.  Buildbot is free software: you can\n# redistribute it and/or modify it under the terms of the GNU General Public\n# License as published by the Free Software Foundation, version 2.\n#\n# This program is distributed in the hope that it will be useful, but WITHOUT\n# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS\n# FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more\n# details.\n#\n# You should have received a copy of the GNU General Public License along with\n# this program; if not, write to the Free Software Foundation, Inc., 51\n# Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.\n#\n# Copyright Buildbot Team Members\n\nfrom __future__ import absolute_import\nfrom __future__ import print_function\nfrom future.utils import iteritems\n\n\nclass RolesFromBase(object):\n\n    def __init__(self):\n        pass\n\n    def getRolesFromUser(self, userDetails):\n        return []\n\n    def setAuthz(self, authz):\n        self.authz = authz\n        self.master = authz.master\n\n\nclass RolesFromGroups(RolesFromBase):\n\n    def __init__(self, groupPrefix=\"\"):\n        RolesFromBase.__init__(self)\n        self.groupPrefix = groupPrefix\n\n    def getRolesFromUser(self, userDetails):\n        roles = []\n        if 'groups' in userDetails:\n            for group in userDetails['groups']:\n                if group.startswith(self.groupPrefix):\n                    roles.append(group[len(self.groupPrefix):])\n        return roles\n\n\nclass RolesFromEmails(RolesFromBase):\n\n    def __init__(self, **kwargs):\n        RolesFromBase.__init__(self)\n        self.roles = {}\n        for role, emails in iteritems(kwargs):\n            for email in emails:\n                self.roles.setdefault(email, []).append(role)\n\n    def getRolesFromUser(self, userDetails):\n        if 'email' in userDetails:\n            return self.roles.get(userDetails['email'], [])\n        return []\n\n\nclass RolesFromOwner(RolesFromBase):\n\n    def __init__(self, role):\n        RolesFromBase.__init__(self)\n        self.role = role\n\n    def getRolesFromUser(self, userDetails, owner):\n        if 'email' in userDetails:\n            if userDetails['email'] == owner and owner is not None:\n                return [self.role]\n        return []\n\n\nclass RolesFromUsername(RolesFromBase):\n    def __init__(self, roles, usernames):\n        self.roles = roles\n        if None in usernames:\n            from buildbot import config\n            config.error('Usernames cannot be None')\n        self.usernames = usernames\n\n    def getRolesFromUser(self, userDetails):\n        if userDetails.get('username') in self.usernames:\n            return self.roles\n        return []\n", "path": "master/buildbot/www/authz/roles.py"}], "after_files": [{"content": "# This file is part of Buildbot.  Buildbot is free software: you can\n# redistribute it and/or modify it under the terms of the GNU General Public\n# License as published by the Free Software Foundation, version 2.\n#\n# This program is distributed in the hope that it will be useful, but WITHOUT\n# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS\n# FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more\n# details.\n#\n# You should have received a copy of the GNU General Public License along with\n# this program; if not, write to the Free Software Foundation, Inc., 51\n# Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.\n#\n# Copyright Buildbot Team Members\n\nfrom __future__ import absolute_import\nfrom __future__ import print_function\nfrom future.utils import iteritems\n\n\nclass RolesFromBase(object):\n\n    def __init__(self):\n        pass\n\n    def getRolesFromUser(self, userDetails):\n        return []\n\n    def setAuthz(self, authz):\n        self.authz = authz\n        self.master = authz.master\n\n\nclass RolesFromGroups(RolesFromBase):\n\n    def __init__(self, groupPrefix=\"\"):\n        RolesFromBase.__init__(self)\n        self.groupPrefix = groupPrefix\n\n    def getRolesFromUser(self, userDetails):\n        roles = []\n        if 'groups' in userDetails:\n            for group in userDetails['groups']:\n                if group.startswith(self.groupPrefix):\n                    roles.append(group[len(self.groupPrefix):])\n        return roles\n\n\nclass RolesFromEmails(RolesFromBase):\n\n    def __init__(self, **kwargs):\n        RolesFromBase.__init__(self)\n        self.roles = {}\n        for role, emails in iteritems(kwargs):\n            for email in emails:\n                self.roles.setdefault(email, []).append(role)\n\n    def getRolesFromUser(self, userDetails):\n        if 'email' in userDetails:\n            return self.roles.get(userDetails['email'], [])\n        return []\n\n\nclass RolesFromDomain(RolesFromEmails):\n\n    def __init__(self, **kwargs):\n        RolesFromBase.__init__(self)\n\n        self.domain_roles = {}\n        for role, domains in iteritems(kwargs):\n            for domain in domains:\n                self.domain_roles.setdefault(domain, []).append(role)\n\n    def getRolesFromUser(self, userDetails):\n        if 'email' in userDetails:\n            email = userDetails['email']\n            edomain = email.split('@')[-1]\n            return self.domain_roles.get(edomain, [])\n        return []\n\n\nclass RolesFromOwner(RolesFromBase):\n\n    def __init__(self, role):\n        RolesFromBase.__init__(self)\n        self.role = role\n\n    def getRolesFromUser(self, userDetails, owner):\n        if 'email' in userDetails:\n            if userDetails['email'] == owner and owner is not None:\n                return [self.role]\n        return []\n\n\nclass RolesFromUsername(RolesFromBase):\n    def __init__(self, roles, usernames):\n        self.roles = roles\n        if None in usernames:\n            from buildbot import config\n            config.error('Usernames cannot be None')\n        self.usernames = usernames\n\n    def getRolesFromUser(self, userDetails):\n        if userDetails.get('username') in self.usernames:\n            return self.roles\n        return []\n", "path": "master/buildbot/www/authz/roles.py"}]}