CapPaste: Also check the title in can_post
Because unsurprisingly pastealacon has silly restrictions.
This commit is contained in:
parent
0d2148bd84
commit
dd6864c2c4
4 changed files with 18 additions and 10 deletions
|
|
@ -20,6 +20,8 @@
|
|||
|
||||
from __future__ import with_statement
|
||||
|
||||
import re
|
||||
|
||||
from weboob.tools.capabilities.paste import BasePasteBackend
|
||||
from weboob.tools.backend import BaseBackend
|
||||
from weboob.capabilities.base import NotLoaded
|
||||
|
|
@ -49,7 +51,7 @@ class PastealaconBackend(BaseBackend, BasePasteBackend):
|
|||
def new_paste(self, *args, **kwargs):
|
||||
return PastealaconPaste(*args, **kwargs)
|
||||
|
||||
def can_post(self, contents, public=None, max_age=None):
|
||||
def can_post(self, contents, title=None, public=None, max_age=None):
|
||||
try:
|
||||
contents.encode(self.browser.ENCODING)
|
||||
except UnicodeEncodeError:
|
||||
|
|
@ -59,6 +61,9 @@ class PastealaconBackend(BaseBackend, BasePasteBackend):
|
|||
if max_age is not None:
|
||||
if self.get_closest_expiration(max_age) is None:
|
||||
return 0
|
||||
# the "title" is filtered (does not even accepts dots)
|
||||
if not title or re.match('^\w+$', title) and len(title) <= 24:
|
||||
return 2
|
||||
return 1
|
||||
|
||||
def get_paste(self, _id):
|
||||
|
|
|
|||
|
|
@ -82,12 +82,12 @@ class PastealaconTest(BackendTest):
|
|||
|
||||
def test_can_post(self):
|
||||
assert 0 == self.backend.can_post('hello', public=False)
|
||||
assert 1 == self.backend.can_post('hello', public=True)
|
||||
assert 1 <= self.backend.can_post('hello', public=True)
|
||||
assert 0 == self.backend.can_post('hello', public=True, max_age=600)
|
||||
assert 1 == self.backend.can_post('hello', public=True, max_age=3600*24)
|
||||
assert 1 == self.backend.can_post('hello', public=True, max_age=3600*24*3)
|
||||
assert 1 == self.backend.can_post('hello', public=True, max_age=False)
|
||||
assert 1 == self.backend.can_post('hello', public=None, max_age=False)
|
||||
assert 1 == self.backend.can_post('hello', public=True, max_age=3600*24*40)
|
||||
assert 1 == self.backend.can_post(u'héhé', public=True)
|
||||
assert 1 <= self.backend.can_post('hello', public=True, max_age=3600*24)
|
||||
assert 1 <= self.backend.can_post('hello', public=True, max_age=3600*24*3)
|
||||
assert 1 <= self.backend.can_post('hello', public=True, max_age=False)
|
||||
assert 1 <= self.backend.can_post('hello', public=None, max_age=False)
|
||||
assert 1 <= self.backend.can_post('hello', public=True, max_age=3600*24*40)
|
||||
assert 1 <= self.backend.can_post(u'héhé', public=True)
|
||||
assert 0 == self.backend.can_post(u'hello ♥', public=True)
|
||||
|
|
|
|||
|
|
@ -63,10 +63,12 @@ class PastebinBackend(BaseBackend, BasePasteBackend):
|
|||
def new_paste(self, *args, **kwargs):
|
||||
return PastebinPaste(*args, **kwargs)
|
||||
|
||||
def can_post(self, contents, public=None, max_age=None):
|
||||
def can_post(self, contents, title=None, public=None, max_age=None):
|
||||
if max_age is not None:
|
||||
if self.get_closest_expiration(max_age) is None:
|
||||
return 0
|
||||
if not title or len(title) <= 60:
|
||||
return 2
|
||||
return 1
|
||||
|
||||
def get_paste(self, _id):
|
||||
|
|
|
|||
|
|
@ -64,13 +64,14 @@ class ICapPaste(IBaseCap):
|
|||
"""
|
||||
raise NotImplementedError()
|
||||
|
||||
def can_post(self, contents, public=None, max_age=None):
|
||||
def can_post(self, contents, title=None, public=None, max_age=None):
|
||||
"""
|
||||
Checks if the paste can be pasted by this backend.
|
||||
Some properties are considered required (public/private, max_age) while others
|
||||
are just bonuses (language).
|
||||
|
||||
contents: Can be used to check encodability, maximum length, etc.
|
||||
title: Can be used to check length, allowed characters. Should not be required.
|
||||
public: True must be public, False must be private, None do not care.
|
||||
max_age: Maximum time to live in seconds.
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue