Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #24471

Re: Frustrating circular bytes issue

From Stefan Behnel <stefan_ml@behnel.de>
Subject Re: Frustrating circular bytes issue
Date 2012-06-26 19:22 +0200
References <CAFB6qZuUYE5Mp_Td-=LiMagP4UM65WEPLLJ5t33__Sa_bOq2hg@mail.gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.1521.1340731362.4697.python-list@python.org> (permalink)

Show all headers | View raw


J, 26.06.2012 18:30:
> def _reader(self, file, size=4096, delimiter=r"\n{2,}"):
>         buffer_old = ""
>         while True:
>             buffer_new = file.read()
>             print(type(buffer_new))
>             if not buffer_new:
>                 break
>             lines = re.split(delimiter, buffer_old + buffer_new)

"delimiter" is a Unicode string, which makes the regular expression a
Unicode regex that can't work on a byte string.


>             buffer_old = lines.pop(-1)
> 
>             for line in lines:
>                 yield line
> 
>         yield buffer_old
> 
> 
> (the print statement is something I put in to verify the problem.
> 
> So stepping through this, when _reader executes, it executes read() on
> the opened filehandle.  Originally, it read in 4096 byte chunks, I
> removed that to test a theory.  It creates buffer_new with the output
> of the read.
> 
> Running type() on buffer_new tells me that it's a bytes object.

Stefan

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: Frustrating circular bytes issue Stefan Behnel <stefan_ml@behnel.de> - 2012-06-26 19:22 +0200

csiph-web