* FAQ    * Search  * Register * Login 
Active topics
Unanswered topics

All times are UTC-06:00



Post new topic  Reply to topic  [ 7 posts ] 
Author Message
 Post subject: Question about how I'm passing a stack from js to python.
PostPosted: Sun Apr 03, 2011 6:27 pm 
Offline
DBB Artist
DBB Artist
User avatar

Joined: Mon Aug 01, 2005 8:47 am
Posts: 7124
Location: Ơ̸̦͇̲̬̭̱̰͎̞͈̣͎͚̳ͬ͋̃̀̇͊͂͋͐ͦ̽ͣ̂ͥ͊̅̀̚͠ B̶͖̯͉̜̰̲̓̔͋̈́ͅ È̯ Y̪̤̼͉̠̙͝
Server side (python):

edit: can't use code box since formatting won't hold. Using screenshot instead:
Attachment:
Screenshot.jpg
Screenshot.jpg [ 18.03 KiB | Viewed 1047 times ]



Browser (javascript):
Code:
<form action="/" method="post"><input type="hidden" name="ad" value="a3jk3j5k3j335h"><input type="hidden" name="ad" value="1"><input type="hidden" name="ad" value="1"><input type="hidden" name="ad" value="3"><input type="submit" value="+add user"></forum>


This button's data, once received by Python:
Code:
>>>self.js
('a3jk3j5k3j335h','1','1','3')



You'll notice that I'm doing something weird by giving all the inputs the same name. On all big name browsers this is treated like a stack and python builds a friendly tuple from it. However, on some obscure browsers, like my nokia, whatever ipad uses, and my grandma's Netscape browser like to only send the first variable and ignores the rest...

Is there an easy way to simply reformat this <form> data to pass a stack with out scaring mobile and archaic browsers?



Thank you, internet people!

_________________
s☼-£♦и̫͍ͥ̍ͪ͌̓͗͡о̡̹̱͊̅ͮ̓̕͢б̧̝̻̪̤̳̜͐̓̉ͤ͢͜ ͙̬͙̆̑ͮ̐ͭ̾̂́͘i̎̌̾̓̽̀̈̓̀҉͉̙̦͎̘̝͕f̻͕͔̘ͣͣ̓͊̿͢͜ ͍͔͈͕̮̫ͣ̆ͮ̊͋/♂6Æ!♪╩"▲L└уͭ̂͐̇҉̴̣̼̞̠̯͓̺̞ф̜̊͌̈́̋̏̐́ц̨͔̮̿̇ ̨̛͖̙͖̖̮̗̱ͩ̆͞ͅа̥͇̞̖͚̟̅͐ͤ͞͠͠э̜̘̩̳̬͔̾ͯ̀ͫ̒̐̿ͅͅг̭̖̀ͦ̒̑ͥ̌ͮͫ͞ё͔̟̃ͬ̾̓͟ё̦̞̙̫͔̩͑̀͂ͯ̄̔̃̑̀͠ͅͅ


Top
   
 Post subject: Re: Question about how I'm passing a stack from js to python
PostPosted: Sun Apr 03, 2011 7:03 pm 
Offline
DBB Master
DBB Master
User avatar

Joined: Sun Sep 05, 1999 2:01 am
Posts: 6377
Location: ☃☃☃
HTTP allows multiple GET and POST parameters with the same name, so you're not doing anything that weird. From what you're saying, it looks like python+cgi presents this as a tuple, which is not uncommon (most frameworks use some sort of list/tuple/array abstraction for this). Do you have an exact example of a browser version that you think fails at this that one can install on a desktop and test? If it's an ancient version of Netscape, then it might just be broken, but I find your claim of Safari on the iPad failing at this a bit more alarming.

The problem might be something less complex, like if you're using XHTML, make sure to close your input tags.

It's not clear to me what Javascript has to do with any of this.

You can always just use name="foo1", name="foo2", etc., and build the tuple yourself, but that's not a very satisfying solution curiosity-wise.


Top
   
 Post subject: Re: Question about how I'm passing a stack from js to python
PostPosted: Sun Apr 03, 2011 7:07 pm 
Offline
DBB Master
DBB Master
User avatar

Joined: Sun Sep 05, 1999 2:01 am
Posts: 6377
Location: ☃☃☃
Also, some general code review:
* Is there a reason you're using """foo""" quotes instead of 'foo' quotes?
* If self.js[0] can contain arbitrary user input, then your code could be unsafe XSS-wise.


Top
   
 Post subject: Re: Question about how I'm passing a stack from js to python
PostPosted: Sun Apr 03, 2011 8:35 pm 
Offline
DBB Artist
DBB Artist
User avatar

Joined: Mon Aug 01, 2005 8:47 am
Posts: 7124
Location: Ơ̸̦͇̲̬̭̱̰͎̞͈̣͎͚̳ͬ͋̃̀̇͊͂͋͐ͦ̽ͣ̂ͥ͊̅̀̚͠ B̶͖̯͉̜̰̲̓̔͋̈́ͅ È̯ Y̪̤̼͉̠̙͝
Jeff250 wrote:
HTTP allows multiple GET and POST parameters with the same name, so you're not doing anything that weird. From what you're saying, it looks like python+cgi presents this as a tuple, which is not uncommon (most frameworks use some sort of list/tuple/array abstraction for this).

That's good! I was so sure this thing I had stumbled while experimenting was the wrong was of passing stacks.


Jeff250 wrote:
Do you have an exact example of a browser version that you think fails at this that one can install on a desktop and test? If it's an ancient version of Netscape, then it might just be broken, but I find your claim of Safari on the iPad failing at this a bit more alarming.


And the android browser. I'll have to get more information, though I think I've got all that on Google Analytics. I don't get much traffic so it's easy for me sort out who's who.

Jeff250 wrote:
The problem might be something less complex, like if you're using XHTML, make sure to close your input tags.


It's actually a single CGI file that imports a main module, which imports a sub module, then imports another submodule, and so on. So it's just one python script that grows depending on what string it's fed. It's probably a bad way of doing things.


Jeff250 wrote:
It's not clear to me what Javascript has to do with any of this.
Oh sorry. I learned about <form> from a javascript site and since it returned data I figured it was javascript related... I should have known it wasn't since I never typed "javacript" into my site. Sorry sorry!

Also, I've decided to start working with javascript a bit more (And by that I mean real javascript, this time) and have found a way to pass stacks within javascript, so I think it will be easy to pass one back to the server. I might be able to start streaming data back and forth, which would rock.

Jeff250 wrote:
You can always just use name="foo1", name="foo2", etc., and build the tuple yourself, but that's not a very satisfying solution curiosity-wise.

You're right. I'll be use forms like this from now on.

I've stopped coding on my server space for a while to study what others have been doing. Also, I've picked up eclipse and pydev, so I've found, what I think is, my favorite editor.

With javascript and python in eclipse I should be able to build a nice workspace online, to start knocking out tutorials, when time permits.

Jeff250 wrote:
Also, some general code review:
* Is there a reason you're using """foo""" quotes instead of 'foo' quotes?

Oh yeah, because I want to break up the line. I hate crazy wrapping code. I can never read it.
So I can do something like:
mystring="""Once upon a time""" """ there was a rabbit""" """ named thunder."""

Jeff250 wrote:
* If self.js[0] can contain arbitrary user input, then your code could be unsafe XSS-wise.

I have not forgotten your post on using cookies. I plan to spend time working on making more secure sites.

Thanks a million!

_________________
s☼-£♦и̫͍ͥ̍ͪ͌̓͗͡о̡̹̱͊̅ͮ̓̕͢б̧̝̻̪̤̳̜͐̓̉ͤ͢͜ ͙̬͙̆̑ͮ̐ͭ̾̂́͘i̎̌̾̓̽̀̈̓̀҉͉̙̦͎̘̝͕f̻͕͔̘ͣͣ̓͊̿͢͜ ͍͔͈͕̮̫ͣ̆ͮ̊͋/♂6Æ!♪╩"▲L└уͭ̂͐̇҉̴̣̼̞̠̯͓̺̞ф̜̊͌̈́̋̏̐́ц̨͔̮̿̇ ̨̛͖̙͖̖̮̗̱ͩ̆͞ͅа̥͇̞̖͚̟̅͐ͤ͞͠͠э̜̘̩̳̬͔̾ͯ̀ͫ̒̐̿ͅͅг̭̖̀ͦ̒̑ͥ̌ͮͫ͞ё͔̟̃ͬ̾̓͟ё̦̞̙̫͔̩͑̀͂ͯ̄̔̃̑̀͠ͅͅ


Top
   
 Post subject: Re: Question about how I'm passing a stack from js to python
