Re: Writing byte stream as jpeg format to disk

2010-08-27 Thread Robert Kern
On 8/27/10 5:58 PM, Lawrence D'Oliveiro wrote: In message , Navkirat Singh wrote: I receive a jpeg file with the POST method.The file (.jpeg) is encoded in bytes, I parse the bytes by decoding them to a string. I wanted to know how i could write the file (now a string) as a jpeg image on disk.

Re: Writing byte stream as jpeg format to disk

2010-08-27 Thread Lawrence D'Oliveiro
In message , Navkirat Singh wrote: > The image bytes are a part of a HTTP header content ( not the message body > ). In which case, won’t they be in some encoding like Base-64? I don’t think you’re allowed arbitrary binary bytes in an HTTP header. -- http://mail.python.org/mailman/listinfo/pyt

Re: Writing byte stream as jpeg format to disk

2010-08-27 Thread Lawrence D'Oliveiro
In message , Navkirat Singh wrote: > I receive a jpeg file with the POST method.The file (.jpeg) is encoded in > bytes, I parse the bytes by decoding them to a string. I wanted to know > how i could write the file (now a string) as a jpeg image on disk. I assume the JPEG data is received along wi

Re: Writing byte stream as jpeg format to disk

2010-08-27 Thread Bryan
Nobody wrote: > Bryan wrote: > > this is a case where we might want to be better > > than correct. BaseHTTPRequestHandler in the Python standard library > > accommodates clients that incorrectly omit the '\r' and end header lines > > with just '\n'. Such apps have been seen in the wild. Since bare

Re: Writing byte stream as jpeg format to disk

2010-08-27 Thread Nobody
On Thu, 26 Aug 2010 23:56:26 -0700, Bryan wrote: >> follow our advice. Split using b'\r\n\r\n' and use the maxsplit=1 >> argument to make sure that you do not split on spurious b'\r\n\r\n' >> sequences inside the JPEG body. Do not decode the bytes. > > Correct, and I'll add that this is a case wh

Re: Writing byte stream as jpeg format to disk

2010-08-27 Thread Bryan
Robert Kern wrote: > Please > follow our advice. Split using b'\r\n\r\n' and use the maxsplit=1 argument to > make sure that you do not split on spurious b'\r\n\r\n' sequences inside the > JPEG body. Do not decode the bytes. Correct, and I'll add that this is a case where we might want to be bette

Re: Writing byte stream as jpeg format to disk

2010-08-26 Thread Navkirat Singh
On 27-Aug-2010, at 4:23 AM, Terry Reedy wrote: > On 8/26/2010 5:28 PM, Navkirat Singh wrote: > > b = b'asdf' > type(b) >> > s = b.split(':') > > You are trying to split bytes with a string, which is impossible. > Split bytes with bytes, strings with strings. > >> Traceback (most r

Re: Writing byte stream as jpeg format to disk

2010-08-26 Thread Terry Reedy
On 8/26/2010 5:28 PM, Navkirat Singh wrote: b = b'asdf' type(b) s = b.split(':') You are trying to split bytes with a string, which is impossible. Split bytes with bytes, strings with strings. Traceback (most recent call last): File "", line 1, in TypeError: Type str doesn't support th

Re: Writing byte stream as jpeg format to disk

2010-08-26 Thread Navkirat Singh
On 27-Aug-2010, at 3:15 AM, Robert Kern wrote: > On 8/26/10 4:17 PM, Navkirat Singh wrote: > >> #-HERE IS WHERE I RECEIVE THE DATA >> while True: >> buff = socket.recv(8192) >> byteStr +=buff >> if not buff: break > > Also, you probab

Re: Writing byte stream as jpeg format to disk

2010-08-26 Thread Navkirat Singh
On 27-Aug-2010, at 3:04 AM, Robert Kern wrote: > On 8/26/10 4:25 PM, Navkirat Singh wrote: > >> @Robert - Thanks a lot for your time :-) , I did know that the body starts >> after >> the occurrence two CRLF sequences, but I was following RFC2616 as a guide, >> which >> specifically mentions: >

Re: Writing byte stream as jpeg format to disk

2010-08-26 Thread Robert Kern
On 8/26/10 4:17 PM, Navkirat Singh wrote: #-HERE IS WHERE I RECEIVE THE DATA while True: buff = socket.recv(8192) byteStr +=buff if not buff: break Also, you probably shouldn't bother writing an HTTP server using raw s

Re: Writing byte stream as jpeg format to disk

2010-08-26 Thread Navkirat Singh
On 27-Aug-2010, at 3:02 AM, Robert Kern wrote: > On 8/26/10 4:17 PM, Navkirat Singh wrote: > >> Here is what I needed to do: >> >> a) Separate image content from header content of the byte stream received >> from the web browser. >> b) Save the image content to disk for further use. >> >> Her

Re: Writing byte stream as jpeg format to disk

2010-08-26 Thread Robert Kern
On 8/26/10 4:28 PM, Navkirat Singh wrote: On 27-Aug-2010, at 2:48 AM, MRAB wrote: On 26/08/2010 21:47, Navkirat Singh wrote: On 27-Aug-2010, at 1:57 AM, MRAB wrote: On 26/08/2010 21:14, Navkirat Singh wrote: On 27-Aug-2010, at 1:32 AM, Dave Angel wrote: Navkirat Singh wrote: Hey guys,

Re: Writing byte stream as jpeg format to disk

2010-08-26 Thread Navkirat Singh
On 27-Aug-2010, at 2:58 AM, Navkirat Singh wrote: > > On 27-Aug-2010, at 2:48 AM, MRAB wrote: > >> On 26/08/2010 21:47, Navkirat Singh wrote: >>> >>> On 27-Aug-2010, at 1:57 AM, MRAB wrote: >>> On 26/08/2010 21:14, Navkirat Singh wrote: > > On 27-Aug-2010, at 1:32 AM, Dave Angel

Re: Writing byte stream as jpeg format to disk

2010-08-26 Thread Robert Kern
On 8/26/10 4:25 PM, Navkirat Singh wrote: @Robert - Thanks a lot for your time :-) , I did know that the body starts after the occurrence two CRLF sequences, but I was following RFC2616 as a guide, which specifically mentions: "The presence of a message-body in a request is signaled by the incl

Re: Writing byte stream as jpeg format to disk

2010-08-26 Thread Robert Kern
On 8/26/10 4:17 PM, Navkirat Singh wrote: Here is what I needed to do: a) Separate image content from header content of the byte stream received from the web browser. b) Save the image content to disk for further use. Here is what I did. Following is just a snippet: #---

Re: Writing byte stream as jpeg format to disk

2010-08-26 Thread Navkirat Singh
On 27-Aug-2010, at 2:48 AM, MRAB wrote: > On 26/08/2010 21:47, Navkirat Singh wrote: >> >> On 27-Aug-2010, at 1:57 AM, MRAB wrote: >> >>> On 26/08/2010 21:14, Navkirat Singh wrote: On 27-Aug-2010, at 1:32 AM, Dave Angel wrote: > Navkirat Singh wrote: >> Hey guys, >>

Re: Writing byte stream as jpeg format to disk

2010-08-26 Thread Navkirat Singh
On 27-Aug-2010, at 2:40 AM, Robert Kern wrote: > On 8/26/10 3:47 PM, Navkirat Singh wrote: >> >> On 27-Aug-2010, at 1:57 AM, MRAB wrote: >> >>> On 26/08/2010 21:14, Navkirat Singh wrote: On 27-Aug-2010, at 1:32 AM, Dave Angel wrote: > Navkirat Singh wrote: >> Hey guys,

Re: Writing byte stream as jpeg format to disk

