[Zope] ZClient?

Luciano Ramalho luciano@hiper.com.br
Mon, 30 Aug 1999 18:49:44 -0300


At 13:12 30/08/99 -0400, Mikhail Terekhov wrote:
 >What is ZClient?

ZClient is a Zope module which you can find in your Zope installation at:
zope/lib/python/ZPublisher/Client.py

It allows Zope to be a HTTP client, to fetch information from other web 
sites, for instance.

In order to use ZClient here at Hiperlogica we wrote this trivial external 
method:

--
from ZPublisher import Client

def hx_client(url = 'http://www.yahoo.com', username = None, password = 
None, **kw):
     '''acess to http servers'''
     if kw:
         return Client.call(url,username,password,kw)[1]
     else:
         return Client.call(url,username,password)[1]
--

The return of Client.call is a tuple, containing a mimetools.Message 
object  and the data. The mimetools.Message (a standard Python class) 
contains headers describing the data, including its MIME type. We are only 
using this to fetch data from HTML pages, so we only return the second part 
of the response (item [1]). A more robust solution would have to read some 
headers and act accordingly...

You can call that external method from DTML like this:

--
<!--#var standard_html_header-->
<h2><!--#var title_or_id--></h2>
<HR>
<!--#var "hx_client('http://www.zope.org')"-->

<HR>

<!--#var standard_html_footer-->
--

We have managed to do some cool things with ZClient, but there are two 
mysteries which still haunt me:

1) How could I invoke the Client.call() method from DTML directly? (I wrote 
the External method because I could not figure this out)

2) Why the first part of the data retrieved is truncated? (So far I've been 
lucky and never had to retrieve a full page, but only parts)

I hope this is useful! And if anyone knows the answer to my two questions, 
any hints will be appreciated.

Best regards,

Luciano Ramalho