[Zope] HowTo Render txt-Files with LocalFS in PythonScript?

douwe@oberon.nl douwe@oberon.nl
Mon, 5 Aug 2002 12:44:30 +0200


Hi,

Just to clarify, you have a .txt file and you want it to be rendered as if
it was a DTML file with LocalFS.

If so, I don' think that is going to work. See, the LocalFS product does
not know the types of the files it serves, so it tries to guess them and
then creates a wrapper object around the file to expose the functionality
of the zope object normally associated with the object. Anyway, if it sees
a .txt file, it will produce a file object (print the meta_type), if it
would serve a .dtml file, it would serve a dtml object. So, in your case
it serves a file object, which does not support the render method __call__

You could solve this by either renaming your file to .dtml, or you might
have a try and change the type_map property of your localFS instance.
associating
.txt files with DTMLMethod/Document should make localFS produce the right
kind of objects.

Douwe

> -----Original Message-----
> From: zope-admin@zope.org [mailto:zope-admin@zope.org]On Behalf Of Elena
> Schulz
> Sent: Monday, August 05, 2002 12:01 PM
> To: zope@zope.org
> Subject: [Zope] HowTo Render txt-Files with LocalFS in PythonScript?
>
>
> Dear List,
>
> with the following PythonScript I try to render the content of txt-Files
> with LocalFS according to the howto of LocalFS (...snip..." To insert the
> text of the file after evaluating it as a DTML template in the current
> namespace, you would use:  <dtml-var "test['foo.dtml'](_.None, _)">
> .....snip ...").
>
> My Script:
>
> ## Script (Python) "getContentFiles"
> ##bind container=container
> ##bind context=context
> ##bind namespace=_
> ##bind script=script
> ##bind subpath=traverse_subpath
> ##parameters=REQUEST=None,myLFSInstance
> ##title=
>
> myLFS = getattr(context, myLFSInstance)
> print myLFS['textfile.txt'](_.None,_)
>
> but I get the below Error-Message. If I try:
>
> print myLFS['textfile.txt'].data
>
> the content is returned but without rendering (as expected).
> Does anybody know how to get the rendering done?
>
> Thanks a lot for your help,
>
> Elena
>
>
> Error-Message:
>
> Error Type: AttributeError
> Error Value: __call__:
>
>
> Traceback (innermost last):
>   File J:\Zope\ZopeSite\lib\python\ZPublisher\Publish.py, line 223, in
> publish_module
>   File J:\Zope\ZopeSite\lib\python\ZPublisher\Publish.py, line 187, in
> publish
>   File J:\Zope\ZopeSite\lib\python\Zope\__init__.py, line 226, in
> zpublisher_exception_hook
>     (Object: jobs)
>   File J:\Zope\ZopeSite\lib\python\ZPublisher\Publish.py, line 171, in
> publish
>   File J:\Zope\ZopeSite\lib\python\ZPublisher\mapply.py, line
> 160, in mapply
>     (Object: index.html)
>   File J:\Zope\ZopeSite\lib\python\ZPublisher\Publish.py, line 112, in
> call_object
>     (Object: index.html)
>   File J:\Zope\ZopeSite\lib\python\OFS\DTMLMethod.py, line 199,
> in __call__
>     (Object: index.html)
>   File J:\Zope\ZopeSite\lib\python\DocumentTemplate\DT_String.py,
> line 546,
> in __call__
>     (Object: index.html)
>   File J:\Zope\ZopeSite\lib\python\OFS\DTMLMethod.py, line 192,
> in __call__
>     (Object: inhalt)
>   File J:\Zope\ZopeSite\lib\python\DocumentTemplate\DT_String.py,
> line 546,
> in __call__
>     (Object: inhalt)
>   File J:\Zope\ZopeSite\lib\python\DocumentTemplate\DT_Util.py,
> line 231, in
> eval
>     (Object: getContentFiles(_.None,sourceFolder,contentFiles))
>     (Info: getContentFiles)
>   File <string>, line 2, in f
>     (Object: guarded_getattr)
>   File J:\Zope\ZopeSite\lib\python\Shared\DC\Scripts\Bindings.py,
> line 324,
> in __call__
>     (Object: getContentFiles)
>   File J:\Zope\ZopeSite\lib\python\Shared\DC\Scripts\Bindings.py,
> line 354,
> in _bindAndExec
>     (Object: getContentFiles)
>   File J:\Zope\ZopeSite\lib\python\Products\PythonScripts\PythonScript.py,
> line 363, in _exec
>     (Object: getContentFiles)
>     (Info: ({'script': <PythonScript instance at 01F468C0>, 'context':
> <Folder instance at 01F4D430>, 'container': <Folder instance at 01EF0530>,
> '_': <TemplateDict object at 01EB1A30>, 'traverse_subpath': []}, (None,
> 'stxTexte', ['jobs.txt']), {}, (None, None)))
>   File Script (Python), line 16, in getContentFiles
> AttributeError: (see above)
>
>
>
>
> _______________________________________________
> Zope maillist  -  Zope@zope.org
> 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 )
>