Skip to content

Commit 98b323e

Browse files
committed
correctly handle group/entry repr when path contains None
1 parent a778eeb commit 98b323e

7 files changed

Lines changed: 17 additions & 3 deletions

File tree

pykeepass/entry.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,9 @@ def is_a_history_entry(self):
220220

221221
@property
222222
def path(self):
223+
"""Path to element as list. List contains all parent group names
224+
ending with entry title. List may contain strings or NoneTypes."""
225+
223226
# The root group is an orphan
224227
if self.parentgroup is None:
225228
return None
@@ -282,7 +285,8 @@ def save_history(self):
282285
self._element.append(history)
283286

284287
def __str__(self):
285-
pathstr = '/'.join(self.path)
288+
# filter out NoneTypes and join into string
289+
pathstr = '/'.join('' if p==None else p for p in self.path)
286290
if self.is_a_history_entry:
287291
return '[History of: {}]'.format(pathstr)
288292
return 'Entry: "{} ({})"'.format(pathstr, self.username)

pykeepass/group.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,5 +94,6 @@ def append(self, entries):
9494
self._element.append(entries._element)
9595

9696
def __str__(self):
97-
pathstr = '/'.join(self.path)
97+
# filter out NoneTypes and join into string
98+
pathstr = '/'.join('' if p==None else p for p in self.path)
9899
return 'Group: "{}"'.format(pathstr)

tests/test3.kdbx

80 Bytes
Binary file not shown.

tests/test3_transformed.kdbx

4.22 KB
Binary file not shown.

tests/test4.kdbx

70 Bytes
Binary file not shown.

tests/test4_transformed.kdbx

4.33 KB
Binary file not shown.

tests/tests.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,11 @@ def test_print_entries(self):
277277
self.assertIsInstance(e.__repr__(), str)
278278
self.assertIsInstance(e.history.__repr__(), str)
279279

280+
# issue 250
281+
e = self.kp.find_entries(username='blank_title', first=True)
282+
self.assertIsNot(e, None)
283+
self.assertIsInstance(e.__repr__(), str)
284+
280285

281286
class GroupFindTests3(KDBX3Tests):
282287

@@ -317,7 +322,7 @@ def test_find_groups_by_notes(self):
317322
def test_groups(self):
318323
results = self.kp.groups
319324

320-
self.assertEqual(len(results), 6)
325+
self.assertEqual(len(results), 7)
321326

322327
# ---------- Adding/Deleting Groups -----------
323328

@@ -349,6 +354,10 @@ def test_add_delete_move_group(self):
349354
def test_print_groups(self):
350355
self.assertIsInstance(self.kp.groups.__repr__(), str)
351356

357+
g = self.kp.find_groups(notes='blank_name')
358+
self.assertIsNot(g, None)
359+
self.assertIsInstance(g.__repr__(), str)
360+
352361
class RecycleBinTests3(KDBX3Tests):
353362

354363
def test_recyclebincreation(self):

0 commit comments

Comments
 (0)