Re: Insane Problem

2009-12-04 Thread Victor Subervi
On Thu, Dec 3, 2009 at 7:07 PM, Steven D'Aprano 
st...@remove-this-cybersource.com.au wrote:

 On Thu, 03 Dec 2009 10:13:14 -0500, Carsten Haese wrote:

  Victor Subervi wrote:
  I believe I mentioned in my first post that the print test does print
  the exact fields being called from the referring page.
 
  Was any part of What do the print statements actually print? Please
  copy and paste their output. unclear to you in any way?
 
  Perhaps this
  is a bug in the cgi interface?
 
  Unlikely.
 
  It's much more likely that whatever frankencode you stitched together
  from examples you found on the internet without understanding how they
  work is doing something unexpected, and you are unable to diagnose the
  problem because you don't understand how your code works.

 Oh come on, how likely is that??? It's much more likely that the original
 poster has discovered a bug in the standard library that thousands of
 users before him never noticed!

 *wink*


Please don't be rude. I never suggested that, but only said that there may
be a possibility that there was some problem, and in the context I wrote it,
it was perfectly obvious, because I made it so, that I was pulling at
straws.

I might not be as good a programmer as you, but I'm not rude, and that makes
me a better person. You can't take your programming with you when you die,
but I can take my pure, peaceful and joy-filled soul with me. Think about
that and don't be rude.
V
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Insane Problem

2009-12-04 Thread Terry Reedy

Victor Subervi wrote:

I'm not rude


To me, asking for help without providing sufficient information, 
especially when requested, is a form of rudeness.



Think about that and don't be rude.


Exactly.

Terry Jan Reedy

--
http://mail.python.org/mailman/listinfo/python-list


Re: Insane Problem

2009-12-04 Thread Lie Ryan

On 12/5/2009 8:27 AM, Terry Reedy wrote:

Victor Subervi wrote:

I'm not rude


To me, asking for help without providing sufficient information,
especially when requested, is a form of rudeness.


Think about that and don't be rude.


Why does this sounds familiar?
http://groups.google.com/group/comp.lang.python/msg/21e80ac383745d88
--
http://mail.python.org/mailman/listinfo/python-list


Re: Insane Problem

2009-12-03 Thread Victor Subervi
On Wed, Dec 2, 2009 at 4:08 PM, MRAB pyt...@mrabarnett.plus.com wrote:

 Victor Subervi wrote:

 Hi;
 I have spent 2-3 hours trying to track this bug. Here's the code snippet:

  form = cgi.FieldStorage()
  fn = getattr(options, 'products')
  ourOptionsNames = []
  optionsNames, doNotUse  = fn('names')
  for name in optionsNames:
test = table + '-' + name
print test
check = form.getfirst(test, '')
print check
if check != '':
  ourOptionsNames.append(name)
  Now, when it looks through with test=='products', it doesn't report that
 any of the values from the form are checked. However, when I explicitly
 write out something like:
 print form.getfirst('products-sizes', '')
 which I checked on the form from the referring page, it does in fact print
 out! My test prints show that 'products-sizes' is being passed to check
 and should therefore be appended to ourOptionsNames. But it isn't! What am
 I missing here??

  What do the print statements actually print? Please copy and paste their
 output.


For the part in question they print __nothing__. That's the point.
V
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Insane Problem

2009-12-03 Thread Victor Subervi
On Thu, Dec 3, 2009 at 6:07 AM, Victor Subervi victorsube...@gmail.comwrote:

 On Wed, Dec 2, 2009 at 4:08 PM, MRAB pyt...@mrabarnett.plus.com wrote:

 Victor Subervi wrote:

 Hi;
 I have spent 2-3 hours trying to track this bug. Here's the code snippet:

  form = cgi.FieldStorage()
  fn = getattr(options, 'products')
  ourOptionsNames = []
  optionsNames, doNotUse  = fn('names')
  for name in optionsNames:
test = table + '-' + name
print test
check = form.getfirst(test, '')
print check
if check != '':
  ourOptionsNames.append(name)
  Now, when it looks through with test=='products', it doesn't report that
 any of the values from the form are checked. However, when I explicitly
 write out something like:
 print form.getfirst('products-sizes', '')
 which I checked on the form from the referring page, it does in fact
 print out! My test prints show that 'products-sizes' is being passed to
 check and should therefore be appended to ourOptionsNames. But it isn't!
 What am I missing here??

  What do the print statements actually print? Please copy and paste their
 output.


 For the part in question they print __nothing__. That's the point.
 V

