pax_global_header 0000666 0000000 0000000 00000000064 14042356110 0014506 g ustar 00root root 0000000 0000000 52 comment=18d41565f955028f9fcd2f6cc437f5f1cb717401
woob-18d41565f955028f9fcd2f6cc437f5f1cb717401-modules-sprunge/ 0000775 0000000 0000000 00000000000 14042356110 0022462 5 ustar 00root root 0000000 0000000 woob-18d41565f955028f9fcd2f6cc437f5f1cb717401-modules-sprunge/modules/ 0000775 0000000 0000000 00000000000 14042356110 0024132 5 ustar 00root root 0000000 0000000 woob-18d41565f955028f9fcd2f6cc437f5f1cb717401-modules-sprunge/modules/sprunge/ 0000775 0000000 0000000 00000000000 14042356110 0025615 5 ustar 00root root 0000000 0000000 woob-18d41565f955028f9fcd2f6cc437f5f1cb717401-modules-sprunge/modules/sprunge/__init__.py 0000664 0000000 0000000 00000001502 14042356110 0027724 0 ustar 00root root 0000000 0000000 # -*- coding: utf-8 -*-
# Copyright(C) 2017 Laurent Bachelier
#
# This file is part of a woob module.
#
# This woob module 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.
#
# This woob module 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 this woob module. If not, see .
from .module import SprungeModule
__all__ = ['SprungeModule']
woob-18d41565f955028f9fcd2f6cc437f5f1cb717401-modules-sprunge/modules/sprunge/browser.py 0000664 0000000 0000000 00000005213 14042356110 0027653 0 ustar 00root root 0000000 0000000 # -*- coding: utf-8 -*-
# Copyright(C) 2017 Laurent Bachelier
#
# This file is part of a woob module.
#
# This woob module 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.
#
# This woob module 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 this woob module. If not, see .
from woob.browser.browsers import PagesBrowser
from woob.browser.elements import ItemElement, method
from woob.browser.filters.standard import BrowserURL, Env, Field
from woob.browser.pages import HTMLPage
from woob.browser.url import URL
from woob.capabilities.base import NotAvailable
from woob.capabilities.paste import BasePaste, PasteNotFound
class SprungePaste(BasePaste):
# all pastes are private
public = False
# TODO perhaps move this logic elsewhere, remove this and id2url from capability
# (page_url is required by pastoob)
@property
def page_url(self):
return self.url
class PastePage(HTMLPage):
@method
class fill_paste(ItemElement):
klass = SprungePaste
obj_id = Env('id')
obj_title = NotAvailable
def obj_contents(self):
text = self.page.response.text
# Sprunge seems to add a newline to our original text
if text.endswith(u'\n'):
text = text[:-1]
return text
obj_url = BrowserURL('paste', id=Field('id'))
def validate(self, obj):
if obj.contents == u'%s not found.' % obj.id:
raise PasteNotFound()
return True
class SprungeBrowser(PagesBrowser):
BASEURL = 'http://sprunge.us/'
paste = URL(r'(?P\w+)', PastePage)
post = URL(r'$')
@paste.id2url
def get_paste(self, url):
url = self.absurl(url, base=True)
m = self.paste.match(url)
if m:
return SprungePaste(m.groupdict()['id'])
def fill_paste(self, paste):
"""
Get as much as information possible from the paste page
"""
return self.paste.stay_or_go(id=paste.id).fill_paste(paste)
def post_paste(self, paste):
url = self.post.open(data={'sprunge': paste.contents}).text.strip()
self.location(url)
return self.page.fill_paste(paste)
woob-18d41565f955028f9fcd2f6cc437f5f1cb717401-modules-sprunge/modules/sprunge/favicon.png 0000664 0000000 0000000 00000000447 14042356110 0027755 0 ustar 00root root 0000000 0000000 PNG
IHDR @ @ M PLTE "]a[j9_od tRNS @f IDAT8
P*\zb.#P'pD)eH.Brͥ%$7 W4" lg+`
- h78u
h:Br 8@ju֗YV!~Y+G0#
bF"_a3+CDVv&@"`PN$ rIݒ
f rDg{േ7 WxE IENDB` woob-18d41565f955028f9fcd2f6cc437f5f1cb717401-modules-sprunge/modules/sprunge/module.py 0000664 0000000 0000000 00000003603 14042356110 0027456 0 ustar 00root root 0000000 0000000 # -*- coding: utf-8 -*-
# Copyright(C) 2017 Laurent Bachelier
#
# This file is part of a woob module.
#
# This woob module 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.
#
# This woob module 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 this woob module. If not, see .
from woob.tools.backend import Module
from woob.tools.capabilities.paste import BasePasteModule
from .browser import SprungeBrowser, SprungePaste
class SprungeModule(Module, BasePasteModule):
NAME = 'sprunge'
MAINTAINER = u'Laurent Bachelier'
EMAIL = 'laurent@bachelier.name'
VERSION = '3.1'
DESCRIPTION = u'Sprunge text sharing tool'
LICENSE = 'AGPLv3+'
BROWSER = SprungeBrowser
EXPIRATIONS = {
False: 'f',
}
def new_paste(self, *args, **kwargs):
return SprungePaste(*args, **kwargs)
def can_post(self, contents, title=None, public=None, max_age=None):
if public is True:
return 0
if max_age is not None:
if self.get_closest_expiration(max_age) is None:
return 0
if not title:
return 2
return 1
def get_paste(self, _id):
return self.browser.get_paste(_id)
def fill_paste(self, paste, fields):
self.browser.fill_paste(paste)
return paste
def post_paste(self, paste, max_age=None):
self.browser.post_paste(paste)
OBJECTS = {SprungePaste: fill_paste}
woob-18d41565f955028f9fcd2f6cc437f5f1cb717401-modules-sprunge/modules/sprunge/test.py 0000664 0000000 0000000 00000005230 14042356110 0027146 0 ustar 00root root 0000000 0000000 # -*- coding: utf-8 -*-
# Copyright(C) 2017 Laurent Bachelier
#
# This file is part of a woob module.
#
# This woob module 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.
#
# This woob module 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 this woob module. If not, see .
from woob.capabilities.base import NotAvailable
from woob.capabilities.paste import PasteNotFound
from woob.tools.test import BackendTest
class SprungeTest(BackendTest):
MODULE = 'sprunge'
def _get_paste(self, _id):
# html method
p = self.backend.get_paste(_id)
self.backend.fillobj(p, ['title'])
assert p.title is NotAvailable
assert p.page_url.startswith('http://sprunge.us/')
assert p.public is False
def test_post(self):
p = self.backend.new_paste(None, contents=u'Woob Test héhéhé')
self.backend.post_paste(p, max_age=False)
assert p.id
self.backend.fill_paste(p, ['title'])
assert p.title is NotAvailable
assert p.id in p.page_url
assert p.public is False
# test all get methods from the Paste we just created
self._get_paste(p.id)
# same but from the full URL
self._get_paste('http://sprunge.us/%s' % p.id)
def test_notfound(self):
for _id in ('ab',
'http://sprunge.us/ab'):
# html method
p = self.backend.get_paste(_id)
self.assertRaises(PasteNotFound, self.backend.fillobj, p, ['title'])
# raw method
p = self.backend.get_paste(_id)
self.assertRaises(PasteNotFound, self.backend.fillobj, p, ['contents'])
def test_checkurl(self):
# call with an URL we can't handle with this backend
assert self.backend.get_paste('http://pastebin.com/nJG9ZFG8') is None
def test_can_post(self):
assert 2 == self.backend.can_post(u'hello', public=False)
assert 1 == self.backend.can_post(u'hello', public=False, title=u'hello')
assert 1 == self.backend.can_post(u'hello', title=u'hello')
assert 0 == self.backend.can_post(u'hello', public=True)
assert 0 == self.backend.can_post(u'hello', public=False, max_age=3600*24)