Fix pep8 on Python3.5

This patch is fixing the pep8 warning messages when running "tox -epep8"
with the python3.5 interpreter (the default on some distros, e.g Arch
Linux).

The method file_open() from common/utils.py was removed because it
wasn't being used anywhere and was violating pep8 by using file() which
is only present in python2.

Change-Id: Ie9356a870ea7b271aa44db57accba02f52b3e948
Closes-Bug: #1617947
This commit is contained in:
Lucas Alvares Gomes 2016-08-29 10:40:36 +01:00
parent 9110e07a5f
commit 55410888de
5 changed files with 6 additions and 21 deletions

View File

@ -80,7 +80,7 @@ def main():
parser.add_argument('--disk-format', default='qcow2',
help='Disk format to use.')
args = parser.parse_args()
with file(templatedir + '/vm.xml', 'rb') as f:
with open(templatedir + '/vm.xml', 'rb') as f:
source_template = f.read()
params = {
'name': args.name,

View File

@ -78,13 +78,13 @@ class IronicException(Exception):
def __str__(self):
"""Encode to utf-8 then wsme api can consume it as well."""
if not six.PY3:
return unicode(self.args[0]).encode('utf-8')
return six.text_type(self.args[0]).encode('utf-8')
return self.args[0]
def __unicode__(self):
"""Return a unicode representation of the exception message."""
return unicode(self.args[0])
return six.text_type(self.args[0])
class NotAuthorized(IronicException):

View File

@ -372,18 +372,6 @@ def read_cached_file(filename, cache_info, reload_func=None):
return cache_info['data']
def file_open(*args, **kwargs):
"""Open file
see built-in file() documentation for more details
Note: The reason this is kept in a separate module is to easily
be able to provide a stub module that doesn't alter system
state at all (for unit tests)
"""
return file(*args, **kwargs)
def _get_hash_object(hash_algo_name):
"""Create a hash object based on given algorithm.

View File

@ -285,9 +285,8 @@ class TestJsonType(base.TestCase):
def test_apimultitype_tostring(self):
vts = str(types.jsontype)
self.assertIn(str(wtypes.text), vts)
self.assertIn(str(int), vts)
if six.PY2:
self.assertIn(str(long), vts)
for int_type in six.integer_types:
self.assertIn(str(int_type), vts)
self.assertIn(str(float), vts)
self.assertIn(str(types.BooleanType), vts)
self.assertIn(str(list), vts)

View File

@ -23,8 +23,6 @@ class TestIronicException(base.TestCase):
expected = b'\xc3\xa9\xe0\xaf\xb2\xe0\xbe\x84'
if six.PY3:
expected = expected.decode('utf-8')
message = chr(233) + chr(0x0bf2) + chr(3972)
else:
message = unichr(233) + unichr(0x0bf2) + unichr(3972)
message = six.unichr(233) + six.unichr(0x0bf2) + six.unichr(3972)
exc = exception.IronicException(message)
self.assertEqual(expected, exc.__str__())