comparison roundup/scripts/roundup_server.py @ 5395:23b8e6067f7c

Python 3 preparation: update calls to dict methods. Tool-assisted patch. Changes of iterkeys / itervalues / iteritems to keys / values / items are fully automated, but may make things less efficient in Python 2. Automated tools want to add list() around many calls to keys / values / items, but I thought most such list() additions were unnecessary because it seemed the result of keys / values / items was just iterated over while the set of dict keys remained unchanged, rather than used in a way requiring an actual list, or used while the set of keys in the dict could change. It's quite possible I missed some cases where list() was really needed, or left in some unnecessary list() calls. In cases where list() was only needed because the resulting list was then sorted in-place, I changed the code to use calls to sorted().
author Joseph Myers <jsm@polyomino.org.uk>
date Tue, 24 Jul 2018 23:04:42 +0000
parents fc97f1f4a7e3
children 99667a0cbd2d
comparison
equal deleted inserted replaced
5394:c26d88ec071e 5395:23b8e6067f7c
243 do_GET = do_POST = do_HEAD = run_cgi 243 do_GET = do_POST = do_HEAD = run_cgi
244 244
245 def index(self): 245 def index(self):
246 ''' Print up an index of the available trackers 246 ''' Print up an index of the available trackers
247 ''' 247 '''
248 keys = self.TRACKER_HOMES.keys() 248 keys = list(self.TRACKER_HOMES.keys())
249 if len(keys) == 1: 249 if len(keys) == 1:
250 self.send_response(302) 250 self.send_response(302)
251 self.send_header('Location', urllib.quote(keys[0]) + '/index') 251 self.send_header('Location', urllib.quote(keys[0]) + '/index')
252 self.end_headers() 252 self.end_headers()
253 else: 253 else:
621 # trackers must be specified on the command line. 621 # trackers must be specified on the command line.
622 if not config.has_section("trackers"): 622 if not config.has_section("trackers"):
623 return 623 return
624 # config defaults appear in all sections. 624 # config defaults appear in all sections.
625 # filter them out. 625 # filter them out.
626 defaults = config.defaults().keys() 626 defaults = list(config.defaults().keys())
627 for name in config.options("trackers"): 627 for name in config.options("trackers"):
628 if name not in defaults: 628 if name not in defaults:
629 self.add_option(TrackerHomeOption(self, "trackers", name)) 629 self.add_option(TrackerHomeOption(self, "trackers", name))
630 630
631 def getopt(self, args, short_options="", long_options=(), 631 def getopt(self, args, short_options="", long_options=(),

Roundup Issue Tracker: http://roundup-tracker.org/