[Zope] parsing strings in DTML

2000-06-26 Thread Timothy Wilson

Hi everyone,

I'm working on what should be a simple problem.

I pulling an address out of an ldap query and the data is in the form of a
$-separated string. Example:

101 Main St.$Anytown$MN$12345

Please correct me if I'm wrong, but I could probably do dtml-call
"REQUEST.set('parsed_address', _.string.join(old_address, '$')" except for
the fact that getting "old_address" (the $-separated one) would require its
own dtml-var old_address statement. I can't nest dtmls so how to I
combine these?

Second question... Once I've got my string parsed into a list called
"parsed_string", what's the syntax for accessing certain elements of the
list?

Thanks.

-Tim

P.S. Maybe I should do this in an external or python method, but I thought
it would be overkill for a single operation like this. Am I wrong?

--
Tim Wilson  | Visit Sibley online: | Check out:
Henry Sibley HS | http://www.isd197.k12.mn.us/ | http://www.zope.org/
W. St. Paul, MN |  | http://slashdot.org/
[EMAIL PROTECTED] |   dtml-var pithy_quote | http://linux.com/


___
Zope maillist  -  [EMAIL PROTECTED]
http://lists.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://lists.zope.org/mailman/listinfo/zope-announce
 http://lists.zope.org/mailman/listinfo/zope-dev )




Re: [Zope] parsing strings in DTML

2000-06-26 Thread R. David Murray

On Mon, 26 Jun 2000, Timothy Wilson wrote:
 "REQUEST.set('parsed_address', _.string.join(old_address, '$')" except for

This is exactly correct.  Inside the quotes you are in python, and
so you can reference variables from the namespace by their unadorned name.

 Second question... Once I've got my string parsed into a list called
 "parsed_string", what's the syntax for accessing certain elements of the
 list?

parsed_string[0], parsed_string[1], ...  (inside an expr, of course).

--RDM


___
Zope maillist  -  [EMAIL PROTECTED]
http://lists.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://lists.zope.org/mailman/listinfo/zope-announce
 http://lists.zope.org/mailman/listinfo/zope-dev )




Re: [Zope] parsing strings in DTML

2000-06-26 Thread Rik Hoekstra



I'm working on what should be a simple problem.

I pulling an address out of an ldap query and the data is in the form of a
$-separated string. Example:

101 Main St.$Anytown$MN$12345

Please correct me if I'm wrong, but I could probably do dtml-call
"REQUEST.set('parsed_address', _.string.join(old_address, '$')" except for
the fact that getting "old_address" (the $-separated one) would require its
own dtml-var old_address statement. I can't nest dtmls so how to I
combine these?


I'm not sure I get you right.
try something like (untested):

dtml-call "REQUEST.set('parse_address', _string.split(old_address, '$')"

for parsing the string


Second question... Once I've got my string parsed into a list called
"parsed_string", what's the syntax for accessing certain elements of the
list?

By slicing:

dtml-call "parsed_string[0]"

gets you the first element parsed_string[1] the second etc

parsed_string[1:] is everything after the second ;-) element of the list

parsed_string[:5] is everything up to element 6

parsed_string[1:5]  is everything from element 2 to element 6

parsed_string[-1] is the last element of the list.

If you want to know more, you should probably look at the Python docs, as
this is Python stuff.


P.S. Maybe I should do this in an external or python method, but I thought
it would be overkill for a single operation like this. Am I wrong?


No, I think you're right, but others may disagree.


hth

Rik


___
Zope maillist  -  [EMAIL PROTECTED]
http://lists.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://lists.zope.org/mailman/listinfo/zope-announce
 http://lists.zope.org/mailman/listinfo/zope-dev )




Re: [Zope] parsing strings in DTML

2000-06-26 Thread Timothy Wilson

On Mon, 26 Jun 2000, Rik Hoekstra wrote:

 Please correct me if I'm wrong, but I could probably do dtml-call
 "REQUEST.set('parsed_address', _.string.join(old_address, '$')" except for
 the fact that getting "old_address" (the $-separated one) would require its
 own dtml-var old_address statement. I can't nest dtmls so how to I
 combine these?
 
 I'm not sure I get you right.
 try something like (untested):
 
 dtml-call "REQUEST.set('parse_address', _string.split(old_address, '$')"

You're right, of course, about the "split." A slip of the typing fingers.
:-)

 If you want to know more, you should probably look at the Python docs, as
 this is Python stuff.

Doing this in Python is easy. That's not the problem. I've been struggling
with all of the RESPONSE.set, REQUEST.set, etc. stuff. I can't keep it all
straight. Adding the dtml layer to this really adds to the comlexity of it
all. I just need more Zen. :-)

Thanks for the help.

-Tim

--
Tim Wilson  | Visit Sibley online: | Check out:
Henry Sibley HS | http://www.isd197.k12.mn.us/ | http://www.zope.org/
W. St. Paul, MN |  | http://slashdot.org/
[EMAIL PROTECTED] |   dtml-var pithy_quote | http://linux.com/


___
Zope maillist  -  [EMAIL PROTECTED]
http://lists.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://lists.zope.org/mailman/listinfo/zope-announce
 http://lists.zope.org/mailman/listinfo/zope-dev )




Re: [Zope] parsing strings in DTML

2000-06-26 Thread Timothy Wilson

On Mon, 26 Jun 2000, Rik Hoekstra wrote:

 try something like (untested):
 
 dtml-call "REQUEST.set('parse_address', _string.split(old_address, '$')"
 
 for parsing the string

But what if "parse_address" comes from a SQL query? Like this:

dtml-in qry_contactInfo
  dtml-call "REQUEST.set(dtml-var parse_address, ... etc.

Don't I run into trouble with nested DTML here?

-Tim

--
Tim Wilson  | Visit Sibley online: | Check out:
Henry Sibley HS | http://www.isd197.k12.mn.us/ | http://www.zope.org/
W. St. Paul, MN |  | http://slashdot.org/
[EMAIL PROTECTED] |   dtml-var pithy_quote | http://linux.com/


___
Zope maillist  -  [EMAIL PROTECTED]
http://lists.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://lists.zope.org/mailman/listinfo/zope-announce
 http://lists.zope.org/mailman/listinfo/zope-dev )




Re: [Zope] parsing strings in DTML

2000-06-26 Thread Bill Anderson

Timothy Wilson wrote:
 
 On Mon, 26 Jun 2000, Rik Hoekstra wrote:
 
  try something like (untested):
 
  dtml-call "REQUEST.set('parse_address', _string.split(old_address, '$')"
 
  for parsing the string
 
 But what if "parse_address" comes from a SQL query? Like this:
 
 dtml-in qry_contactInfo
   dtml-call "REQUEST.set(dtml-var parse_address, ... etc.
 
 Don't I run into trouble with nested DTML here?


Untested, but should be correct:

 dtml-in qry_contactInfo
   dtml-call "REQUEST.set(_['parse_address'], ... etc.

___
Zope maillist  -  [EMAIL PROTECTED]
http://lists.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://lists.zope.org/mailman/listinfo/zope-announce
 http://lists.zope.org/mailman/listinfo/zope-dev )




Re: [Zope] parsing strings in DTML

2000-06-26 Thread Jeff K. Hoffman

On Mon, 26 Jun 2000, Timothy Wilson wrote:

 On Mon, 26 Jun 2000, Rik Hoekstra wrote:
 
  try something like (untested):
  
  dtml-call "REQUEST.set('parse_address', _string.split(old_address, '$')"
  
  for parsing the string
 
 But what if "parse_address" comes from a SQL query? Like this:
 
 dtml-in qry_contactInfo
   dtml-call "REQUEST.set(dtml-var parse_address, ... etc.
 
 Don't I run into trouble with nested DTML here?

You should never "nest" DTML like you are suggesting. It won't work.

Variables set through REQUEST.set are immediately accessable in DTML
expressions after it, i.e.:

  dtml-call expr="REQUEST.set('i', 0)"
  dtml-var i
  dtml-call expr="REQUEST.set('i', i + 1)"
  dtml-var i

Notice all I did was "i + 1", not "dtml-var i + 1". You simply reference
it, as you would in python.

 -Tim

--Jeff

---
Jeff K. Hoffman   704.849.0731 x108
Chief Technology Officer  mailto:[EMAIL PROTECTED]
Going Virtual, L.L.C. http://www.goingv.com/


___
Zope maillist  -  [EMAIL PROTECTED]
http://lists.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://lists.zope.org/mailman/listinfo/zope-announce
 http://lists.zope.org/mailman/listinfo/zope-dev )