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. """
20 from JobManager
import Job
, TaskResult
, TaskThread
, JobHandler
27 class FeedDiscoveryJobHandler(JobHandler
):
28 job_id
= "feed-discovery"
31 "feed-discovered" : (gobject
.SIGNAL_RUN_LAST
, gobject
.TYPE_NONE
, (gobject
.TYPE_PYOBJECT
,))
34 def __init__(self
, id, job
):
35 JobHandler
.__init
__(self
, id, job
)
37 def _on_fetch_started(self
, handler
, task
):
40 def _on_url_fetched(self
, handler
, task_result
):
41 url
= task_result
.task
.user_data
42 fetch_result
= task_result
.result
44 if feedfinder
.couldBeFeedData(fetch_result
.content
):
45 feed
= SummaryParser
.parse(fetch_result
.content
, location
= url
)
46 self
._notify
("feed-discovered", feed
)
48 def _on_fetch_done(self
, handler
, data
):
52 self
.observers
= [{ "task-done": [ self
._on
_url
_fetched
],
53 "task-start": [ self
._on
_fetch
_started
],
54 "job-done": [ self
._on
_fetch
_done
]}]
57 fetch_task
= Fetcher
.create_task(url
= self
.job
.url
, credentials
= self
.job
.credentials
, user_data
= None)
58 fetch_result
= fetch_task
.fetch()
60 if fetch_result
.error
:
63 if feedfinder
.couldBeFeedData(fetch_result
.content
):
64 feed
= SummaryParser
.parse(fetch_result
.content
, location
= self
.job
.url
)
66 if self
.job
.credentials
:
67 print self
.job
.credentials
68 feed
.pdict
["username"], feed
.pdict
["password"], domain
= self
.job
.credentials
70 self
._notify
("feed-discovered", feed
)
73 urls
= feedfinder
.urls(self
.job
.url
, fetch_result
.content
)
74 fetch_tasks
= [Fetcher
.create_task(url
= url
, user_data
= url
) for url
in urls
]
75 self
.fetcher_id
= Fetcher
.fetch(fetch_tasks
, observers
= self
.observers
, wait
= True)
77 class FeedDiscoveryJob(Job
):
78 def __init__(self
, url
, credentials
, observers
):
79 Job
.__init
__(self
, "feed-discovery")
81 self
.observers
= observers
83 self
.credentials
= credentials
85 JobManager
.register_handler(FeedDiscoveryJobHandler
)
87 def discover(url
, credentials
, observers
):
88 job
= FeedDiscoveryJob(url
, credentials
, observers
)