I believe I mentioned in my first post that the print test does print the
exact fields being called from the referring page. The print check prints
nothing. Another thing that's strange is that there are two tables of fields
in the referrer page; it will print the first of those tables--whichever of
the two I choose--but not the latter. Perhaps this is a bug in the cgi
interface? Perhaps I should migrate this to mod_python?
TIA,
V
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Insane Problem

2009-12-03 Thread Victor Subervi
On Thu, Dec 3, 2009 at 8:02 AM, Victor Subervi victorsube...@gmail.comwrote:

 On Thu, Dec 3, 2009 at 6:07 AM, Victor Subervi victorsube...@gmail.comwrote:

 On Wed, Dec 2, 2009 at 4:08 PM, MRAB pyt...@mrabarnett.plus.com wrote:

 Victor Subervi wrote:

 Hi;
 I have spent 2-3 hours trying to track this bug. Here's the code
 snippet:

  form = cgi.FieldStorage()
  fn = getattr(options, 'products')
  ourOptionsNames = []
  optionsNames, doNotUse  = fn('names')
  for name in optionsNames:
test = table + '-' + name
print test
check = form.getfirst(test, '')
print check
if check != '':
  ourOptionsNames.append(name)
  Now, when it looks through with test=='products', it doesn't report
 that any of the values from the form are checked. However, when I 
 explicitly
 write out something like:
 print form.getfirst('products-sizes', '')
 which I checked on the form from the referring page, it does in fact
 print out! My test prints show that 'products-sizes' is being passed to
 check and should therefore be appended to ourOptionsNames. But it 
 isn't!
 What am I missing here??

  What do the print statements actually print? Please copy and paste
 their
 output.


 For the part in question they print __nothing__. That's the point.
 V

 I believe I mentioned in my first post that the print test does print the
 exact fields being called from the referring page. The print check prints
 nothing. Another thing that's strange is that there are two tables of fields
 in the referrer page; it will print the first of those tables--whichever of
 the two I choose--but not the latter. Perhaps this is a bug in the cgi
 interface? Perhaps I should migrate this to mod_python?
 TIA,
 V

Perhaps the following code, which is from the referrer, will help. I don't
see how it makes any difference at all, since all the code is printed
between the opening form and the submit button:

#!/usr/bin/python

import cgitb; cgitb.enable()
import MySQLdb
import cgi
import sys,os
sys.path.append(os.getcwd())
from login import login
import string
import options
from particulars import optionsTables, addStore

def chooseOptions():
  print '''Content-Type: text/html\r\n
!DOCTYPE html PUBLIC -//W3C//DTD HTML 4.01 Transitional//EN
html
form action='chooseOptions2.py' method='post'
'''
  storesTables = []
  junkStores = string.join(addStore(), ', ')
  for table in optionsTables():
if table not in ('particulars', junkStores):
  storesTables.append(table)
  bgcolors = ['F2F6D3', 'F2DDD3', 'D7DDD3']
  myOptions = []
  myMeanings = []
  for table in storesTables:
try:
  fn = getattr(options, table)
  opts, means = fn('names')
  myOptions.append(opts)
  myMeanings.append(means)
except:
  pass
  i = 0
  print font size='4'bPlease select which of the option groups below
you would like to associate with each store. On the next page, you will have
the opportunity to select which options within each option group you would
like to have in your selection for each store./b/fontbr /br /
  for table in storesTables:
print table align='center' bgcolor='#%s' border='1'\n tr\n  td
colspan='3'\n % bgcolors[i]
print h1 align='center'%s/h1\n  /td\n /tr\n %
(table[0].upper() + table[1:])
print  tr\n  td align='center'bOption/b/td\n  td
align='center'bDefinition/b/td\n  td
align='center'bCheck/b/td\n /tr\n
j = 0
while j  len(myOptions[0]):
  print  tr\n  td%s/td\n  td%s/td\n  td
align='center'input type='checkbox' name='%s' //td\n /tr\n %
(myOptions[0][j], myMeanings[0][j], table + '-' + myOptions[0][j])
  j += 1
print /tablebr /br /\n
i += 1
  print '''
div align='center'
input type='submit' value=' Send ' /
/div
/form
/body
/html'''

chooseOptions()

TIA,
V
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Insane Problem

2009-12-03 Thread Carsten Haese
Victor Subervi wrote:
 I believe I mentioned in my first post that the print test does print
 the exact fields being called from the referring page.

Was any part of What do the print statements actually print? Please
copy and paste their output. unclear to you in any way?

 Perhaps this
 is a bug in the cgi interface?

Unlikely.

It's much more likely that whatever frankencode you stitched together
from examples you found on the internet without understanding how they
work is doing something unexpected, and you are unable to diagnose the
problem because you don't understand how your code works.

In order to help you diagnose the problem, we need to see the *exact*
code you're running, we need to see the *exact* inputs going into it,
and we need to see the *exact* output coming out of it.

--
Carsten Haese
http://informixdb.sourceforge.net

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Insane Problem

2009-12-03 Thread Victor Subervi
On Thu, Dec 3, 2009 at 10:13 AM, Carsten Haese carsten.ha...@gmail.comwrote:

 Victor Subervi wrote:
  I believe I mentioned in my first post that the print test does print
  the exact fields being called from the referring page.

 Was any part of What do the print statements actually print? Please
 copy and paste their output. unclear to you in any way?


products-sizes

products-colorsShadesNumbersShort

products-colorsNamesNumbers

products-colorsShadesNumbers


The very fact that, as I stated earlier, I can get the cgi calls from the
table in question to print by forcing the absence of the other, I believe,
is proof positive that it's not what you think it is. Sorry for the
misunderstanding.


  Perhaps this
  is a bug in the cgi interface?

 Unlikely.

 It's much more likely that whatever frankencode you stitched together
 from examples you found on the internet without understanding how they
 work is doing something unexpected, and you are unable to diagnose the
 problem because you don't understand how your code works.


Frankencode? Please don't be rude.



 In order to help you diagnose the problem, we need to see the *exact*
 code you're running, we need to see the *exact* inputs going into it,
 and we need to see the *exact* output coming out of it.


Let's see your answers and see if you're right that the above output helps
you arrive at the correct conclusion.
TIA,
V
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Insane Problem

2009-12-03 Thread Carsten Haese
Victor Subervi wrote:
 In order to help you diagnose the problem, we need to see the *exact*
 code you're running, we need to see the *exact* inputs going into it,
 and we need to see the *exact* output coming out of it.
 
 
 Let's see your answers and see if you're right that the above output
 helps you arrive at the correct conclusion.

No, it doesn't, because you've only provided one third of what I asked
for. I also asked for the code and the inputs that go into it.

--
Carsten Haese
http://informixdb.sourceforge.net

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Insane Problem

2009-12-03 Thread Victor Subervi
On Thu, Dec 3, 2009 at 10:53 AM, Carsten Haese carsten.ha...@gmail.comwrote:

 Victor Subervi wrote:
  In order to help you diagnose the problem, we need to see the *exact*
  code you're running, we need to see the *exact* inputs going into it,
  and we need to see the *exact* output coming out of it.
 
 
  Let's see your answers and see if you're right that the above output
  helps you arrive at the correct conclusion.

 No, it doesn't, because you've only provided one third of what I asked
 for. I also asked for the code and the inputs that go into it.


I provided those earlier. To be sure I don't miss anything that may be
important, here is the entire code for chooseOptions.py, the referrer. What
I consider to be the important code is between the SNIPPETS:

#!/usr/bin/python

import cgitb; cgitb.enable()
import MySQLdb
import cgi
import sys,os
sys.path.append(os.getcwd())
from login import login
import string
import options
from particulars import optionsTables, addStore

def chooseOptions():
  print '''Content-Type: text/html\r\n
!DOCTYPE html PUBLIC -//W3C//DTD HTML 4.01 Transitional//EN
html
form action='chooseOptions2.py' method='post'
'''
  storesTables = []
  junkStores = string.join(addStore(), ', ')
  for table in optionsTables():
