Coverage for pass_import/managers/pwsafe.py: 100%
25 statements
« prev ^ index » next coverage.py v7.4.3, created at 2024-02-26 12:11 +0000
« 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#
6import os
8from pass_import.core import register_managers
9from pass_import.formats.xml import XML
12class Pwsafe(XML):
13 """Importer for Pwsafe in XML format."""
14 name = 'pwsafe'
15 url = 'https://pwsafe.org'
16 hexport = 'File > Export To > XML Format'
17 himport = 'pass import pwsafe file.xml'
18 xml_header = {'root': 'passwordsafe'}
19 keyslist = [
20 'title', 'password', 'login', 'url', 'email', 'comments', 'group'
21 ]
22 keys = {
23 'title': 'title',
24 'password': 'password',
25 'login': 'username',
26 'url': 'url',
27 'email': 'email',
28 'comments': 'notes',
29 'group': 'group'
30 }
32 def _import(self, element, path=''):
33 delimiter = element.attrib['delimiter']
34 for xmlentry in element.findall('entry'):
35 entry = self._getentry(xmlentry)
36 entry['group'] = entry.get('group', '').replace('.', os.sep)
37 entry['comments'] = entry.get('comments',
38 '').replace(delimiter, '\n')
39 histkey = './pwhistory/history_entries/history_entry'
40 for historyentry in xmlentry.findall(histkey):
41 for hist in historyentry:
42 xmlkey, value = self._getvalue(hist)
43 xmlkey += historyentry.attrib.get('num', '')
44 entry[xmlkey] = value
45 self.data.append(entry)
48register_managers(Pwsafe)