/modules/zerobin/module.py

https://github.com/laurentb/weboob · Python · 83 lines · 34 code · 15 blank · 34 comment · 5 complexity · fa1e5bce44a18c2f6f1a91b70cd4c2e0 MD5 · raw file

  1. # -*- coding: utf-8 -*-
  2. # Copyright(C) 2016 Vincent A
  3. #
  4. # This file is part of a weboob module.
  5. #
  6. # This weboob module is free software: you can redistribute it and/or modify
  7. # it under the terms of the GNU Affero General Public License as published by
  8. # the Free Software Foundation, either version 3 of the License, or
  9. # (at your option) any later version.
  10. #
  11. # This weboob module is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU Affero General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU Affero General Public License
  17. # along with this weboob module. If not, see <http://www.gnu.org/licenses/>.
  18. from weboob.tools.backend import Module, BackendConfig
  19. from weboob.tools.value import Value, ValueBool
  20. from weboob.capabilities.paste import CapPaste
  21. from .browser import ZerobinBrowser, ZeroPaste
  22. __all__ = ['ZerobinModule']
  23. class ZerobinModule(Module, CapPaste):
  24. NAME = 'zerobin'
  25. DESCRIPTION = u'ZeroBin/0bin/PrivateBin encrypted pastebin'
  26. MAINTAINER = u'Vincent A'
  27. EMAIL = 'dev@indigo.re'
  28. LICENSE = 'AGPLv3+'
  29. VERSION = '2.1'
  30. CONFIG = BackendConfig(
  31. Value('url', label='URL of the zerobin/0bin/privatebin', regexp='https?://.*', default='https://zerobin.net'),
  32. ValueBool('discussion', label='Allow paste comments (ZeroBin only)', default=False),
  33. )
  34. BROWSER = ZerobinBrowser
  35. def create_default_browser(self):
  36. return self.create_browser(self.config['url'].get(), self.config['discussion'].get())
  37. def can_post(self, contents, title=None, public=None, max_age=None):
  38. """
  39. Checks if the paste can be pasted by this backend.
  40. Some properties are considered required (public/private, max_age) while others
  41. are just bonuses (language).
  42. contents: Can be used to check encodability, maximum length, etc.
  43. title: Can be used to check length, allowed characters. Should not be required.
  44. public: True must be public, False must be private, None do not care.
  45. max_age: Maximum time to live in seconds.
  46. A score of 0 means the backend is not suitable.
  47. A score of 1 means the backend is suitable.
  48. Higher scores means it is more suitable than others with a lower score.
  49. :rtype: int
  50. :returns: score
  51. """
  52. if public:
  53. return 0
  54. return self.browser.can_post(contents, max_age)
  55. def get_paste(self, id):
  56. if '#' not in id:
  57. return
  58. elif id.startswith('http://') or id.startswith('https://'):
  59. if not id.startswith(self.config['url'].get()):
  60. return
  61. return self.browser.get_paste(id)
  62. def new_paste(self, *args, **kwargs):
  63. return ZeroPaste(*args, **kwargs)
  64. def post_paste(self, paste, max_age=None):
  65. self.browser.post_paste(paste, max_age)