nodes.py 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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. if isinstance(tag, bytes):
  59. try:
  60. tagsloc += u"tag:"+tag.decode()+u"**endtag**"
  61. except:
  62. tagsloc += u"tag:"+tag+u"**endtag**"
  63. dump += tagsloc
  64. dump = [dump]
  65. return dump
  66. @property
  67. def password(self):
  68. """Get the current password."""
  69. enc = CryptoEngine.get()
  70. return enc.decrypt(self._password).strip()
  71. @property
  72. def username(self):
  73. """Get the current username."""
  74. enc = CryptoEngine.get()
  75. return enc.decrypt(self._username).strip()
  76. @username.setter
  77. def username(self, value):
  78. """Set the username."""
  79. enc = CryptoEngine.get()
  80. self._username = enc.encrypt(value).strip()
  81. @password.setter
  82. def password(self, value):
  83. """Set the Notes."""
  84. enc = CryptoEngine.get()
  85. self._password = enc.encrypt(value).strip()
  86. @property
  87. def tags(self):
  88. enc = CryptoEngine.get()
  89. try:
  90. return [enc.decrypt(tag) for tag in filter(None, self._tags)]
  91. except Exception:
  92. return [tag for tag in filter(None, self._tags)]
  93. @tags.setter
  94. def tags(self, value):
  95. self._tags = [tag for tag in value]
  96. @property
  97. def url(self):
  98. """Get the current url."""
  99. enc = CryptoEngine.get()
  100. return enc.decrypt(self._url).strip()
  101. @url.setter
  102. def url(self, value):
  103. """Set the Notes."""
  104. enc = CryptoEngine.get()
  105. self._url = enc.encrypt(value).strip()
  106. @property
  107. def notes(self):
  108. """Get the current notes."""
  109. enc = CryptoEngine.get()
  110. return enc.decrypt(self._notes).strip()
  111. @notes.setter
  112. def notes(self, value):
  113. """Set the Notes."""
  114. enc = CryptoEngine.get()
  115. self._notes = enc.encrypt(value).strip()