Form-Through-Script Nightmare

2007-08-14 Thread tonylabarbara
Hi;
I originally submitted this to the Zope list, but after no replies and 
realizing it's probably better suited for the python list, I'm submitting it 
here.


I have a form where purchasers can deselect items they've added to their 
shopping cart. All the hidden fields have been numbered according to the items 
they *originally* selected. If they deselect an item, then it will probably 
necessitate a renumbering of all those hidden fields, since PayPal doesn't 
tolerate misnumbering: everything must be numbered "1" for all the hidden 
fields of the first product, "2" for the second, etc. If the customer selects 5 
products and deletes the 3rd, then I need to renumber. I wrote a script that 
can do that. Now, I have to send the form to that script, with all its lovely 
hidden fields, then reproduce it somewhere so I can send it off to PP. That is, 
the form must return from the called script to a new page and deliver all the 
renumbered hidden fields. 

?

Let me summarize what I've written before to put in one post exactly what's 
going on:


1)?I have a form that I need to send to a script and then send off to a URL 
(PayPal). I need to process it through the script to renumber things for PP. 
How do I do this? I imagine I add an element to the PT like so:



but I need to pass a parameter "doc", which, of course, is the document I'm 
submitting. So I tried this:




which renders my page fine, but throws an error when I submit the form:

Cannot locate object at: 
http://example.com/s/c/x/j/en-us/s/renumberTheCart%28here

meaning, of course, that it didn't receive the required parameter.

2) I changed it to an absolute URL just to double-check, and got basically the 
same error:
?

Invalid request

The parameter, doc, was omitted from the request. 


How do I pass the parameter, which in my case is quite long and stashed neatly 
away in a PT macro?


http://example.com/s/renumberTheCart?doc=docs"; method="post">?
?



Now, Tom Von Lahndorff suggested the following:


Sounds like the script should check to see if the user is removing something 
like:






if remove

remove the item

redirect back to the udpated form page

else

send to PP




this way once the item is removed and the same script is called, since there's 
no remove this time, it'll go to PP.


I would LOVE to do that...if I knew how! Any ideas?
TIA,
Tony




?

Invalid request

The parameter, doc, was omitted from the request. 


How do I pass the parameter, which in my case is quite long and stashed neatly 
away in a PT macro?


http://example.com/s/renumberTheCart?doc=docs"; method="post">?
?



Now, Tom Von Lahndorff suggested the following:


Sounds like the script should check to see if the user is removing something 
like:






if remove

remove the item

redirect back to the udpated form page

else

send to PP




this way once the item is removed and the same script is called, since there's 
no remove this time, it'll go to PP.


I would LOVE to do that...if I knew how! Any ideas?
TIA,
Tony




AOL now offers free email to everyone.  Find out more about what's free from 
AOL at AOL.com.
-- 
http://mail.python.org/mailman/listinfo/python-list

Editing MS Word

2007-10-26 Thread tonylabarbara

Hi;

I'm trying to edit MS Word tables with a python script. Here's a snippet:

import string

def msw2htmlTables():

input = "/usr/home/me/test.doc"

input = open(input,'r')

word = "whatever"

inputFlag = 0

splitString = []

for line in input:

# Check first the inputFlag, since we only want to delete the top

if inputFlag == 0:

splitString = line.split(word)

try:

keep = splitString[1]

except:

keep = "nada"

print len(splitString)

inputFlag = 1

elif inputFlag == 1:

# This means we've deleted the top junk. Let's search for the bottom junk.

splitString = line.split(word)

try:

keep = splitString[0]

inputFlag = 2

print len(splitString)

except:

keep += line

elif inputFlag == 2:

# This means everything else is junk.

pass

Now, if var "word" is "orange", it will never pring the length of splitString. 
If it's "dark", it will. The only difference is the way they appear in the 
document. "orange" appears with a space character to the left and some MS 
garbage character to the right, while "dark" appears with a space character to 
the left and a comma to the right. Furthermore, if I use MSW junk characters as 
the definition of "word" (such as " Ù ", which is what I really need to 
search), it never even compiles (complains of an unpaired quote). It appears 
that python doesn't like MSW's junk characters. What shall I do?

TIA,

Tony


Email and AIM finally together. You've gotta check out free AOL Mail! - 
http://mail.aol.com
-- 
http://mail.python.org/mailman/listinfo/python-list

PIL Problem

2007-11-07 Thread tonylabarbara
Hi;
I´ve installed Zope 2.10.5 on top of Python 2.4.2 (not optimal, but it will 
work, according to the build instructions). I installed Plone 3.0.2 and I get 
errors when I crank up Zope, all related to a non-existent PIL. So I d/l/d the 
latest PIL, plopped it in my Extensions dir, ran this:


python setup.py build_ext -i

and got this:


running build_ext

building '_imagingtk' extension

creating build/temp.freebsd-5.5-RELEASE-i386-2.4/Tk

cc -fno-strict-aliasing -DNDEBUG -O -pipe -D__wchar_t=wchar_t 
-DTHREAD_STACK_SIZE=0x10 -fPIC -I/usr/local/include/freetype2 -IlibImaging 
-I/usr/local/include -I/usr/include -I/usr/local/include/python2.4 -c 
_imagingtk.c -o build/temp.freebsd-5.5-RELEASE-i386-2.4/_imagingtk.o

_imagingtk.c:20:16: tk.h: No such file or directory

_imagingtk.c:23: error: syntax error before '*' token

_imagingtk.c:31: error: syntax error before "Tcl_Interp"

_imagingtk.c: In function `_tkinit':

_imagingtk.c:37: error: `Tcl_Interp' undeclared (first use in this function)

