3 Module for routing feed data from the poller
5 __copyright__
= "Copyright (c) 2002-2005 Free Software Foundation, Inc."
7 Straw is free software; you can redistribute it and/or modify it under the
8 terms of the GNU General Public License as published by the Free Software
9 Foundation; either version 2 of the License, or (at your option) any later
12 Straw is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14 A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License along with
17 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
18 Place - Suite 330, Boston, MA 02111-1307, USA. """
24 class FeedDataRouter(object):
25 def __init__(self
, feed
):
26 ImageCache
.cache
.signal_connect(Event
.ImageUpdatedSignal
,
30 # stuff we are potentially waiting for
32 self
._wait
_images
= {}
35 def start_polling(self
):
37 self
.update_process_status()
39 def route_no_data(self
):
41 self
._feed
.error
= None
43 self
.update_process_status()
45 def route_all(self
, header
, parsed
):
46 needed_loading
= self
._feed
.load_contents()
47 self
.route_data(header
, parsed
)
50 self
._feed
.unload_contents()
52 def route_data(self
, header
, parsed
):
54 etag
= header
.getheader('etag', None)
57 self
._feed
.previous_etag
= etag
58 self
._feed
.channel_title
= parsed
.title
59 self
._feed
.channel_description
= parsed
.description
60 self
._feed
.channel_copyright
= parsed
.copyright
61 self
._feed
.channel_link
= parsed
.link
62 self
._feed
.channel_creator
= parsed
.creator
64 parsed
.items
.reverse()
65 self
._feed
.add_items(parsed
.items
)
66 self
._feed
.error
= None
68 self
._feed
.poll_done()
70 def route_extras(self
):
72 for i
in self
._feed
.items
:
73 for name
in i
.image_keys():
74 image
= i
.get_image(name
)
75 if image
.status
== image
.WAITING
:
76 self
._wait
_images
[image
.url
] = 1
78 # if we don't get the images, we can probably still show
81 self
.update_process_status()
83 def set_error(self
, err
):
85 self
._feed
.error
= err
86 self
.update_process_status()
89 def set_stopper(self
, stopper
):
90 self
._stopper
= stopper
91 stopper
.signal_connect(Event
.PollingStoppedSignal
,
92 self
._polling
_stopped
)
93 def get_stopper(self
): return self
._stopper
94 stopper
= property(get_stopper
, set_stopper
)
97 self
._feed
.poll_done()
100 def stop_polling(self
):
104 for image
in self
._wait
_images
.keys():
105 ImageCache
.cache
.stop_transfer(image
)
106 del self
._wait
_images
[image
]
107 self
.update_process_status()
108 self
._feed
.poll_done()
110 def _polling_stopped(self
, signal
):
115 def image_updated(self
, signal
):
116 if signal
.url
in self
._wait
_images
:
117 del self
._wait
_images
[signal
.url
]
118 self
.update_process_status()
120 def update_process_status(self
):
121 length_images
= len(self
._wait
_images
)
122 if self
._wait
_data
or length_images
:
123 self
._feed
.process_status
= self
._feed
.STATUS_POLLING
125 self
._feed
.process_status
= self
._feed
.STATUS_IDLE