1 # -*- Mode: python; coding: utf-8; tab-width: 8; indent-tabs-mode: t; -*-
3 # Copyright (C) 2006 - Jonathan Matthew
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2, or (at your option)
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
29 class GnomeVFSAsyncSrc (object):
33 def read_cb (self
, handle
, buffer, exc_type
, bytes_requested
, (data
, callback
, args
)):
35 if issubclass (exc_type
, gnomevfs
.EOFError):
36 gobject
.idle_add (callback
, data
, *args
)
37 handle
.close (lambda *args
: None)
39 gobject
.idle_add (callback
, None, *args
)
40 handle
.close (lambda *args
: None)
44 handle
.read (self
.chunk
, self
.read_cb
, (data
, callback
, args
))
46 def open_cb (self
, handle
, exc_type
, (data
, callback
, args
)):
48 gobject
.idle_add (callback
, None, *args
)
51 handle
.read (self
.chunk
, self
.read_cb
, (data
, callback
, args
))
53 def get_url (self
, url
, callback
, *args
):
54 gnomevfs
.async.open (url
, self
.open_cb
, data
=("", callback
, args
))
57 class URLLibSrc (object):
58 def get_url (self
, url
, callback
, *args
):
60 sock
= urllib
.urlopen (url
)
63 callback (data
, *args
)
65 callback (None, *args
)
71 return GnomeVFSAsyncSrc ()