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 better

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 where we

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 '\n'

Re: Writing byte stream as jpeg format to disk

2010-08-27 Thread Lawrence D'Oliveiro
In message mailman.64.1282843346.29448.python-l...@python.org, 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

Re: Writing byte stream as jpeg format to disk

2010-08-27 Thread Lawrence D'Oliveiro
In message mailman.71.1282852048.29448.python-l...@python.org, 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

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 mailman.64.1282843346.29448.python-l...@python.org, 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

Writing byte stream as jpeg format to disk

2010-08-26 Thread Navkirat Singh
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 encode the same string to a

Re: Writing byte stream as jpeg format to disk

2010-08-26 Thread John Bokma
Navkirat Singh navkir...@gmail.com 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 Navkirat Singh
On 26-Aug-2010, at 11:01 PM, John Bokma wrote: Navkirat Singh navkir...@gmail.com 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 Grant Edwards
On 2010-08-26, Navkirat Singh navkir...@gmail.com wrote: On 26-Aug-2010, at 11:01 PM, John Bokma wrote: Navkirat Singh navkir...@gmail.com 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

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 image on

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

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

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 Singhnavkir...@gmail.com 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

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 Singhnavkir...@gmail.com writes: Hey guys, I am programming a webserver, I receive a jpeg file with the POST method.The file (.jpeg) is

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 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

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 file (now a

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 file (now a

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 Dave Angel
Navkirat Singh wrote: O snip 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 encoded in bytes, I parse the

Re: Writing byte stream as jpeg format to disk

2010-08-26 Thread John Bokma
Navkirat Singh navkir...@gmail.com 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:

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

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 encoded in bytes, I parse the

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 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, I am programming a webserver,

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, I am programming a webserver, I

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 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

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 wrote: Navkirat Singh

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

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. Here is what I

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

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: The

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 probably shouldn't

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) class 'bytes' 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 stdin, line 1, inmodule TypeError: Type

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) class 'bytes' 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