diff --git a/weboob/backends/pastebin/__init__.py b/weboob/backends/pastebin/__init__.py
new file mode 100644
index 00000000..92f8d862
--- /dev/null
+++ b/weboob/backends/pastebin/__init__.py
@@ -0,0 +1,22 @@
+# -*- coding: utf-8 -*-
+
+# Copyright(C) 2011 Laurent Bachelier
+#
+# This file is part of weboob.
+#
+# weboob is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# weboob is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with weboob. If not, see .
+
+from .backend import PastebinBackend
+
+__all__ = ['PastebinBackend']
diff --git a/weboob/backends/pastebin/backend.py b/weboob/backends/pastebin/backend.py
new file mode 100644
index 00000000..72ff6a8b
--- /dev/null
+++ b/weboob/backends/pastebin/backend.py
@@ -0,0 +1,55 @@
+# -*- coding: utf-8 -*-
+
+# Copyright(C) 2011 Laurent Bachelier
+#
+# This file is part of weboob.
+#
+# weboob is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# weboob is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with weboob. If not, see .
+
+
+from weboob.capabilities.paste import ICapPaste
+from weboob.tools.backend import BaseBackend
+
+from .browser import PastebinBrowser
+from .paste import PastebinPaste
+
+
+__all__ = ['PastebinBackend']
+
+
+class PastebinBackend(BaseBackend, ICapPaste):
+ NAME = 'pastebin'
+ MAINTAINER = 'Laurent Bachelier'
+ EMAIL = 'laurent@bachelier.name'
+ VERSION = '0.8'
+ DESCRIPTION = 'Pastebin paste tool'
+ LICENSE = 'AGPLv3+'
+ BROWSER = PastebinBrowser
+
+ def get_paste(self, _id):
+ paste = PastebinPaste(_id)
+ self.browser.fill_paste(paste)
+ return paste
+
+ def fill_paste(self, paste, fields):
+ self.browser.fill_paste(paste)
+ if 'contents' in fields:
+ contents = self.browser.get_contents(paste.id)
+ paste.contents = contents
+ return paste
+
+ def post_paste(self, paste):
+ self.browser.post_paste(paste)
+
+ OBJECTS = {PastebinPaste: fill_paste}
diff --git a/weboob/backends/pastebin/browser.py b/weboob/backends/pastebin/browser.py
new file mode 100644
index 00000000..2ea99370
--- /dev/null
+++ b/weboob/backends/pastebin/browser.py
@@ -0,0 +1,48 @@
+# -*- coding: utf-8 -*-
+
+# Copyright(C) 2011 Laurent Bachelier
+#
+# This file is part of weboob.
+#
+# weboob is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# weboob is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with weboob. If not, see .
+
+
+from weboob.tools.browser import BaseBrowser
+
+from .pages import PastePage, PostPage
+from .paste import PastebinPaste
+
+__all__ = ['PastebinBrowser']
+
+from weboob.tools.browser import BaseBrowser
+BaseBrowser.SAVE_RESPONSES=True
+
+class PastebinBrowser(BaseBrowser):
+ DOMAIN = 'pastebin.com'
+ ENCODING = 'UTF-8'
+ PAGES = {'http://%s/(?P.+)' % DOMAIN: PastePage,
+ 'http://%s/' % DOMAIN: PostPage}
+
+ def fill_paste(self, paste):
+ self.location(paste.page_url)
+ return self.page.fill_paste(paste)
+
+ def get_contents(self, _id):
+ return self.readurl('http://%s/raw.php?i=%s' % (self.DOMAIN, _id))
+
+ def post_paste(self, paste):
+ self.home()
+ self.page.post(paste)
+ paste.id = self.page.get_id()
+ self.fill_paste(paste)
diff --git a/weboob/backends/pastebin/pages.py b/weboob/backends/pastebin/pages.py
new file mode 100644
index 00000000..63407754
--- /dev/null
+++ b/weboob/backends/pastebin/pages.py
@@ -0,0 +1,45 @@
+# -*- coding: utf-8 -*-
+
+# Copyright(C) 2011 Laurent Bachelier
+#
+# This file is part of weboob.
+#
+# weboob is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# weboob is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with weboob. If not, see .
+
+
+from weboob.tools.browser import BasePage
+from urlparse import urlparse
+
+__all__ = ['PastePage']
+
+class PastePage(BasePage):
+ def fill_paste(self, paste):
+ header = self.parser.select(self.document.getroot(), '#content_left div.paste_box_info', 1)
+
+ paste.title = self.parser.select(header, 'div.paste_box_line1 h1', 1).text
+
+ def get_id(self):
+ """
+ Find out the ID from the URL
+ """
+ path = urlparse(self.url).path
+ return path[1:]
+
+
+class PostPage(BasePage):
+ def post(self, paste):
+ self.browser.select_form(name='myform')
+ self.browser['paste_code'] = paste.contents
+ self.browser['paste_name'] = paste.title
+ self.browser.submit()
diff --git a/weboob/backends/pastebin/paste.py b/weboob/backends/pastebin/paste.py
new file mode 100644
index 00000000..bca243db
--- /dev/null
+++ b/weboob/backends/pastebin/paste.py
@@ -0,0 +1,30 @@
+# -*- coding: utf-8 -*-
+
+# Copyright(C) 2011 Laurent Bachelier
+#
+# This file is part of weboob.
+#
+# weboob is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# weboob is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with weboob. If not, see .
+
+
+from weboob.capabilities.paste import BasePaste
+
+
+__all__ = ['PastebinPaste']
+
+
+class PastebinPaste(BasePaste):
+ @classmethod
+ def id2url(cls, _id):
+ return 'http://pastebin.com/%s' % _id
diff --git a/weboob/backends/pastebin/test.py b/weboob/backends/pastebin/test.py
new file mode 100644
index 00000000..964731ee
--- /dev/null
+++ b/weboob/backends/pastebin/test.py
@@ -0,0 +1,39 @@
+# -*- coding: utf-8 -*-
+
+# Copyright(C) 2011 Laurent Bachelier
+#
+# This file is part of weboob.
+#
+# weboob is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# weboob is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with weboob. If not, see .
+
+
+from weboob.tools.test import BackendTest
+from .paste import PastebinPaste
+
+class PastebinTest(BackendTest):
+ BACKEND = 'pastebin'
+
+ def test_get_paste(self):
+ p = self.backend.get_paste('7HmXwzyt')
+ self.backend.fillobj(p, ('title', 'contents'))
+ assert p.title == 'plop'
+ assert p.page_url == 'http://pastebin.com/7HmXwzyt'
+ assert p.contents == 'prout'
+
+ def test_post(self):
+ p = PastebinPaste(None, title='ouiboube', contents='Weboob Test')
+ self.backend.post_paste(p)
+ assert p.id
+ assert p.title == 'ouiboube'
+ assert p.id in p.page_url
diff --git a/weboob/capabilities/paste.py b/weboob/capabilities/paste.py
new file mode 100644
index 00000000..8a1cfccb
--- /dev/null
+++ b/weboob/capabilities/paste.py
@@ -0,0 +1,69 @@
+# -*- coding: utf-8 -*-
+
+# Copyright(C) 2011 Laurent Bachelier
+#
+# This file is part of weboob.
+#
+# weboob is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# weboob is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with weboob. If not, see .
+
+
+from .base import IBaseCap, CapBaseObject, NotLoaded
+
+
+__all__ = ['BasePaste', 'ICapPaste']
+
+
+class BasePaste(CapBaseObject):
+ """
+ Represents a pasted text.
+ """
+ def __init__(self, _id, title=NotLoaded, language=NotLoaded, contents=NotLoaded):
+ CapBaseObject.__init__(self, unicode(_id))
+
+ self.add_field('title', basestring, title)
+ self.add_field('language', basestring, language)
+ self.add_field('contents', basestring, contents)
+
+ @classmethod
+ def id2url(cls, _id):
+ """Overloaded in child classes provided by backends."""
+ raise NotImplementedError()
+
+ @property
+ def page_url(self):
+ return self.id2url(self.id)
+
+
+class ICapPaste(IBaseCap):
+ """
+ This capability represents the ability for a website backend to store text.
+ """
+
+ def get_paste(self, _id):
+ """
+ Get a Video from an ID.
+
+ @param _id the video id. It can be a numeric ID, or a page url, or so.
+ @return a Video object
+ """
+ raise NotImplementedError()
+
+ def post_message(self, paste):
+ """
+ Post a paste.
+
+ @param paste Paste object
+ @return
+ """
+ raise NotImplementedError()