quick search:
 

use CURL

Submitted by: runyaga
Last Edited: 2004-10-14

Category: Python(External Method)

Average rating is: 4.0 out of 5 (1 ratings)

Description:
a python interface into curl just came out and I have never heard of CURL. could be cool to wrap a class around it and manipulate returned data in a bit more sensible way.

MUST:
* install curl - http://curl.haxx.se/
* install pycurl - http://pycurl.sourceforge.net/
* make sure you can see pycurl form python interpreter running ZOPE




Source (Text):
#create a file in zope/Extensions calledd, useCURL.py

import curl
import tempfile

def useCURL(uri='dict://dict.org/d:zope'):
    f = tempfile.TemporaryFile()
    ret = ""

    _curl = curl.init()
    _curl.setopt(curl.URL, uri)
    _curl.setopt(curl.FILE, f)
    _curl.setopt(curl.NOPROGRESS, 1)
    _curl.setopt(curl.FOLLOWLOCATION, 1)
    _curl.setopt(curl.MAXREDIRS, 5)
    _curl.perform()
    _curl.cleanup()

    f.seek(0)

    for l in f.readlines():
        ret = ret + l

    f.close()

    return ret

# create a External Method called useCURL
# id - getURI, module- useCURL, function - useCURL

# inside a dtml method 
<pre>
<dtml-var "getURI(uri='dict://dict.org/d:zope')">
</pre>

Explanation:
this is really a silly example of a fast way of exposing a python
library into Zope ala External Methods. But as easy as it is to hook
CURL into ZOPE you can hook any other python library.


Comments:

No Comments