🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: pl.comp.lang.python
1 messages
1 total messages Started by System Egzaminacyjny Mon, 29 Nov 2010 14:51
multipart/form-data
#27822
Author: System Egzaminacyjny
Date: Mon, 29 Nov 2010 14:51
81 lines
3725 bytes
a jak zrobic, zeby dzialo z binariami, ktore nie mieszcza sie w ascii?

Python 3.1.2 (release31-maint, Sep 26 2010, 13:51:01)
[GCC 4.4.5] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from io import BytesIO,StringIO
>>> from cgi import *
[...]
>>> ctt
'multipart/form-data; boundary=ciach-5e821pttrzt92d25qw'
>>> print(repr(dat).replace('\\n','\\n\n'))
b'--ciach-5e821pttrzt92d25qw\r\n
Content-Disposition: form-data; name="a"\r\n
\r\n
b\r\n
--ciach-5e821pttrzt92d25qw\r\n
Content-Disposition: form-data; name="c"\r\n
\r\n
d\r\n
--ciach-5e821pttrzt92d25qw--\r\n
'
>>> bf=BytesIO(dat)
>>> bf.seek(0,0)
0
>>> env={}
>>> env['CONTENT_TYPE']=ctt
>>> bf.seek(0,2)
180
>>> env['CONTENT_LENGTH']=bf.seek(0,2)
>>> env['REQUEST_METHOD']='POST'
>>> env
{'CONTENT_LENGTH': 180, 'REQUEST_METHOD': 'POST', 'CONTENT_TYPE':
'multipart/form-data; boundary=ciach-5e821pttrzt92d25qw'}
>>> bf.seek(0,0);bf.read();bf.seek(0,0)
0
b'--ciach-5e821pttrzt92d25qw\r\nContent-Disposition: form-data;
name="a"\r\n\r\nb\r\n--ciach-5e821pttrzt92d25qw\r\nContent-
Disposition:
form-data; name="c"\r\n\r\nd\r\n--ciach-5e821pttrzt92d25qw--\r\n'
0
>>> dat
b'--ciach-5e821pttrzt92d25qw\r\nContent-Disposition: form-data;
name="a"\r\n\r\nb\r\n--ciach-5e821pttrzt92d25qw\r\nContent-
Disposition:
form-data; name="c"\r\n\r\nd\r\n--ciach-5e821pttrzt92d25qw--\r\n'
>>> sto3=FieldStorage(bf,environ=env)
Traceback (most recent call last):
               File "<stdin>", line 1, in <module>
               File "/usr/lib/python3.1/cgi.py", line 491, in __init__
                 self.read_multi(environ, keep_blank_values,
strict_parsing)
               File "/usr/lib/python3.1/cgi.py", line 611, in
read_multi
                 parser.feed(self.fp.read())
               File "/usr/lib/python3.1/email/feedparser.py", line
156, in
feed
                 self._input.push(data)
               File "/usr/lib/python3.1/email/feedparser.py", line 99,
in
push
                 data, self._partial = self._partial + data, ''
TypeError: Can't convert 'bytes' object to str implicitly
>>> invld=StringIO(dat.decode())
>>> print(dat.decode())
--ciach-5e821pttrzt92d25qw
Content-Disposition: form-data; name="a"

b
--ciach-5e821pttrzt92d25qw
Content-Disposition: form-data; name="c"

d
--ciach-5e821pttrzt92d25qw--

>>> sto=FieldStorage(invld,environ=env)
>>> sto
FieldStorage(None, None, [FieldStorage('a', None, 'b'),
FieldStorage('c',
None, 'd')])
>>>
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads