def runLengthDecode(stream):
 decodedStream = ''
 index = 0
 try:
  while (index < len(stream)):
   length = ord(stream[index])
   if ((length >= 0) and (length < 128)):
    decodedStream += stream[(index + 1):((index + length) + 2)]
    index += (length + 2)
   elif ((length > 128) and (length < 256)):
    decodedStream += (stream[(index + 1)] * (257 - length))
    index += 2
   else:
    break
 except:
  return ((-1), 'Error decoding string')
 return (0, decodedStream)

def runLengthDecode ( stream ) : decodedStream = '' index = 0 try : while ( index < len ( stream ) ) : length = ord ( stream [ index ] ) if ( ( length >= 0 ) and ( length < 128 ) ) : decodedStream += stream [ ( index + 1 ) : ( ( index + length ) + 2 ) ] index += ( length + 2 ) elif ( ( length > 128 ) and ( length < 256 ) ) : decodedStream += ( stream [ ( index + 1 ) ] * ( 257 - length ) ) index += 2 else : break except : return ( ( - 1 ) , 'Error decoding string' ) return ( 0 , decodedStream )
method to decode streams using the run-length algorithm .