Make the owners code work with python3

When generating electorate rolls under python3 we get the following:
 Traceback (most recent call last):
   File ".tox/venv/bin/generate-rolls", line 10, in <module>
     sys.exit(main())
   File "/home/tony/projects/openstack/openstack/election/openstack_election/cmds/generate_rolls.py", line 84, in main
     owners.main(options)
   File "/home/tony/projects/openstack/openstack/election/openstack_election/owners.py", line 532, in main
     normalized_project = normalize_project(project)
   File "/home/tony/projects/openstack/openstack/election/openstack_election/owners.py", line 60, in normalize_project
     return project.translate(maketrans(' -', '__')).lower()
 TypeError: a bytes-like object is required, not 'str'

Remove the python2 compat code and just use str.maketrans() always.

Change-Id: I12e351886d3e431144eeeb3a0efbd94dd0552946
This commit is contained in:
Tony Breeds 2018-09-06 14:33:53 +10:00
parent 60fb423adf
commit da1faab51b
1 changed files with 1 additions and 6 deletions

View File

@ -27,11 +27,6 @@ import yaml
from openstack_election import utils
try:
from string import maketrans
except ImportError: # Python3
maketrans = bytes.maketrans
def dumper(data, stream):
"""Convenience wrapper to consistently set YAML formatting"""
@ -57,7 +52,7 @@ def normalize_project(project):
Replace spaces and hyphens with underscores in project teams
and then lower-case them, for more convenient filenames
"""
return project.translate(maketrans(' -', '__')).lower()
return project.translate(str.maketrans(' -', '__')).lower()
def date_merged(change, after=None, before=None):