def readFile(filename, offset, length):
 absoffset = abs(offset)
 abslength = abs(length)
 try:
  with open(filename, 'rb') as f:
   if (absoffset != offset):
    if length:
     raise ValueError('BAD_ARGUMENTS')
    f.seek(0, 2)
    sz = f.tell()
    pos = int((sz - absoffset))
    if (pos < 0):
     pos = 0
    f.seek(pos)
    data = f.read(absoffset)
   else:
    if (abslength != length):
     raise ValueError('BAD_ARGUMENTS')
    if (length == 0):
     f.seek(offset)
     data = f.read()
    else:
     f.seek(offset)
     data = f.read(length)
 except (OSError, IOError):
  raise ValueError('FAILED')
 return data

def readFile ( filename , offset , length ) : absoffset = abs ( offset ) abslength = abs ( length ) try : with open ( filename , 'rb' ) as f : if ( absoffset != offset ) : if length : raise ValueError ( 'BAD_ARGUMENTS' ) f . seek ( 0 , 2 ) sz = f . tell ( ) pos = int ( ( sz - absoffset ) ) if ( pos < 0 ) : pos = 0 f . seek ( pos ) data = f . read ( absoffset ) else : if ( abslength != length ) : raise ValueError ( 'BAD_ARGUMENTS' ) if ( length == 0 ) : f . seek ( offset ) data = f . read ( ) else : f . seek ( offset ) data = f . read ( length ) except ( OSError , IOError ) : raise ValueError ( 'FAILED' ) return data
read length bytes from the file named by filename starting at offset .