[Zope] Extracting just the string of the zope file or dtml object
Andy Bulka
abulka@netspace.net.au
Mon, 10 Sep 2001 21:48:19 +1000
How do I ensure that the string *contents* of my Zope object is passed to an
external method, rather than passing the zope object itself?
E.g. if
mydtmldoc is a DTML document with plain text inside it
myFile is a file object with content-type plain text
then when I call
<dtml-call "ProcessAstring1('a literal string')">
<dtml-call "ProcessAstring1(mydtmldoc)">
<dtml-call "ProcessAstring1(myFile)">
I get
Got string
Got DTML Document
Got File
respectively in my external method. I really just want the string contents
of these zope objects. I want to be able to do all sortd of string
operations on them - but this is not working since python complains they are
not strings. My test external method is simply
def ProcessAstring(astr):
print 'Got', safetest(astr) # safetest I got off this mailing list, and
is listed below
How do I just get at the string being passed? Or how do I just pass the raw
string?
thanks
Andy Bulka
-----------------------------
def safetest(object):
if object is None:
return 'None'
s = str(object)
if object==s:
return 'string'
try:
t = object.meta_type
return t
except:
pass
try:
l = len(object)
if s[0]=='[': return 'list'
if s[0]=='(': return 'tuple'
if s[0]=='{': return 'dict'
return 'sequence'
except:
pass
try:
t = object.timeTime()
return 'DateTime'
except:
pass
try:
val = int(object)
if val is object:
return 'integer'
return 'number'
except:
return 'unknown'