diff --git a/weboob/backends/pastealacon/paste.py b/weboob/backends/pastealacon/paste.py
index 7b7c2a1e..1c86c556 100644
--- a/weboob/backends/pastealacon/paste.py
+++ b/weboob/backends/pastealacon/paste.py
@@ -25,6 +25,9 @@ __all__ = ['PastealaconPaste']
class PastealaconPaste(BasePaste):
+ # all pastes are public
+ public = True
+
@classmethod
def id2url(cls, _id):
return 'http://pastealacon.com/%s' % _id
diff --git a/weboob/backends/pastealacon/test.py b/weboob/backends/pastealacon/test.py
index 2302a877..8418eb93 100644
--- a/weboob/backends/pastealacon/test.py
+++ b/weboob/backends/pastealacon/test.py
@@ -34,6 +34,7 @@ class PastealaconTest(BackendTest):
assert p.title == 'ouiboube'
assert p.page_url.startswith('http://pastealacon.com/')
assert u'héhéhé' in p.contents
+ assert p.public is True
# raw method
p = self.backend.get_paste(_id)
@@ -41,6 +42,7 @@ class PastealaconTest(BackendTest):
assert p.title is NotLoaded
assert p.page_url.startswith('http://pastealacon.com/')
assert u'héhéhé' in p.contents
+ assert p.public is True
def test_post(self):
p = self.backend.new_paste(None, title='ouiboube', contents=u'Weboob Test héhéhé')
@@ -49,6 +51,7 @@ class PastealaconTest(BackendTest):
self.backend.fill_paste(p, ['title'])
assert p.title == 'ouiboube'
assert p.id in p.page_url
+ assert p.public is True
# test all get methods from the Paste we just created
self._get_paste(p.id)
diff --git a/weboob/backends/pastebin/browser.py b/weboob/backends/pastebin/browser.py
index 5a60aaa0..09f86181 100644
--- a/weboob/backends/pastebin/browser.py
+++ b/weboob/backends/pastebin/browser.py
@@ -79,6 +79,7 @@ class PastebinBrowser(BaseBrowser):
data = {'api_dev_key': dev_key,
'api_option': 'paste',
'api_paste_expire_date': '1M',
+ 'api_paste_private': '0' if paste.public else '1',
'api_paste_code': paste.contents.encode(self.ENCODING),
}
if paste.title:
diff --git a/weboob/backends/pastebin/pages.py b/weboob/backends/pastebin/pages.py
index 92ad107c..091feeaa 100644
--- a/weboob/backends/pastebin/pages.py
+++ b/weboob/backends/pastebin/pages.py
@@ -18,7 +18,7 @@
# along with weboob. If not, see .
-from weboob.tools.browser import BasePage
+from weboob.tools.browser import BasePage, BrokenPageError
__all__ = ['PastePage', 'PostPage']
@@ -30,6 +30,14 @@ class PastePage(BasePage):
'//div[@class="paste_box_line1"]//h1', 1, 'xpath').text
paste.contents = self.parser.select(self.document.getroot(),
'//textarea[@id="paste_code"]', 1, 'xpath').text
+ visibility_text = self.parser.select(header,
+ '//div[@class="paste_box_line1"]//img', 1, 'xpath').attrib['alt']
+ if visibility_text.startswith('Public'):
+ paste.public = True
+ elif visibility_text.startswith('Private'):
+ paste.public = False
+ else:
+ raise BrokenPageError('Unable to get the paste visibility')
return paste
def get_id(self):
@@ -44,5 +52,6 @@ class PostPage(BasePage):
self.browser.select_form(name='myform')
self.browser['paste_code'] = paste.contents.encode(self.browser.ENCODING)
self.browser['paste_name'] = paste.title.encode(self.browser.ENCODING)
+ self.browser['paste_private'] = ['0' if paste.public else '1']
self.browser['paste_expire_date'] = ['1M']
self.browser.submit()
diff --git a/weboob/backends/pastebin/test.py b/weboob/backends/pastebin/test.py
index 5a3793f6..772d0e41 100644
--- a/weboob/backends/pastebin/test.py
+++ b/weboob/backends/pastebin/test.py
@@ -32,6 +32,7 @@ class PastebinTest(BackendTest):
assert p.title == 'plop'
assert p.page_url == 'http://pastebin.com/7HmXwzyt'
assert p.contents == 'prout'
+ assert p.public is True
# raw method
p = self.backend.get_paste(_id)
@@ -39,25 +40,29 @@ class PastebinTest(BackendTest):
assert p.title is NotLoaded
assert p.page_url == 'http://pastebin.com/7HmXwzyt'
assert p.contents == 'prout'
+ assert p.public is NotLoaded
def test_post(self):
- p = self.backend.new_paste(None, title='ouiboube', contents='Weboob Test')
+ p = self.backend.new_paste(None, title='ouiboube', contents='Weboob Test', public=True)
self.backend.post_paste(p)
assert p.id
self.backend.fill_paste(p, ['title'])
assert p.title == 'ouiboube'
assert p.id in p.page_url
+ assert p.public is True
def test_specialchars(self):
# post a paste and get the contents through the HTML response
- p1 = self.backend.new_paste(None, title='ouiboube', contents=u'Weboob ¿¡')
+ p1 = self.backend.new_paste(None, title='ouiboube', contents=u'Weboob ¿¡', public=False)
self.backend.post_paste(p1)
assert p1.id
+ assert p1.public is False
# this should use the raw method to get the contents
p2 = self.backend.get_paste(p1.id)
self.backend.fillobj(p2, ['contents'])
assert p2.contents == p1.contents
+ assert p2.public is NotLoaded
def test_notfound(self):
for _id in ('weboooooooooooooooooooooooooob', 'http://pastebin.com/weboooooooooooooooooooooooooob'):
diff --git a/weboob/capabilities/paste.py b/weboob/capabilities/paste.py
index 794423d7..51714ad8 100644
--- a/weboob/capabilities/paste.py
+++ b/weboob/capabilities/paste.py
@@ -31,12 +31,14 @@ class BasePaste(CapBaseObject):
"""
Represents a pasted text.
"""
- def __init__(self, _id, title=NotLoaded, language=NotLoaded, contents=NotLoaded):
+ def __init__(self, _id, title=NotLoaded, language=NotLoaded, contents=NotLoaded,
+ public=NotLoaded):
CapBaseObject.__init__(self, unicode(_id))
self.add_field('title', basestring, title)
self.add_field('language', basestring, language)
self.add_field('contents', basestring, contents)
+ self.add_field('public', bool, public)
@classmethod
def id2url(cls, _id):