def lineify_fileobjs(ifo, ofo, strip=False): from pyutil.strutil import pop_trailing_newlines, split_on_newlines for l in ifo: for sl in split_on_newlines(pop_trailing_newlines(l)): if strip: sl = sl.strip() ofo.write(pop_trailing_newlines(sl) + '\n')
def test_split(self): _assert( strutil.split_on_newlines("x\r\ny") == [ "x", "y", ], strutil.split_on_newlines("x\r\ny")) _assert( strutil.split_on_newlines("x\r\ny\r\n") == [ "x", "y", '', ], strutil.split_on_newlines("x\r\ny\r\n")) _assert( strutil.split_on_newlines("x\n\ny\n\n") == [ "x", '', "y", '', '', ], strutil.split_on_newlines("x\n\ny\n\n"))
def test_split(self): _assert(strutil.split_on_newlines("x\r\ny") == ["x", "y",], strutil.split_on_newlines("x\r\ny")) _assert(strutil.split_on_newlines("x\r\ny\r\n") == ["x", "y", '',], strutil.split_on_newlines("x\r\ny\r\n")) _assert(strutil.split_on_newlines("x\n\ny\n\n") == ["x", '', "y", '', '',], strutil.split_on_newlines("x\n\ny\n\n"))