PostPosted: Sun Apr 03, 2011 10:03 pm 
Offline
DBB Master
DBB Master
User avatar

Joined: Sun Sep 05, 1999 2:01 am
Posts: 6377
Location: ☃☃☃
Isaac wrote:
And the android browser. I'll have to get more information, though I think I've got all that on Google Analytics. I don't get much traffic so it's easy for me sort out who's who.


I'm a luddite--I still own a flip phone. :P

The most common time people use multiple POST parameters with the same name is when they use checklists. The idiom is to give every checkbox in the same list the same name. That way your framework gives you a nice list-like data structure with all of the checked items, which is natural to work with. Giving multiple text fields the same name is more unusual. I've never done it myself, and it might be a code path that isn't well-tested on some browsers. Still, I'm suspicious that there isn't something more going on.

Isaac wrote:
It's actually a single CGI file that imports a main module, which imports a sub module, then imports another submodule, and so on. So it's just one python script that grows depending on what string it's fed. It's probably a bad way of doing things.


I mean, what kind of file is your CGI script generating, i.e., does it have an XHTML doctype?

Isaac wrote:
You're right. I'll be use forms like this from now on.


I still hope you're interested in getting to the bottom of this.

Isaac wrote:
So I can do something like:
mystring="""Once upon a time""" """ there was a rabbit""" """ named thunder."""


Code:
>>> 'a' 'b' 'c'
'abc'


:P

edit:

You also technically need a <div></div> tag (or some other block element) to wrap the input tags inside of the form, although I doubt this would cause the problem. In general though, you want to make sure that your generated html validates (validator.w3.org) before trying to debug weird issues with it.


Top
   
 Post subject: Re: Question about how I'm passing a stack from js to python
PostPosted: Sun Apr 03, 2011 10:06 pm 
Offline
DBB Master
DBB Master
User avatar

Joined: Sun Sep 05, 1999 2:01 am
Posts: 6377
Location: ☃☃☃
Also, I think you don't mean to say "stack" here--maybe just "list" or "array." A stack in Computer Science is a specific kind of list or array where the last thing you put in is the first thing that gets taken out (I use this data structure to decide which clothes on my floor to wear in the morning ;)).


Top
   
 Post subject: Re: Question about how I'm passing a stack from js to python
PostPosted: Mon Apr 04, 2011 5:31 am 
Offline
DBB Artist
DBB Artist
User avatar

Joined: Mon Aug 01, 2005 8:47 am
Posts: 7124
Location: Ơ̸̦͇̲̬̭̱̰͎̞͈̣͎͚̳ͬ͋̃̀̇͊͂͋͐ͦ̽ͣ̂ͥ͊̅̀̚͠ B̶͖̯͉̜̰̲̓̔͋̈́ͅ È̯ Y̪̤̼͉̠̙͝
Ah, thanks. I'll remember that.

_________________
s☼-£♦и̫͍ͥ̍ͪ͌̓͗͡о̡̹̱͊̅ͮ̓̕͢б̧̝̻̪̤̳̜͐̓̉ͤ͢͜ ͙̬͙̆̑ͮ̐ͭ̾̂́͘i̎̌̾̓̽̀̈̓̀҉͉̙̦͎̘̝͕f̻͕͔̘ͣͣ̓͊̿͢͜ ͍͔͈͕̮̫ͣ̆ͮ̊͋/♂6Æ!♪╩"▲L└уͭ̂͐̇҉̴̣̼̞̠̯͓̺̞ф̜̊͌̈́̋̏̐́ц̨͔̮̿̇ ̨̛͖̙͖̖̮̗̱ͩ̆͞ͅа̥͇̞̖͚̟̅͐ͤ͞͠͠э̜̘̩̳̬͔̾ͯ̀ͫ̒̐̿ͅͅг̭̖̀ͦ̒̑ͥ̌ͮͫ͞ё͔̟̃ͬ̾̓͟ё̦̞̙̫͔̩͑̀͂ͯ̄̔̃̑̀͠ͅͅ


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic  [ 7 posts ] 

All times are UTC-06:00


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  



Descent'rs have piloted these pages
 
The layout and contents contained within this site are © DescentBB.net 1997-2006.
Descent, Descent II are © Parallax Software Corporation.
Descent III is Outrage Entertainment.
Descent is a Trademark of Interplay Productions.

Miner Wars™ is trademark of Keen Software House s. r. o.
.


Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group