def readUntilRegex(stream, regex, ignore_eof=False):
 name = b_('')
 while True:
  tok = stream.read(16)
  if (not tok):
   if (ignore_eof == True):
    return name
   else:
    raise PdfStreamError('Stream has ended unexpectedly')
  m = regex.search(tok)
  if (m is not None):
   name += tok[:m.start()]
   stream.seek((m.start() - len(tok)), 1)
   break
  name += tok
 return name

def readUntilRegex ( stream , regex , ignore_eof = False ) : name = b_ ( '' ) while True : tok = stream . read ( 16 ) if ( not tok ) : if ( ignore_eof == True ) : return name else : raise PdfStreamError ( 'Stream has ended unexpectedly' ) m = regex . search ( tok ) if ( m is not None ) : name += tok [ : m . start ( ) ] stream . seek ( ( m . start ( ) - len ( tok ) ) , 1 ) break name += tok return name
reads until the regular expression pattern matched raise pdfstreamerror on premature end-of-file .