Coverage for pass_import/managers/keepassx.py: 100%

28 statements  

« prev     ^ index     » next       coverage.py v7.4.3, created at 2024-02-26 12:11 +0000

1# -*- encoding: utf-8 -*- 

2# pass import - Passwords importer swiss army knife 

3# Copyright (C) 2017-2024 Alexandre PUJOL <alexandre@pujol.io>. 

4# 

5 

6import os 

7 

8from pass_import.core import register_managers 

9from pass_import.formats.xml import XML 

10 

11 

12class KeepassxXML(XML): 

13 """Importer for KeepassX in XML format.""" 

14 name = 'keepassx' 

15 url = 'https://www.keepassx.org' 

16 hexport = 'File > Export to > Keepass XML File' 

17 himport = 'pass import keepassx file.xml' 

18 group = 'group' 

19 entry = 'entry' 

20 xml_header = { 

21 'doctype': '<!DOCTYPE KEEPASSX_DATABASE>', 

22 'root': 'database' 

23 } 

24 keys = { 

25 'title': 'title', 

26 'password': 'password', 

27 'login': 'username', 

28 'url': 'url', 

29 'comments': 'comment' 

30 } 

31 

32 @classmethod 

33 def _getpath(cls, element, path=''): 

34 title = '' 

35 if element.tag != 'database': 

36 if element.find('title').text: 

37 title = element.find('title').text 

38 return os.path.join(path, title) 

39 

40 def _import(self, element, path=''): 

41 path = self._getpath(element, path) 

42 for group in element.findall(self.group): 

43 self._import(group, path) 

44 for xmlentry in element.findall(self.entry): 

45 entry = self._getentry(xmlentry) 

46 entry['group'] = path 

47 self.data.append(entry) 

48 

49 

50register_managers(KeepassxXML)