CapCollection is stateless: remove get_working_collection() and change_working_collection() methods

This commit is contained in:
Romain Bignon 2011-04-21 10:34:42 +02:00
commit e8084ef99f
5 changed files with 27 additions and 81 deletions

View file

@ -66,10 +66,6 @@ class CanalplusBackend(BaseBackend, ICapVideo, ICapCollection):
OBJECTS = {CanalplusVideo: fill_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): def iter_resources(self, splited_path):
with self.browser: with self.browser:
return self.browser.iter_resources(splited_path) return self.browser.iter_resources(splited_path)

View file

@ -77,32 +77,13 @@ class CanalplusBrowser(BaseBrowser):
self.location(url) self.location(url)
return self.page.get_video(video, self.quality) 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): def iter_resources(self, splited_path):
self.home() self.home()
collections = self.page.collections collections = self.page.collections
def walk_res(path, collections): def walk_res(path, collections):
if not isinstance(collections, (list, Collection)): if len(path) == 0 or not isinstance(collections, (list, Collection)):
return collections return collections
if len(path) == 0:
return [collection.title for collection in collections ]
i = path[0] i = path[0]
if i not in [collection.title for collection in collections]: if i not in [collection.title for collection in collections]:
raise CollectionNotFound() raise CollectionNotFound()

View file

@ -44,9 +44,6 @@ class DownparadiseBackend(BaseBackend, ICapCollection, ICapMessages, ICapMessage
############################# #############################
## Collection ## Collection
def change_working_collection(self, splited_path):
return self.browser.change_working_forum(splited_path)
def iter_resources(self, splited_path): def iter_resources(self, splited_path):
return self.browser.iter_forums(splited_path) return self.browser.iter_forums(splited_path)

View file

@ -46,36 +46,15 @@ class Downparadise(BaseBrowser):
def is_logged(self): def is_logged(self):
return (self.page and self.page.is_logged()) return (self.page and self.page.is_logged())
def change_working_forum(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): def iter_forums(self, splited_path):
if not self.is_on_page(IndexPage): if not self.is_on_page(IndexPage):
self.home() self.home()
collections = self.page.get_collections() collections = self.page.get_collections()
def walk_res(path, collections): def walk_res(path, collections):
if not isinstance(collections, (list, Collection)): if len(path) == 0 or not isinstance(collections, (list, Collection)):
return collections return collections
if len(path) == 0:
return [collection.title for collection in collections ]
i = path[0] i = path[0]
if i not in [collection.title for collection in collections]: if i not in [collection.title for collection in collections]:
raise CollectionNotFound() raise CollectionNotFound()

View file

@ -60,12 +60,5 @@ class Ressource(object):
pass pass
class ICapCollection(IBaseCap): 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): def iter_resources(self, splited_path):
raise NotImplementedError() raise NotImplementedError()