2010-08-26 Thread MRAB
On 26/08/2010 21:47, Navkirat Singh wrote: On 27-Aug-2010, at 1:57 AM, MRAB wrote: On 26/08/2010 21:14, Navkirat Singh wrote: On 27-Aug-2010, at 1:32 AM, Dave Angel wrote: Navkirat Singh wrote: Hey guys, I am programming a webserver, I receive a jpeg file with the POST method.The file (.

Re: Writing byte stream as jpeg format to disk

2010-08-26 Thread Navkirat Singh
On 27-Aug-2010, at 1:57 AM, MRAB wrote: > On 26/08/2010 21:14, Navkirat Singh wrote: >> >> On 27-Aug-2010, at 1:32 AM, Dave Angel wrote: >> >>> Navkirat Singh wrote: Hey guys, I am programming a webserver, I receive a jpeg file with the POST method.The file (.jpeg) is encod

Re: Writing byte stream as jpeg format to disk

2010-08-26 Thread Robert Kern
On 8/26/10 3:47 PM, Navkirat Singh wrote: On 27-Aug-2010, at 1:57 AM, MRAB wrote: On 26/08/2010 21:14, Navkirat Singh wrote: On 27-Aug-2010, at 1:32 AM, Dave Angel wrote: Navkirat Singh wrote: Hey guys, I am programming a webserver, I receive a jpeg file with the POST method.The file (.j

Re: Writing byte stream as jpeg format to disk

2010-08-26 Thread John Bokma
Navkirat Singh writes: >>> I am using Python3 and I receive a byte stream with a jpeg attached sent >>> by the web browser over a socket, which looks like this: >>> >>> b': image/jpeg\r\nAccept: text/*\r\nReferer: >>> http://127.0.0.1:8001/\r\nAccept-Language: en-us\r\nAccept-Encoding: >>> gzip,

Re: Writing byte stream as jpeg format to disk

2010-08-26 Thread Navkirat Singh
On 27-Aug-2010, at 1:57 AM, MRAB wrote: > On 26/08/2010 21:14, Navkirat Singh wrote: >> >> On 27-Aug-2010, at 1:32 AM, Dave Angel wrote: >> >>> Navkirat Singh wrote: Hey guys, I am programming a webserver, I receive a jpeg file with the POST method.The file (.jpeg) is encod

Re: Writing byte stream as jpeg format to disk

2010-08-26 Thread Dave Angel
Navkirat Singh wrote: O I am using Python3 and I receive a byte stream with a jpeg attached sent by the web browser over a socket, which looks like this: b': image/jpeg\r\nAccept: text/*\r\nReferer: http://127.0.0.1:8001/\r\nAccept-Language: en-us\r\nAccept-Encoding: gzip, deflate\r\nContent

Re: Writing byte stream as jpeg format to disk

2010-08-26 Thread MRAB
On 26/08/2010 21:14, Navkirat Singh wrote: On 27-Aug-2010, at 1:32 AM, Dave Angel wrote: Navkirat Singh wrote: Hey guys, I am programming a webserver, I receive a jpeg file with the POST method.The file (.jpeg) is encoded in bytes, I parse the bytes by decoding them to a string. I wanted to

Re: Writing byte stream as jpeg format to disk

2010-08-26 Thread Navkirat Singh
On 27-Aug-2010, at 1:32 AM, Dave Angel wrote: > Navkirat Singh wrote: >> Hey guys, >> >> I am programming a webserver, I receive a jpeg file with the POST method.The >> file (.jpeg) is encoded in bytes, I parse the bytes by decoding them to a >> string. I wanted to know how i could write the f

Re: Writing byte stream as jpeg format to disk

2010-08-26 Thread Navkirat Singh
On 27-Aug-2010, at 1:32 AM, Dave Angel wrote: > Navkirat Singh wrote: >> Hey guys, >> >> I am programming a webserver, I receive a jpeg file with the POST method.The >> file (.jpeg) is encoded in bytes, I parse the bytes by decoding them to a >> string. I wanted to know how i could write the f

Re: Writing byte stream as jpeg format to disk

2010-08-26 Thread Dave Angel
Navkirat Singh wrote: Hey guys, I am programming a webserver, I receive a jpeg file with the POST method.The file (.jpeg) is encoded in bytes, I parse the bytes by decoding them to a string. I wanted to know how i could write the file (now a string) as a jpeg image on disk. When I try to enco

Re: Writing byte stream as jpeg format to disk

2010-08-26 Thread Navkirat Singh
On 27-Aug-2010, at 12:45 AM, MRAB wrote: > On 26/08/2010 19:57, Navkirat Singh wrote: >> I am sorry, maybe I was not elaborate in what I was having trouble >> with. I am using a jpegcam library, which on my web page captures a >> webcam image and sends it to the server via the POST method. On the

Re: Writing byte stream as jpeg format to disk

2010-08-26 Thread Navkirat Singh
On 27-Aug-2010, at 1:10 AM, Robert Kern wrote: > On 8/26/10 1:25 PM, Navkirat Singh wrote: >> >> On 26-Aug-2010, at 11:01 PM, John Bokma wrote: >> >>> Navkirat Singh writes: >>> Hey guys, I am programming a webserver, I receive a jpeg file with the POST method.The file (.

Re: Writing byte stream as jpeg format to disk

2010-08-26 Thread Robert Kern
On 8/26/10 1:25 PM, Navkirat Singh wrote: On 26-Aug-2010, at 11:01 PM, John Bokma wrote: Navkirat Singh writes: Hey guys, I am programming a webserver, I receive a jpeg file with the POST method.The file (.jpeg) is encoded in bytes, I parse the bytes by decoding them to a string. Why? -

Re: Writing byte stream as jpeg format to disk

2010-08-26 Thread MRAB
On 26/08/2010 19:57, Navkirat Singh wrote: I am sorry, maybe I was not elaborate in what I was having trouble with. I am using a jpegcam library, which on my web page captures a webcam image and sends it to the server via the POST method. On the Server side (python 3), I receive this image as a p

Re: Writing byte stream as jpeg format to disk

2010-08-26 Thread Navkirat Singh
I am sorry, maybe I was not elaborate in what I was having trouble with. I am using a jpegcam library, which on my web page captures a webcam image and sends it to the server via the POST method. On the Server side (python 3), I receive this image as a part of header content in bytes (I know tha

Re: Writing byte stream as jpeg format to disk

2010-08-26 Thread Stefan Schwarzer
Hi Navkirat, On 2010-08-26 19:22, Navkirat Singh wrote: > I am programming a webserver, I receive a jpeg file with > the POST method.The file (.jpeg) is encoded in bytes, I > parse the bytes by decoding them to a string. I wanted to > know how i could write the file (now a string) as a jpeg > imag

Re: Writing byte stream as jpeg format to disk

2010-08-26 Thread Grant Edwards
On 2010-08-26, Navkirat Singh wrote: > > On 26-Aug-2010, at 11:01 PM, John Bokma wrote: > >> Navkirat Singh writes: >> >>> Hey guys, >>> >>> I am programming a webserver, I receive a jpeg file with the POST >>> method.The file (.jpeg) is encoded in bytes, I parse the bytes by >>> decoding them

Re: Writing byte stream as jpeg format to disk

2010-08-26 Thread Navkirat Singh
On 26-Aug-2010, at 11:01 PM, John Bokma wrote: > Navkirat Singh writes: > >> Hey guys, >> >> I am programming a webserver, I receive a jpeg file with the POST >> method.The file (.jpeg) is encoded in bytes, I parse the bytes by >> decoding them to a string. > > Why? > > -- > John Bokma

Re: Writing byte stream as jpeg format to disk

2010-08-26 Thread John Bokma
Navkirat Singh writes: > Hey guys, > > I am programming a webserver, I receive a jpeg file with the POST > method.The file (.jpeg) is encoded in bytes, I parse the bytes by > decoding them to a string. Why? -- John Bokma j3b Blog: