CapPaste: check the contents in can_post
For pastealacon, it is used to check for encoding compatibility.
This commit is contained in:
parent
56fe4448d3
commit
0d2148bd84
6 changed files with 32 additions and 22 deletions
|
|
@ -49,7 +49,11 @@ class PastealaconBackend(BaseBackend, BasePasteBackend):
|
|||
def new_paste(self, *args, **kwargs):
|
||||
return PastealaconPaste(*args, **kwargs)
|
||||
|
||||
def can_post(self, public=None, max_age=None):
|
||||
def can_post(self, contents, public=None, max_age=None):
|
||||
try:
|
||||
contents.encode(self.browser.ENCODING)
|
||||
except UnicodeEncodeError:
|
||||
return 0
|
||||
if public is False:
|
||||
return 0
|
||||
if max_age is not None:
|
||||
|
|
|
|||
|
|
@ -81,11 +81,13 @@ class PastealaconTest(BackendTest):
|
|||
assert self.backend.get_paste('nJG9ZFG8') is None
|
||||
|
||||
def test_can_post(self):
|
||||
assert 0 == self.backend.can_post(public=False)
|
||||
assert 1 == self.backend.can_post(public=True)
|
||||
assert 0 == self.backend.can_post(public=True, max_age=600)
|
||||
assert 1 == self.backend.can_post(public=True, max_age=3600*24)
|
||||
assert 1 == self.backend.can_post(public=True, max_age=3600*24*3)
|
||||
assert 1 == self.backend.can_post(public=True, max_age=False)
|
||||
assert 1 == self.backend.can_post(public=None, max_age=False)
|
||||
assert 1 == self.backend.can_post(public=True, max_age=3600*24*40)
|
||||
assert 0 == self.backend.can_post('hello', public=False)
|
||||
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 0 == self.backend.can_post(u'hello ♥', public=True)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue