Skip to content

Instantly share code, notes, and snippets.

@reedobrien
Created February 21, 2011 02:21
Show Gist options
  • Save reedobrien/836588 to your computer and use it in GitHub Desktop.
Save reedobrien/836588 to your computer and use it in GitHub Desktop.
"""
https://bitbucket.org/ianb/webob/changeset/6b1f2d09fee7#chg-webob/request.py_newline489
self.body_file_raw appears to re-escape characters on each POST
property access
whereas self.body_file does not. I think the latter is the correct
behavior.
I tried to make some failing test for you, but I was struggling
against not knowing the codebase, the test setup or hg: and I am out
of time. So I have included a lightly annotated debug session
below. Sorry.
"""
### with self.body_file_raw
> /usr/local/src/webob/webob/request.py(491)str_POST() -> return vars
(Pdb) self.body
'------WebKitFormBoundaryDqQL4WO4Gmr05PKb\r\nContent-Disposition:
form-data;
name="_charset_"\r\n\r\n\r\n------WebKitFormBoundaryDqQL4WO4Gmr05PKb\r\nContent-Disposition:
form-data;
name="__formid__"\r\n\r\ndeform\r\n------WebKitFormBoundaryDqQL4WO4Gmr05PKb\r\nContent-Disposition:
form-data;
name="__start__"\r\n\r\nblah_blah:mapping\r\n------WebKitFormBoundaryDqQL4WO4Gmr05PKb\r\nContent-Disposition:
form-data;
name="__start__"\r\n\r\ninterests:mapping\r\n------WebKitFormBoundaryDqQL4WO4Gmr05PKb\r\nContent-Disposition:
form-data;
name="With%3A%20funny%20%28chars%29"\r\n\r\n1\r\n------WebKitFormBoundaryDqQL4WO4Gmr05PKb\r\nContent-Disposition:
form-data;
name="white%20space"\r\n\r\n3\r\n------WebKitFormBoundaryDqQL4WO4Gmr05PKb\r\nContent-Disposition:
form-data;
name="__end__"\r\n\r\ninterests:mapping\r\n------WebKitFormBoundaryDqQL4WO4Gmr05PKb\r\nContent-Disposition:
form-data;
name="__end__"\r\n\r\nblah_blah:mapping\r\n------WebKitFormBoundaryDqQL4WO4Gmr05PKb\r\nContent-Disposition:
form-data;
name="save"\r\n\r\nsave\r\n------WebKitFormBoundaryDqQL4WO4Gmr05PKb--'
(Pdb) self.POST UnicodeMultiDict([('_charset_', u''), ('__formid__',
u'deform'), ('__start__', u'blah_blah:mapping'), ('__start__',
u'interests:mapping'), ('With%3A%20funny%20%28chars%29', u'1'),
('white%20space', u'3'), ('__end__', u'interests:mapping'),
('__end__', u'blah_blah:mapping'), ('save', u'save')]) (Pdb) self.POST
UnicodeMultiDict([('_charset_', u''), ('__formid__', u'deform'),
('__start__', u'blah_blah:mapping'), ('__start__',
u'interests:mapping'), ('With%253A%2520funny%2520%2528chars%2529',
u'1'), ('white%2520space', u'3'), ('__end__', u'interests:mapping'),
('__end__', u'blah_blah:mapping'), ('save', u'save')]) (Pdb) self.POST
UnicodeMultiDict([('_charset_', u''), ('__formid__', u'deform'),
('__start__', u'blah_blah:mapping'), ('__start__',
u'interests:mapping'),
('With%25253A%252520funny%252520%252528chars%252529', u'1'),
('white%252520space', u'3'), ('__end__', u'interests:mapping'),
('__end__', u'blah_blah:mapping'), ('save', u'save')]) (Pdb) self.POST
UnicodeMultiDict([('_charset_', u''), ('__formid__', u'deform'),
('__start__', u'blah_blah:mapping'), ('__start__',
u'interests:mapping'),
('With%2525253A%25252520funny%25252520%25252528chars%25252529', u'1'),
('white%25252520space', u'3'), ('__end__', u'interests:mapping'),
('__end__', u'blah_blah:mapping'), ('save', u'save')])
## You can see above that each access adds to the escaped characters.
## Look for the word funny up there...
## below is a similar session with self.body_file as the arg
(Pdb) c > /usr/local/src/webob/webob/request.py(491)str_POST() ->
return vars (Pdb) /usr/local/src/webob/webob/request.pyc changed;
reloading... -------------------- Restarting --------------------
Starting server in PID 84171. serving on 0.0.0.0:6543 view at
http://127.0.0.1:6543 2011-02-21 01:55:32,174 INFO
[paste.httpserver.ThreadPool][MainThread] Shutting down threadpool ^C
caught in monitor process Erase is delete. Interrupt is control-C
(^C). (venv)sumac:starter-0.1 robrien$ ./venv/bin/paster serve
development.ini --reload Starting subprocess with file monitor
Starting server in PID 84178. serving on 0.0.0.0:6543 view at
http://127.0.0.1:6543 >
/usr/local/src/webob/webob/request.py(491)str_POST() -> return vars
(Pdb) self.body
'------WebKitFormBoundaryw3rApktHQ4IlX90j\r\nContent-Disposition:
form-data;
name="_charset_"\r\n\r\n\r\n------WebKitFormBoundaryw3rApktHQ4IlX90j\r\nContent-Disposition:
form-data;
name="__formid__"\r\n\r\ndeform\r\n------WebKitFormBoundaryw3rApktHQ4IlX90j\r\nContent-Disposition:
form-data;
name="__start__"\r\n\r\nblah_blah:mapping\r\n------WebKitFormBoundaryw3rApktHQ4IlX90j\r\nContent-Disposition:
form-data;
name="__start__"\r\n\r\ninterests:mapping\r\n------WebKitFormBoundaryw3rApktHQ4IlX90j\r\nContent-Disposition:
form-data;
name="With%3A%20funny%20%28chars%29"\r\n\r\n1\r\n------WebKitFormBoundaryw3rApktHQ4IlX90j\r\nContent-Disposition:
form-data;
name="white%20space"\r\n\r\n2\r\n------WebKitFormBoundaryw3rApktHQ4IlX90j\r\nContent-Disposition:
form-data;
name="__end__"\r\n\r\ninterests:mapping\r\n------WebKitFormBoundaryw3rApktHQ4IlX90j\r\nContent-Disposition:
form-data;
name="__end__"\r\n\r\nblah_blah:mapping\r\n------WebKitFormBoundaryw3rApktHQ4IlX90j\r\nContent-Disposition:
form-data;
name="save"\r\n\r\nsave\r\n------WebKitFormBoundaryw3rApktHQ4IlX90j--'
(Pdb) self.POST UnicodeMultiDict([('_charset_', u''), ('__formid__',
u'deform'), ('__start__', u'blah_blah:mapping'), ('__start__',
u'interests:mapping'), ('With: funny (chars)', u'1'), ('white space',
u'2'), ('__end__', u'interests:mapping'), ('__end__',
u'blah_blah:mapping'), ('save', u'save')]) (Pdb) self.POST
UnicodeMultiDict([('_charset_', u''), ('__formid__', u'deform'),
('__start__', u'blah_blah:mapping'), ('__start__',
u'interests:mapping'), ('With: funny (chars)', u'1'), ('white space',
u'2'), ('__end__', u'interests:mapping'), ('__end__',
u'blah_blah:mapping'), ('save', u'save')]) (Pdb) self.POST
UnicodeMultiDict([('_charset_', u''), ('__formid__', u'deform'),
('__start__', u'blah_blah:mapping'), ('__start__',
u'interests:mapping'), ('With: funny (chars)', u'1'), ('white space',
u'2'), ('__end__', u'interests:mapping'), ('__end__',
u'blah_blah:mapping'), ('save', u'save')]) (Pdb) self.POST
UnicodeMultiDict([('_charset_', u''), ('__formid__', u'deform'),
('__start__', u'blah_blah:mapping'), ('__start__',
u'interests:mapping'), ('With: funny (chars)', u'1'), ('white space',
u'2'), ('__end__', u'interests:mapping'), ('__end__',
u'blah_blah:mapping'), ('save', u'save')])
## You can see this behaves as expected (or at least as I expect it
## to.).
## Sorry there wasn't better contribution than this.>
/usr/local/src/webob/webob/request.py(491)str_POST() -> return vars
(Pdb) self.body
'------WebKitFormBoundaryDqQL4WO4Gmr05PKb\r\nContent-Disposition:
form-data;
name="_charset_"\r\n\r\n\r\n------WebKitFormBoundaryDqQL4WO4Gmr05PKb\r\nContent-Disposition:
form-data;
name="__formid__"\r\n\r\ndeform\r\n------WebKitFormBoundaryDqQL4WO4Gmr05PKb\r\nContent-Disposition:
form-data;
name="__start__"\r\n\r\nblah_blah:mapping\r\n------WebKitFormBoundaryDqQL4WO4Gmr05PKb\r\nContent-Disposition:
form-data;
name="__start__"\r\n\r\ninterests:mapping\r\n------WebKitFormBoundaryDqQL4WO4Gmr05PKb\r\nContent-Disposition:
form-data;
name="With%3A%20funny%20%28chars%29"\r\n\r\n1\r\n------WebKitFormBoundaryDqQL4WO4Gmr05PKb\r\nContent-Disposition:
form-data;
name="white%20space"\r\n\r\n3\r\n------WebKitFormBoundaryDqQL4WO4Gmr05PKb\r\nContent-Disposition:
form-data;
name="__end__"\r\n\r\ninterests:mapping\r\n------WebKitFormBoundaryDqQL4WO4Gmr05PKb\r\nContent-Disposition:
form-data;
name="__end__"\r\n\r\nblah_blah:mapping\r\n------WebKitFormBoundaryDqQL4WO4Gmr05PKb\r\nContent-Disposition:
form-data;
name="save"\r\n\r\nsave\r\n------WebKitFormBoundaryDqQL4WO4Gmr05PKb--'
(Pdb) self.POST UnicodeMultiDict([('_charset_', u''), ('__formid__',
u'deform'), ('__start__', u'blah_blah:mapping'), ('__start__',
u'interests:mapping'), ('With%3A%20funny%20%28chars%29', u'1'),
('white%20space', u'3'), ('__end__', u'interests:mapping'),
('__end__', u'blah_blah:mapping'), ('save', u'save')]) (Pdb) self.POST
UnicodeMultiDict([('_charset_', u''), ('__formid__', u'deform'),
('__start__', u'blah_blah:mapping'), ('__start__',
u'interests:mapping'), ('With%253A%2520funny%2520%2528chars%2529',
u'1'), ('white%2520space', u'3'), ('__end__', u'interests:mapping'),
('__end__', u'blah_blah:mapping'), ('save', u'save')]) (Pdb) self.POST
UnicodeMultiDict([('_charset_', u''), ('__formid__', u'deform'),
('__start__', u'blah_blah:mapping'), ('__start__',
u'interests:mapping'),
('With%25253A%252520funny%252520%252528chars%252529', u'1'),
('white%252520space', u'3'), ('__end__', u'interests:mapping'),
('__end__', u'blah_blah:mapping'), ('save', u'save')]) (Pdb) self.POST
UnicodeMultiDict([('_charset_', u''), ('__formid__', u'deform'),
('__start__', u'blah_blah:mapping'), ('__start__',
u'interests:mapping'),
('With%2525253A%25252520funny%25252520%25252528chars%25252529', u'1'),
('white%25252520space', u'3'), ('__end__', u'interests:mapping'),
('__end__', u'blah_blah:mapping'), ('save', u'save')]) (Pdb) c >
/usr/local/src/webob/webob/request.py(491)str_POST() -> return vars
(Pdb) /usr/local/src/webob/webob/request.pyc changed; reloading...
-------------------- Restarting -------------------- Starting server
in PID 84171. serving on 0.0.0.0:6543 view at http://127.0.0.1:6543
2011-02-21 01:55:32,174 INFO [paste.httpserver.ThreadPool][MainThread]
Shutting down threadpool ^C caught in monitor process Erase is delete.
Interrupt is control-C (^C). (venv)sumac:starter-0.1 robrien$
./venv/bin/paster serve development.ini --reload Starting subprocess
with file monitor Starting server in PID 84178. serving on
0.0.0.0:6543 view at http://127.0.0.1:6543 >
/usr/local/src/webob/webob/request.py(491)str_POST() -> return vars
(Pdb) self.body
'------WebKitFormBoundaryw3rApktHQ4IlX90j\r\nContent-Disposition:
form-data;
name="_charset_"\r\n\r\n\r\n------WebKitFormBoundaryw3rApktHQ4IlX90j\r\nContent-Disposition:
form-data;
name="__formid__"\r\n\r\ndeform\r\n------WebKitFormBoundaryw3rApktHQ4IlX90j\r\nContent-Disposition:
form-data;
name="__start__"\r\n\r\nblah_blah:mapping\r\n------WebKitFormBoundaryw3rApktHQ4IlX90j\r\nContent-Disposition:
form-data;
name="__start__"\r\n\r\ninterests:mapping\r\n------WebKitFormBoundaryw3rApktHQ4IlX90j\r\nContent-Disposition:
form-data;
name="With%3A%20funny%20%28chars%29"\r\n\r\n1\r\n------WebKitFormBoundaryw3rApktHQ4IlX90j\r\nContent-Disposition:
form-data;
name="white%20space"\r\n\r\n2\r\n------WebKitFormBoundaryw3rApktHQ4IlX90j\r\nContent-Disposition:
form-data;
name="__end__"\r\n\r\ninterests:mapping\r\n------WebKitFormBoundaryw3rApktHQ4IlX90j\r\nContent-Disposition:
form-data;
name="__end__"\r\n\r\nblah_blah:mapping\r\n------WebKitFormBoundaryw3rApktHQ4IlX90j\r\nContent-Disposition:
form-data;
name="save"\r\n\r\nsave\r\n------WebKitFormBoundaryw3rApktHQ4IlX90j--'
(Pdb) self.POST UnicodeMultiDict([('_charset_', u''), ('__formid__',
u'deform'), ('__start__', u'blah_blah:mapping'), ('__start__',
u'interests:mapping'), ('With: funny (chars)', u'1'), ('white space',
u'2'), ('__end__', u'interests:mapping'), ('__end__',
u'blah_blah:mapping'), ('save', u'save')]) (Pdb) self.POST
UnicodeMultiDict([('_charset_', u''), ('__formid__', u'deform'),
('__start__', u'blah_blah:mapping'), ('__start__',
u'interests:mapping'), ('With: funny (chars)', u'1'), ('white space',
u'2'), ('__end__', u'interests:mapping'), ('__end__',
u'blah_blah:mapping'), ('save', u'save')]) (Pdb) self.POST
UnicodeMultiDict([('_charset_', u''), ('__formid__', u'deform'),
('__start__', u'blah_blah:mapping'), ('__start__',
u'interests:mapping'), ('With: funny (chars)', u'1'), ('white space',
u'2'), ('__end__', u'interests:mapping'), ('__end__',
u'blah_blah:mapping'), ('save', u'save')]) (Pdb) self.POST
UnicodeMultiDict([('_charset_', u''), ('__formid__', u'deform'),
('__start__', u'blah_blah:mapping'), ('__start__',
u'interests:mapping'), ('With: funny (chars)', u'1'), ('white space',
u'2'), ('__end__', u'interests:mapping'), ('__end__',
u'blah_blah:mapping'), ('save', u'save')])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment