nodes.py 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. #============================================================================
  2. # This file is part of Pwman3.
  3. #
  4. # Pwman3 is free software; you can redistribute it and/or modify
  5. # it under the terms of the GNU General Public License, version 2
  6. # as published by the Free Software Foundation;
  7. #
  8. # Pwman3 is distributed in the hope that it will be useful,
  9. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. # GNU General Public License for more details.
  12. #
  13. # You should have received a copy of the GNU General Public License
  14. # along with Pwman3; if not, write to the Free Software
  15. # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  16. #============================================================================
  17. # Copyright (C) 2012 Oz Nahum <nahumoz@gmail.com>
  18. #============================================================================
  19. #============================================================================
  20. # Copyright (C) 2006 Ivan Kelly <ivan@ivankelly.net>
  21. #============================================================================
  22. from pwman.util.crypto_engine import CryptoEngine
  23. class NewNode(object):
  24. def __str__(self): # pragma: no cover
  25. enc = CryptoEngine.get()
  26. try:
  27. tags = ', '.join([enc.decrypt(tag).strip() for tag in filter(None,
  28. self._tags)])
  29. except Exception:
  30. tags = ', '.join([tag.strip() for tag in filter(None, self._tags)])
  31. user = enc.decrypt(self._username).strip()
  32. url = enc.decrypt(self._url).strip()
  33. return '{0}@{1}\t{2}'.format(user, url,
  34. tags)
  35. def dump_edit_to_db(self):
  36. dump = u""
  37. try:
  38. dump += u"username:"+self._username.decode()+u"##"
  39. except AttributeError:
  40. dump += u"username:"+self._username+u"##"
  41. try:
  42. dump += u"password:"+self._password.decode()+u"##"
  43. except AttributeError:
  44. dump += u"password:"+self._password+u"##"
  45. try:
  46. dump += u"url:"+self._url.decode()+u"##"
  47. except AttributeError:
  48. dump += u"url:"+self._url+u"##"
  49. try:
  50. dump += u"notes:"+self._notes.decode()+u"##"
  51. except AttributeError:
  52. dump += u"notes:"+self._notes+u"##"
  53. dump += u"tags:"
  54. tagsloc = u""
  55. for tag in self._tags:
  56. if isinstance(tag, str):
  57. tagsloc += u"tag:"+tag.strip()+u"**endtag**"
  58. else:
  59. tagsloc += u'tag:'+tag._name.decode()+u'**endtag**'
  60. dump += tagsloc
  61. dump = [dump]
  62. return dump
  63. @property
  64. def password(self):
  65. """Get the current password."""
  66. enc = CryptoEngine.get()
  67. return enc.decrypt(self._password).strip()
  68. @property
  69. def username(self):
  70. """Get the current username."""
  71. enc = CryptoEngine.get()
  72. return enc.decrypt(self._username).strip()
  73. @username.setter
  74. def username(self, value):
  75. """Set the username."""
  76. enc = CryptoEngine.get()
  77. self._username = enc.encrypt(value).strip()
  78. @password.setter
  79. def password(self, value):
  80. """Set the Notes."""
  81. enc = CryptoEngine.get()
  82. self._password = enc.encrypt(value).strip()
  83. @property
  84. def tags(self):
  85. enc = CryptoEngine.get()
  86. try:
  87. return [enc.decrypt(tag) for tag in filter(None, self._tags)]
  88. except Exception:
  89. return [tag for tag in filter(None, self._tags)]
  90. @tags.setter
  91. def tags(self, value):
  92. self._tags = [tag for tag in value]
  93. @property
  94. def url(self):
  95. """Get the current url."""
  96. enc = CryptoEngine.get()
  97. return enc.decrypt(self._url).strip()
  98. @url.setter
  99. def url(self, value):
  100. """Set the Notes."""
  101. enc = CryptoEngine.get()
  102. self._url = enc.encrypt(value).strip()
  103. @property
  104. def notes(self):
  105. """Get the current notes."""
  106. enc = CryptoEngine.get()
  107. return enc.decrypt(self._notes).strip()
  108. @notes.setter
  109. def notes(self, value):
  110. """Set the Notes."""
  111. enc = CryptoEngine.get()
  112. self._notes = enc.encrypt(value).strip()