diff --git a/weboob/backends/canalplus/backend.py b/weboob/backends/canalplus/backend.py index 9330fc6c..a1def390 100644 --- a/weboob/backends/canalplus/backend.py +++ b/weboob/backends/canalplus/backend.py @@ -65,11 +65,7 @@ class CanalplusBackend(BaseBackend, ICapVideo, ICapCollection): return video OBJECTS = {CanalplusVideo: fill_video} - - def change_working_collection(self, splited_path): - with self.browser: - return self.browser.change_working_collection(splited_path) - + def iter_resources(self, splited_path): with self.browser: return self.browser.iter_resources(splited_path) diff --git a/weboob/backends/canalplus/browser.py b/weboob/backends/canalplus/browser.py index af98feeb..6c78d5b3 100644 --- a/weboob/backends/canalplus/browser.py +++ b/weboob/backends/canalplus/browser.py @@ -76,37 +76,18 @@ class CanalplusBrowser(BaseBrowser): def get_video(self, url, video=None): self.location(url) return self.page.get_video(video, self.quality) - - def change_working_collection(self, splited_path): - self.home() - collections = self.page.collections - - def walk(path, collections, final=[]): - if len(path) == 0: return final - i = path.pop(0) - if i in [collection.title for collection in collections if isinstance(collection, Collection)]: - final.append(i) - else: - #~ print "Error path %s unknow, %s , %s " % (i,final,[collection.title for collection in collections if isinstance(collection, Collection)] ) - raise CollectionNotFound() - - return walk(path, [collection.children for collection in collections if isinstance(collection, Collection) and collection.title == i][0], final) - - return walk(splited_path, collections) - + def iter_resources(self, splited_path): self.home() collections = self.page.collections - + def walk_res(path, collections): - if not isinstance(collections, (list, Collection)): + if len(path) == 0 or not isinstance(collections, (list, Collection)): return collections - if len(path) == 0: - return [collection.title for collection in collections ] i = path[0] if i not in [collection.title for collection in collections]: raise CollectionNotFound() - + return walk_res(path[1:], [collection.children for collection in collections if collection.title == i][0]) - + return walk_res(splited_path, collections) diff --git a/weboob/backends/downparadise/backend.py b/weboob/backends/downparadise/backend.py index be444a00..9c3f863f 100644 --- a/weboob/backends/downparadise/backend.py +++ b/weboob/backends/downparadise/backend.py @@ -32,27 +32,24 @@ class DownparadiseBackend(BaseBackend, ICapCollection, ICapMessages, ICapMessage VERSION = '0.8' LICENSE = 'AGPLv3+' DESCRIPTION = "Downparadise message board" - + CONFIG = ValuesDict(Value('username', label='Username', regexp='.+'), Value('password', label='Password', regexp='.+', masked=True)) - + BROWSER = Downparadise def create_default_browser(self): return self.create_browser(self.config['username'], self.config['password']) - + ############################# ## Collection - def change_working_collection(self, splited_path): - return self.browser.change_working_forum(splited_path) - def iter_resources(self, splited_path): return self.browser.iter_forums(splited_path) - + ############################# ## Messages - + def iter_threads(self): """ Iterates on threads, from newers to olders. @@ -85,10 +82,10 @@ class DownparadiseBackend(BaseBackend, ICapCollection, ICapMessages, ICapMessage @param [message] message read (or ID) """ raise NotImplementedError() - + ############################# ## Message Post - + def post_message(self, message): """ Post a message. diff --git a/weboob/backends/downparadise/browser.py b/weboob/backends/downparadise/browser.py index ce35f20a..b26c6428 100644 --- a/weboob/backends/downparadise/browser.py +++ b/weboob/backends/downparadise/browser.py @@ -31,10 +31,10 @@ class Downparadise(BaseBrowser): 'http://forum.downparadise.ws/ucp.php.*' : UcpPage, 'http://forum.downparadise.ws/viewforum.php.*' : ViewforumPage, } - + def home(self): return self.location('http://forum.downparadise.ws/index.php') - + def login(self): data = {'login': 'Connexion', 'password': self.password, @@ -42,44 +42,23 @@ class Downparadise(BaseBrowser): self.location('http://forum.downparadise.ws/ucp.php?mode=login', urllib.urlencode(data) , no_login=True) if not self.is_logged(): raise BrowserIncorrectPassword() - + def is_logged(self): return (self.page and self.page.is_logged()) - - def change_working_forum(self, splited_path): + + def iter_forums(self, splited_path): if not self.is_on_page(IndexPage): self.home() collections = self.page.get_collections() - - def walk(path, collections, final=[]): - if len(path) == 0: return final - i = path.pop(0) - if i in [collection.title for collection in collections if isinstance(collection, Collection)]: - final.append(i) - else: - raise CollectionNotFound() - - return walk(path, [collection.children for collection in collections if isinstance(collection, Collection) and collection.title == i][0], final) - - return walk(splited_path, collections) - - def iter_forums(self, splited_path): - - if not self.is_on_page(IndexPage): - self.home() - collections = self.page.get_collections() - def walk_res(path, collections): - if not isinstance(collections, (list, Collection)): + if len(path) == 0 or not isinstance(collections, (list, Collection)): return collections - if len(path) == 0: - return [collection.title for collection in collections ] i = path[0] if i not in [collection.title for collection in collections]: raise CollectionNotFound() - + return walk_res(path[1:], [collection.children for collection in collections if collection.title == i][0]) - + return walk_res(splited_path, collections) diff --git a/weboob/capabilities/collection.py b/weboob/capabilities/collection.py index baeb1275..fd19db57 100644 --- a/weboob/capabilities/collection.py +++ b/weboob/capabilities/collection.py @@ -34,10 +34,10 @@ class Children(object): return obj._childrenfct(obj.id) else: return obj._children - + def __set__(self, obj, value): obj._childrenfct = value - + class Collection(object): """ _childrenfct @@ -46,26 +46,19 @@ class Collection(object): children return iterator """ children = Children() - + def __init__(self, title=None, children=None): self.title = title self._children = children if children else [] self._childrenfct = None - + def appendchild(self, child): self._children.append(child) - - + + class Ressource(object): pass class ICapCollection(IBaseCap): - - def get_working_collection(self): - raise NotImplementedError() - - def change_working_collection(self, splited_path): - raise NotImplementedError() - def iter_resources(self, splited_path): raise NotImplementedError()