~ubuntu-branches/ubuntu/karmic/pida/karmic

« back to all changes in this revision

Viewing changes to pida/utils/web.py

  • Committer: Bazaar Package Importer
  • Author(s): Jan Luebbe
  • Date: 2007-09-05 17:54:09 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20070905175409-ty9f6qpuctyjv1sd
Tags: 0.5.1-2
* Depend on librsvg2-common, which is not pulled in by the other depends
  (closes: #394860)
* gvim is no alternative for python-gnome2 and python-gnome2-extras
  (closes: #436431)
* Pida now uses ~/.pida2, so it can no longer be confused by old
  configurations (closes: #421378)
* Culebra is no longer supported by upstream (closes: #349009)
* Update manpage (closes: #440375)
* Update watchfile (pida is now called PIDA)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
from urllib import urlopen, urlencode
 
3
 
 
4
from pida.utils.gthreads import AsyncTask
 
5
 
 
6
def fetch_url(url, content_callback, data={}):
 
7
    """Asynchronously fetch a URL"""
 
8
    if data:
 
9
        urlargs = (url, urlencode(data))
 
10
    else:
 
11
        urlargs = (url,)
 
12
 
 
13
    def _fetcher():
 
14
        try:
 
15
            f = urlopen(*urlargs)
 
16
            content = f.read()
 
17
            url = f.url
 
18
        except Exception, e:
 
19
            content = str(e)
 
20
            url = None
 
21
        return url, content
 
22
 
 
23
    task = AsyncTask(_fetcher, content_callback) 
 
24
    task.start()
 
25
 
 
26
if __name__ == '__main__':
 
27
    
 
28
    def cc(url, data):
 
29
        print url, data
 
30
        gtk.main_quit()
 
31
 
 
32
    fetch_url('http://google.com/sdfsdfsdf', cc)
 
33
    import gtk
 
34
    gtk.threads_init()
 
35
    gtk.threads_enter()
 
36
    gtk.main()
 
37
    gtk.threads_leave()
 
38