From bd8d103a8e4c2138266667d908a4bb52ba46780c Mon Sep 17 00:00:00 2001 From: Laurent Bachelier Date: Mon, 12 Mar 2012 00:24:29 +0100 Subject: [PATCH] Remove PAGES hacks from pastebin, cleanups Using OrderedDict fixes the issue. Also some pep8 fixes. --- modules/pastebin/backend.py | 6 +++--- modules/pastebin/browser.py | 12 ++++++++---- modules/pastebin/pages.py | 9 +++++---- 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/modules/pastebin/backend.py b/modules/pastebin/backend.py index 4ffdccb9..2dcc30a0 100644 --- a/modules/pastebin/backend.py +++ b/modules/pastebin/backend.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -# Copyright(C) 2011 Laurent Bachelier +# Copyright(C) 2011-2012 Laurent Bachelier # # This file is part of weboob. # @@ -49,8 +49,8 @@ class PastebinBackend(BaseBackend, BasePasteBackend): EXPIRATIONS = { 600: '10M', 3600: '1H', - 3600*24: '1D', - 3600*24*30: '1M', + 3600 * 24: '1D', + 3600 * 24 * 30: '1M', False: 'N', } diff --git a/modules/pastebin/browser.py b/modules/pastebin/browser.py index 51efb3b6..a8897a5d 100644 --- a/modules/pastebin/browser.py +++ b/modules/pastebin/browser.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -# Copyright(C) 2011 Laurent Bachelier +# Copyright(C) 2011-2012 Laurent Bachelier # # This file is part of weboob. # @@ -20,6 +20,7 @@ from weboob.tools.browser import BaseBrowser, BrowserHTTPNotFound, BrowserIncorrectPassword from weboob.tools.browser.decorators import id2url, check_url +from weboob.tools.ordereddict import OrderedDict from weboob.capabilities.paste import PasteNotFound @@ -31,6 +32,7 @@ import re __all__ = ['PastebinBrowser'] + class BadAPIRequest(Exception): pass @@ -40,9 +42,11 @@ class PastebinBrowser(BaseBrowser): ENCODING = 'UTF-8' PASTE_URL = 'http://%s/(?P\w+)' % DOMAIN API_URL = 'http://%s/api/api_post.php' % DOMAIN - PAGES = {PASTE_URL: PastePage, - 'http://%s/u/(?P.+)' % DOMAIN: UserPage, - 'http://%s/' % DOMAIN: PostPage} + PAGES = OrderedDict(( + ('http://%s/u/(?P.+)' % DOMAIN, UserPage), + ('http://%s/' % DOMAIN, PostPage), + (PASTE_URL, PastePage), + )) def __init__(self, api_key, *args, **kwargs): self.api_key = api_key diff --git a/modules/pastebin/pages.py b/modules/pastebin/pages.py index 91b7f1e9..20c2a316 100644 --- a/modules/pastebin/pages.py +++ b/modules/pastebin/pages.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -# Copyright(C) 2011 Laurent Bachelier +# Copyright(C) 2011-2012 Laurent Bachelier # # This file is part of weboob. # @@ -22,6 +22,7 @@ from weboob.tools.browser import BasePage, BrokenPageError __all__ = ['PastePage', 'PostPage'] + class BasePastebinPage(BasePage): def is_logged(self): header = self.parser.select(self.document.getroot(), @@ -32,8 +33,7 @@ class BasePastebinPage(BasePage): if link.text == 'login': return False -# XXX hack, since all pages are detected as a PostPage we make PastePage -# inherit LoginPage + class LoginPage(BasePastebinPage): def login(self, username, password): self.browser.select_form(nr=1) @@ -42,7 +42,7 @@ class LoginPage(BasePastebinPage): self.browser.submit() -class PastePage(LoginPage): +class PastePage(BasePastebinPage): def fill_paste(self, paste): header = self.parser.select(self.document.getroot(), '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.submit() + class UserPage(BasePastebinPage): pass