Remove PAGES hacks from pastebin, cleanups
Using OrderedDict fixes the issue. Also some pep8 fixes.
This commit is contained in:
parent
203244868f
commit
bd8d103a8e
3 changed files with 16 additions and 11 deletions
|
|
@ -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',
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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<id>\w+)' % DOMAIN
|
||||
API_URL = 'http://%s/api/api_post.php' % DOMAIN
|
||||
PAGES = {PASTE_URL: PastePage,
|
||||
'http://%s/u/(?P<username>.+)' % DOMAIN: UserPage,
|
||||
'http://%s/' % DOMAIN: PostPage}
|
||||
PAGES = OrderedDict((
|
||||
('http://%s/u/(?P<username>.+)' % DOMAIN, UserPage),
|
||||
('http://%s/' % DOMAIN, PostPage),
|
||||
(PASTE_URL, PastePage),
|
||||
))
|
||||
|
||||
def __init__(self, api_key, *args, **kwargs):
|
||||
self.api_key = api_key
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue