fork download
  1. import re
  2. split_rule = re.compile("(?:\r\n)|(?:\r)|(?:\n)")
  3.  
  4.  
  5. def converter(byte_data):
  6. left_d = ""
  7. for d in byte_data:
  8. t = split_rule.split(left_d + d.decode())
  9. last_index = len(t) - 1
  10. for index, i in enumerate(t):
  11. if not i:
  12. continue
  13. if index != last_index:
  14. yield i
  15. else:
  16. left_d = i
  17. else:
  18. if left_d:
  19. yield left_d
  20.  
  21.  
  22. for i in (converter(iter((
  23. b'a',
  24. b'b,c\n',
  25. b'd,e\n')))
  26. ):
  27. print(repr(i))
Success #stdin #stdout 0.03s 9472KB
stdin
Standard input is empty
stdout
'ab,c'
'ad,e'
'a'