Skip to content

Commit

Permalink
Python compat - portable way of raising exceptions
Browse files Browse the repository at this point in the history
Differential Revision: https://reviews.llvm.org/D56256

llvm-svn: 350311
  • Loading branch information
serge-sans-paille-qb committed Jan 3, 2019
1 parent 7d0174c commit beb6fee
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions llvm/test/tools/llvm-readobj/Inputs/relocs.py
Expand Up @@ -44,17 +44,17 @@ def __init__(self, name, bases = (), attributes = {}):

# Not supported (Enums are immutable).
def __setattr__(self, name, value):
raise NotSupportedException, self.__setattr__
raise NotSupportedException(self.__setattr__)

# Not supported (Enums are immutable).
def __delattr__(self, name):
raise NotSupportedException, self.__delattr__
raise NotSupportedException(self.__delattr__)

# Gets the enum symbol for the specified value.
def __getitem__(self, value):
symbol = self._map.get(value)
if symbol is None:
raise KeyError, value
raise KeyError(value)
return symbol

# Gets the enum symbol for the specified value or none.
Expand All @@ -64,11 +64,11 @@ def lookup(self, value):

# Not supported (Enums are immutable).
def __setitem__(self, value, symbol):
raise NotSupportedException, self.__setitem__
raise NotSupportedException(self.__setitem__)

# Not supported (Enums are immutable).
def __delitem__(self, value):
raise NotSupportedException, self.__delitem__
raise NotSupportedException(self.__delitem__)

def entries(self):
# sort by (value, name)
Expand Down Expand Up @@ -101,7 +101,7 @@ def seek(self, pos):
def read(self, N):
data = self.file.read(N)
if len(data) != N:
raise ValueError, "Out of data!"
raise ValueError("Out of data!")
return data

def int8(self):
Expand Down Expand Up @@ -267,15 +267,15 @@ def patchElf(path, relocs):
elif fileclass == 2:
f.is64Bit = True
else:
raise ValueError, "Unknown file class %x" % fileclass
raise ValueError("Unknown file class %x" % fileclass)

byteordering = f.uint8()
if byteordering == 1:
f.isLSB = True
elif byteordering == 2:
f.isLSB = False
else:
raise ValueError, "Unknown byte ordering %x" % byteordering
raise ValueError("Unknown byte ordering %x" % byteordering)

f.seek(18)
e_machine = f.uint16()
Expand Down Expand Up @@ -376,7 +376,7 @@ def patchMacho(filename, relocs):
elif magic == '\xCF\xFA\xED\xFE':
f.isLSB, f.is64Bit = True, True
else:
raise ValueError,"Not a Mach-O object file: %r (bad magic)" % path
raise ValueError("Not a Mach-O object file: %r (bad magic)" % path)

cputype = f.uint32()
cpusubtype = f.uint32()
Expand All @@ -393,8 +393,8 @@ def patchMacho(filename, relocs):
patchMachoLoadCommand(f, relocs)

if f.tell() - start != loadCommandsSize:
raise ValueError,"%s: warning: invalid load commands size: %r" % (
sys.argv[0], loadCommandsSize)
raise ValueError("%s: warning: invalid load commands size: %r" % (
sys.argv[0], loadCommandsSize))

def patchMachoLoadCommand(f, relocs):
start = f.tell()
Expand All @@ -409,8 +409,8 @@ def patchMachoLoadCommand(f, relocs):
f.read(cmdSize - 8)

if f.tell() - start != cmdSize:
raise ValueError,"%s: warning: invalid load command size: %r" % (
sys.argv[0], cmdSize)
raise ValueError("%s: warning: invalid load command size: %r" % (
sys.argv[0], cmdSize))

def patchMachoSegmentLoadCommand(f, relocs):
segment_name = f.read(16)
Expand Down

0 comments on commit beb6fee

Please sign in to comment.