if table not in ('particulars', junkStores):
  storesTables.append(table)
  bgcolors = ['F2F6D3', 'F2DDD3', 'D7DDD3']
  myOptions = []
  myMeanings = []

SNIPPET

  for table in storesTables:
try:
  fn = getattr(options, table)
  opts, means = fn('names')
  myOptions.append(opts)
  myMeanings.append(means)
except:
  pass

/SNIPPET

  i = 0
  print font size='4'bPlease select which of the option groups below
you would like to associate with each store. On the next page, you will have
the opportunity to select which options within each option group you would
like to have in your selection for each store./b/fontbr /br /

SNIPPET

  for table in storesTables:
print table align='center' bgcolor='#%s' border='1'\n tr\n  td
colspan='3'\n % bgcolors[i]
print h1 align='center'%s/h1\n  /td\n /tr\n %
(table[0].upper() + table[1:])
print  tr\n  td align='center'bOption/b/td\n  td
align='center'bDefinition/b/td\n  td
align='center'bCheck/b/td\n /tr\n
j = 0
while j  len(myOptions[0]):
  print  tr\n  td%s/td\n  td%s/td\n  td
align='center'input type='checkbox' name='%s' //td\n /tr\n %
(myOptions[0][j], myMeanings[0][j], table + '-' + myOptions[0][j])
  j += 1
print /tablebr /br /\n
i += 1

SNIPPET

  print '''
div align='center'
input type='submit' value=' Send ' /
/div
/form
/body
/html'''

chooseOptions()


Here is the pared-down code (to the products) from options.py:

def products(which='', specificTables=[]):
  code = []
  names = []
  meanings = []
  code.append(['Extra-small', 'Small', 'Medium', 'Large', 'XLarge',
'XXLarge', 'XXXLarge'])
  meanings.append('The standard sizes.')
  names.append('sizes')
  if which == 'names':
for name in colors('products', 'names'):
  names.append(name)
for meaning in colors('products', 'meanings'):
  meanings.append(meaning)
return names, meanings
  elif which == 'specificTables':
whichTablesToReturn = []
colorsTables, colorsNames = colors('products', 'specificTables',
specificTables)
for name in colorsNames:
  names.append(name)
for table in colorsTables:
  code.append(table)
i = 0
while i  len(names): # We utilize the name of the table to determine
where it is in the code tuple
  for table in specificTables:
if names[i] == table:
  whichTablesToReturn.append(i)
  i += 1
returnTheseTables = []
for table in whichTablesToReturn:
  returnTheseTables.append(code[table])
returnTheseNames = []
for table in whichTablesToReturn:
  returnTheseNames.append(names[table])
i = 0
all = ''
table = ''
while i  len(returnTheseNames):
  table += table border='1'\n tr\n  td colspan='16'
align='center'b%s/b/td\n /tr % returnTheseNames[i]
  j = 0
  for elt in code[i]:
if (j + 8) % 8 == 0:
  table += ' tr\n'
table += '  td%s/td\n' % code[i][j]
table +=   tdinput type='checkbox' name='%s' value='%s' //td
% (returnTheseNames[i], returnTheseTables[i][j])
if (j + 1) % 8 == 0:
  table += ' /tr\n'
j += 1
  if table[-6:] != '/tr\n':
table += ' /tr\n'
  table += '/table\n'
  all += table + 'br /br /'
  i += 1
print all
  else:
i = 0
all = ''
if which != '': # I place a dummy value in here to get what I want
  ourCode = []
  ourMeanings = []
  ourNames = specificTables
  i = 0
  for name in names:
for check in ourNames:
  if name == check:
ourCode.append(code[i])
ourMeanings.append(meanings[i])
i += 1
else:
  ourCode = code
  ourMeanings = meanings
  ourNames = names
ourColors = []
  

Re: Insane Problem

2009-12-03 Thread Carsten Haese
Victor Subervi wrote:
 No, it doesn't, because you've only provided one third of what I asked
 for. I also asked for the code and the inputs that go into it.
 
 
 I provided those earlier.

No, you didn't provide the exact code you're running. You provided a
selected snippet you deemed important, but because you don't actually
know what the problem is and where it is, your determination of what's
important is not helpful. You actually managed to snip away the part
that causes the problem.

The code snipped you posted earlier showed cgi.FieldStorage being called
once. The code you're posting now makes it clear that cgi.FieldStorage
is actually called multiple times in a loop:

 [snip...]
 def optionsPrintout(table):
   form = cgi.FieldStorage()
   fn = getattr(options, table)
   ourOptionsNames = []
   optionsNames, doNotUse  = fn('names')
 
 [snip...]

   for table in storesTables:
   [snip...]
   print optionsPrintout(table)
   [snip ...]

The problem is that the first call to cgi.FieldStorage() consumes all
POST variables that were given to the script, so any subsequent call
reads an empty file and results in an empty FieldStorage object. Rewrite
your code to construct the FieldStorage object once and refer to that
one object in every pass of the loop.

As you can see, and as I suspected, it's not a bug in the cgi module.

--
Carsten Haese
http://informixdb.sourceforge.net

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Insane Problem

2009-12-03 Thread Victor Subervi
On Thu, Dec 3, 2009 at 12:38 PM, Carsten Haese carsten.ha...@gmail.comwrote:

 Victor Subervi wrote:
  No, it doesn't, because you've only provided one third of what I
 asked
  for. I also asked for the code and the inputs that go into it.
 
 
  I provided those earlier.

 No, you didn't provide the exact code you're running. You provided a
 selected snippet you deemed important, but because you don't actually
 know what the problem is and where it is, your determination of what's
 important is not helpful. You actually managed to snip away the part
 that causes the problem.

 The code snipped you posted earlier showed cgi.FieldStorage being called
 once. The code you're posting now makes it clear that cgi.FieldStorage
 is actually called multiple times in a loop:

  [snip...]
  def optionsPrintout(table):
form = cgi.FieldStorage()
fn = getattr(options, table)
ourOptionsNames = []
optionsNames, doNotUse  = fn('names')
 
  [snip...]
 
for table in storesTables:
[snip...]
print optionsPrintout(table)
[snip ...]

 The problem is that the first call to cgi.FieldStorage() consumes all
 POST variables that were given to the script, so any subsequent call
 reads an empty file and results in an empty FieldStorage object. Rewrite
 your code to construct the FieldStorage object once and refer to that
 one object in every pass of the loop.

 As you can see, and as I suspected, it's not a bug in the cgi module.


Thank you! Well, I suspected it wasn't a bug either, but I was at my wit's
end and pulling straws.
Thanks again!
V
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Insane Problem

2009-12-03 Thread Steven D'Aprano
On Thu, 03 Dec 2009 10:13:14 -0500, Carsten Haese wrote:

 Victor Subervi wrote:
 I believe I mentioned in my first post that the print test does print
 the exact fields being called from the referring page.
 
 Was any part of What do the print statements actually print? Please
 copy and paste their output. unclear to you in any way?
 
 Perhaps this
 is a bug in the cgi interface?
 
 Unlikely.
 
 It's much more likely that whatever frankencode you stitched together
 from examples you found on the internet without understanding how they
 work is doing something unexpected, and you are unable to diagnose the
 problem because you don't understand how your code works.

Oh come on, how likely is that??? It's much more likely that the original 
poster has discovered a bug in the standard library that thousands of 
users before him never noticed!

*wink*



-- 
Steven
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Insane Problem

2009-12-02 Thread MRAB

Victor Subervi wrote:

Hi;
I have spent 2-3 hours trying to track this bug. Here's the code snippet:

  form = cgi.FieldStorage()
  fn = getattr(options, 'products')
  ourOptionsNames = []
  optionsNames, doNotUse  = fn('names')
  for name in optionsNames:
test = table + '-' + name
print test
check = form.getfirst(test, '')
print check
if check != '':
  ourOptionsNames.append(name)
 
Now, when it looks through with test=='products', it doesn't report that 
any of the values from the form are checked. However, when I explicitly 
write out something like:

print form.getfirst('products-sizes', '')
which I checked on the form from the referring page, it does in fact 
print out! My test prints show that 'products-sizes' is being passed to 
check and should therefore be appended to ourOptionsNames. But it 
isn't! What am I missing here??



What do the print statements actually print? Please copy and paste their
output.
--
http://mail.python.org/mailman/listinfo/python-list