CapCollection is stateless: remove get_working_collection() and change_working_collection() methods
This commit is contained in:
parent
cc52b8eb3c
commit
e8084ef99f
5 changed files with 27 additions and 81 deletions
|
|
@ -65,11 +65,7 @@ class CanalplusBackend(BaseBackend, ICapVideo, ICapCollection):
|
||||||
return video
|
return video
|
||||||
|
|
||||||
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)
|
||||||
|
|
|
||||||
|
|
@ -76,37 +76,18 @@ class CanalplusBrowser(BaseBrowser):
|
||||||
def get_video(self, url, video=None):
|
def get_video(self, url, video=None):
|
||||||
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()
|
||||||
|
|
||||||
return walk_res(path[1:], [collection.children for collection in collections if collection.title == i][0])
|
return walk_res(path[1:], [collection.children for collection in collections if collection.title == i][0])
|
||||||
|
|
||||||
return walk_res(splited_path, collections)
|
return walk_res(splited_path, collections)
|
||||||
|
|
|
||||||
|
|
@ -32,27 +32,24 @@ class DownparadiseBackend(BaseBackend, ICapCollection, ICapMessages, ICapMessage
|
||||||
VERSION = '0.8'
|
VERSION = '0.8'
|
||||||
LICENSE = 'AGPLv3+'
|
LICENSE = 'AGPLv3+'
|
||||||
DESCRIPTION = "Downparadise message board"
|
DESCRIPTION = "Downparadise message board"
|
||||||
|
|
||||||
CONFIG = ValuesDict(Value('username', label='Username', regexp='.+'),
|
CONFIG = ValuesDict(Value('username', label='Username', regexp='.+'),
|
||||||
Value('password', label='Password', regexp='.+', masked=True))
|
Value('password', label='Password', regexp='.+', masked=True))
|
||||||
|
|
||||||
BROWSER = Downparadise
|
BROWSER = Downparadise
|
||||||
|
|
||||||
def create_default_browser(self):
|
def create_default_browser(self):
|
||||||
return self.create_browser(self.config['username'], self.config['password'])
|
return self.create_browser(self.config['username'], self.config['password'])
|
||||||
|
|
||||||
#############################
|
#############################
|
||||||
## 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)
|
||||||
|
|
||||||
#############################
|
#############################
|
||||||
## Messages
|
## Messages
|
||||||
|
|
||||||
def iter_threads(self):
|
def iter_threads(self):
|
||||||
"""
|
"""
|
||||||
Iterates on threads, from newers to olders.
|
Iterates on threads, from newers to olders.
|
||||||
|
|
@ -85,10 +82,10 @@ class DownparadiseBackend(BaseBackend, ICapCollection, ICapMessages, ICapMessage
|
||||||
@param [message] message read (or ID)
|
@param [message] message read (or ID)
|
||||||
"""
|
"""
|
||||||
raise NotImplementedError()
|
raise NotImplementedError()
|
||||||
|
|
||||||
#############################
|
#############################
|
||||||
## Message Post
|
## Message Post
|
||||||
|
|
||||||
def post_message(self, message):
|
def post_message(self, message):
|
||||||
"""
|
"""
|
||||||
Post a message.
|
Post a message.
|
||||||
|
|
|
||||||
|
|
@ -31,10 +31,10 @@ class Downparadise(BaseBrowser):
|
||||||
'http://forum.downparadise.ws/ucp.php.*' : UcpPage,
|
'http://forum.downparadise.ws/ucp.php.*' : UcpPage,
|
||||||
'http://forum.downparadise.ws/viewforum.php.*' : ViewforumPage,
|
'http://forum.downparadise.ws/viewforum.php.*' : ViewforumPage,
|
||||||
}
|
}
|
||||||
|
|
||||||
def home(self):
|
def home(self):
|
||||||
return self.location('http://forum.downparadise.ws/index.php')
|
return self.location('http://forum.downparadise.ws/index.php')
|
||||||
|
|
||||||
def login(self):
|
def login(self):
|
||||||
data = {'login': 'Connexion',
|
data = {'login': 'Connexion',
|
||||||
'password': self.password,
|
'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)
|
self.location('http://forum.downparadise.ws/ucp.php?mode=login', urllib.urlencode(data) , no_login=True)
|
||||||
if not self.is_logged():
|
if not self.is_logged():
|
||||||
raise BrowserIncorrectPassword()
|
raise BrowserIncorrectPassword()
|
||||||
|
|
||||||
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):
|
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(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):
|
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()
|
||||||
|
|
||||||
return walk_res(path[1:], [collection.children for collection in collections if collection.title == i][0])
|
return walk_res(path[1:], [collection.children for collection in collections if collection.title == i][0])
|
||||||
|
|
||||||
return walk_res(splited_path, collections)
|
return walk_res(splited_path, collections)
|
||||||
|
|
|
||||||
|
|
@ -34,10 +34,10 @@ class Children(object):
|
||||||
return obj._childrenfct(obj.id)
|
return obj._childrenfct(obj.id)
|
||||||
else:
|
else:
|
||||||
return obj._children
|
return obj._children
|
||||||
|
|
||||||
def __set__(self, obj, value):
|
def __set__(self, obj, value):
|
||||||
obj._childrenfct = value
|
obj._childrenfct = value
|
||||||
|
|
||||||
class Collection(object):
|
class Collection(object):
|
||||||
"""
|
"""
|
||||||
_childrenfct
|
_childrenfct
|
||||||
|
|
@ -46,26 +46,19 @@ class Collection(object):
|
||||||
children return iterator
|
children return iterator
|
||||||
"""
|
"""
|
||||||
children = Children()
|
children = Children()
|
||||||
|
|
||||||
def __init__(self, title=None, children=None):
|
def __init__(self, title=None, children=None):
|
||||||
self.title = title
|
self.title = title
|
||||||
self._children = children if children else []
|
self._children = children if children else []
|
||||||
self._childrenfct = None
|
self._childrenfct = None
|
||||||
|
|
||||||
def appendchild(self, child):
|
def appendchild(self, child):
|
||||||
self._children.append(child)
|
self._children.append(child)
|
||||||
|
|
||||||
|
|
||||||
class Ressource(object):
|
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()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue