Remove PAGES hacks from pastebin, cleanups

Using OrderedDict fixes the issue.
Also some pep8 fixes.
This commit is contained in:
Laurent Bachelier 2012-03-12 00:24:29 +01:00
commit bd8d103a8e
3 changed files with 16 additions and 11 deletions

View file

@ -1,6 +1,6 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# Copyright(C) 2011 Laurent Bachelier # Copyright(C) 2011-2012 Laurent Bachelier
# #
# This file is part of weboob. # This file is part of weboob.
# #
@ -49,8 +49,8 @@ class PastebinBackend(BaseBackend, BasePasteBackend):
EXPIRATIONS = { EXPIRATIONS = {
600: '10M', 600: '10M',
3600: '1H', 3600: '1H',
3600*24: '1D', 3600 * 24: '1D',
3600*24*30: '1M', 3600 * 24 * 30: '1M',
False: 'N', False: 'N',
} }

View file

@ -1,6 +1,6 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# Copyright(C) 2011 Laurent Bachelier # Copyright(C) 2011-2012 Laurent Bachelier
# #
# This file is part of weboob. # This file is part of weboob.
# #
@ -20,6 +20,7 @@
from weboob.tools.browser import BaseBrowser, BrowserHTTPNotFound, BrowserIncorrectPassword from weboob.tools.browser import BaseBrowser, BrowserHTTPNotFound, BrowserIncorrectPassword
from weboob.tools.browser.decorators import id2url, check_url from weboob.tools.browser.decorators import id2url, check_url
from weboob.tools.ordereddict import OrderedDict
from weboob.capabilities.paste import PasteNotFound from weboob.capabilities.paste import PasteNotFound
@ -31,6 +32,7 @@ import re
__all__ = ['PastebinBrowser'] __all__ = ['PastebinBrowser']
class BadAPIRequest(Exception): class BadAPIRequest(Exception):
pass pass
@ -40,9 +42,11 @@ class PastebinBrowser(BaseBrowser):
ENCODING = 'UTF-8' ENCODING = 'UTF-8'
PASTE_URL = 'http://%s/(?P<id>\w+)' % DOMAIN PASTE_URL = 'http://%s/(?P<id>\w+)' % DOMAIN
API_URL = 'http://%s/api/api_post.php' % DOMAIN API_URL = 'http://%s/api/api_post.php' % DOMAIN
PAGES = {PASTE_URL: PastePage, PAGES = OrderedDict((
'http://%s/u/(?P<username>.+)' % DOMAIN: UserPage, ('http://%s/u/(?P<username>.+)' % DOMAIN, UserPage),
'http://%s/' % DOMAIN: PostPage} ('http://%s/' % DOMAIN, PostPage),
(PASTE_URL, PastePage),
))
def __init__(self, api_key, *args, **kwargs): def __init__(self, api_key, *args, **kwargs):
self.api_key = api_key self.api_key = api_key

View file

@ -1,6 +1,6 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# Copyright(C) 2011 Laurent Bachelier # Copyright(C) 2011-2012 Laurent Bachelier
# #
# This file is part of weboob. # This file is part of weboob.
# #
@ -22,6 +22,7 @@ from weboob.tools.browser import BasePage, BrokenPageError
__all__ = ['PastePage', 'PostPage'] __all__ = ['PastePage', 'PostPage']
class BasePastebinPage(BasePage): class BasePastebinPage(BasePage):
def is_logged(self): def is_logged(self):
header = self.parser.select(self.document.getroot(), header = self.parser.select(self.document.getroot(),
@ -32,8 +33,7 @@ class BasePastebinPage(BasePage):
if link.text == 'login': if link.text == 'login':
return False return False
# XXX hack, since all pages are detected as a PostPage we make PastePage
# inherit LoginPage
class LoginPage(BasePastebinPage): class LoginPage(BasePastebinPage):
def login(self, username, password): def login(self, username, password):
self.browser.select_form(nr=1) self.browser.select_form(nr=1)
@ -42,7 +42,7 @@ class LoginPage(BasePastebinPage):
self.browser.submit() self.browser.submit()
class PastePage(LoginPage): class PastePage(BasePastebinPage):
def fill_paste(self, paste): def fill_paste(self, paste):
header = self.parser.select(self.document.getroot(), header = self.parser.select(self.document.getroot(),
'id("content_left")//div[@class="paste_box_info"]', 1, 'xpath') 'id("content_left")//div[@class="paste_box_info"]', 1, 'xpath')
@ -80,5 +80,6 @@ class PostPage(BasePastebinPage):
self.browser['paste_expire_date'] = [expiration] self.browser['paste_expire_date'] = [expiration]
self.browser.submit() self.browser.submit()
class UserPage(BasePastebinPage): class UserPage(BasePastebinPage):
pass pass