_imagingtk.c:37: error: (Each undeclared identifier is reported only once

_imagingtk.c:37: error: for each function it appears in.)

_imagingtk.c:37: error: `interp' undeclared (first use in this function)

_imagingtk.c:45: error: syntax error before ')' token

_imagingtk.c:50: error: `app' undeclared (first use in this function)

_imagingtk.c: At top level:

_imagingtk.c:55: warning: parameter names (without types) in function 
declaration

_imagingtk.c:55: error: conflicting types for 'TkImaging_Init'

_imagingtk.c:23: error: previous declaration of 'TkImaging_Init' was here

_imagingtk.c:55: error: conflicting types for 'TkImaging_Init'

_imagingtk.c:23: error: previous declaration of 'TkImaging_Init' was here

_imagingtk.c:55: warning: data definition has no type or storage class

_imagingtk.c:57: error: syntax error before '&' token

error: command 'cc' failed with exit status 1

What do?
TIA,
Tony


running build_ext

building '_imagingtk' extension

creating build/temp.freebsd-5.5-RELEASE-i386-2.4/Tk

cc -fno-strict-aliasing -DNDEBUG -O -pipe -D__wchar_t=wchar_t 
-DTHREAD_STACK_SIZE=0x10 -fPIC -I/usr/local/include/freetype2 -IlibImaging 
-I/usr/local/include -I/usr/include -I/usr/local/include/python2.4 -c 
_imagingtk.c -o build/temp.freebsd-5.5-RELEASE-i386-2.4/_imagingtk.o

_imagingtk.c:20:16: tk.h: No such file or directory

_imagingtk.c:23: error: syntax error before '*' token

_imagingtk.c:31: error: syntax error before "Tcl_Interp"

_imagingtk.c: In function `_tkinit':

_imagingtk.c:37: error: `Tcl_Interp' undeclared (first use in this function)

_imagingtk.c:37: error: (Each undeclared identifier is reported only once

_imagingtk.c:37: error: for each function it appears in.)

_imagingtk.c:37: error: `interp' undeclared (first use in this function)

_imagingtk.c:45: error: syntax error before ')' token

_imagingtk.c:50: error: `app' undeclared (first use in this function)

_imagingtk.c: At top level:

_imagingtk.c:55: warning: parameter names (without types) in function 
declaration

_imagingtk.c:55: error: conflicting types for 'TkImaging_Init'

_imagingtk.c:23: error: previous declaration of 'TkImaging_Init' was here

_imagingtk.c:55: error: conflicting types for 'TkImaging_Init'

_imagingtk.c:23: error: previous declaration of 'TkImaging_Init' was here

_imagingtk.c:55: warning: data definition has no type or storage class

_imagingtk.c:57: error: syntax error before '&' token

error: command 'cc' failed with exit status 1

What do?
TIA,
Tony


Email and AIM finally together. You've gotta check out free AOL Mail! - 
http://mail.aol.com
-- 
http://mail.python.org/mailman/listinfo/python-list

Automatically Writing a Dictionary

2008-01-23 Thread tonylabarbara
Hi;
I have data in a file and I would like to write it to a dictionary, and then 
perform commands on it, something like this:


input = "/usr/local/machine-lang-trans/dictionary.txt"

input = open(input,'r')


dict = "{"
for line in input:
? tup = re.split(','line)
? dict += '"' + tup[0] +'":"' + tup[1] +'", '
dict += "}"
input.close()


Of course, that will just give me a string. How do I convert it to, or make 
from scratch, a dictionary of that?
TIA,
Tony


More new features than ever.  Check out the new AOL Mail ! - 
http://webmail.aol.com
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Automatically Writing a Dictionary

2008-01-25 Thread tonylabarbara


d = {}?
? for line in input:?
? key, value = line.split(',').rstrip('\n')?
? d[key] = value?



Thanks. That worked except for the rstrip. So I did this:


for line in input:

? line = string.rstrip(line, '\n')

? key, value = line.split(',')

? dictionary[key] = value



Thanks again,
Tony

-Original Message-
From: Tim Chase <[EMAIL PROTECTED]>
To: [EMAIL PROTECTED]
Cc: python-list@python.org
Sent: Wed, 23 Jan 2008 3:37 pm
Subject: Re: Automatically Writing a Dictionary



> input = "/usr/local/machine-lang-trans/dictionary.txt"?
> > input = open(input,'r')?
> > dict = "{"?
> for line in input:?
> ? tup = re.split(','line)?
> ? dict += '"' + tup[0] +'":"' + tup[1] +'", '?
> dict += "}"?
> input.close()?
> > > Of course, that will just give me a string. How do I convert?
> it to, or make from scratch, a dictionary of that??
?
Don't bother with the string (and as a side-note, it's bad style to mask the 
built-in dict() so I'll use "d"):?
?
? d = {}?
? for line in input:?
? key, value = line.split(',').rstrip('\n')?
? d[key] = value?
?
or even just?
?
? d = dict(line.split(',').rstrip('\n')?
? for line in input)?
?
using the aforementioned dict() function :-)?
?
You may want to clean it up a bit in case there are spurious leading/trailing 
spaces to be trimmed:?
?
? from string import strip?
? d = dict(map(strip, line.split(','))?
? for line in input)?
?
or even ignore lines with the wrong number of commas:?
?
? d = dict(map(strip, line.split(','))?
? for line in input?
? if line.count(',') == 1)?
?
or assume any extra commas are part of the value:?
?
? d = dict(map(strip, line.split(',',1))?
? for line in input?
? if line.count(',') > 0)?
?
HTH,?
?
-tkc?
?
?



More new features than ever.  Check out the new AOL Mail ! - 
http://webmail.aol.com
-- 
http://mail.python.org/mailman/listinfo/python-list