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

41 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 json 

7 

8from pass_import.core import register_managers 

9from pass_import.formats.csv import CSV 

10from pass_import.formats.json import JSON 

11 

12 

13class BlurCSV(CSV): 

14 """Importer for Blur in CSV format.""" 

15 name = 'blur' 

16 secure = False 

17 default = False 

18 url = 'https://abine.com' 

19 hexport = 'Settings: Export Data: Export CSV: Accounts: Export CSV' 

20 himport = 'pass import blur file.csv' 

21 keys = { 

22 'title': 'label', 

23 'password': 'password', 

24 'login': 'username', 

25 'email': 'email', 

26 'url': 'domain', 

27 } 

28 

29 def parse(self): 

30 """Parse Blur CSV file.""" 

31 super().parse() 

32 for entry in self.data: 

33 for key in entry: 

34 if entry[key] == 'undefined': 

35 entry[key] = '' 

36 

37 

38class BlurJSON(JSON): 

39 """Importer for Blur in JSON format.""" 

40 name = 'blur' 

41 secure = False 

42 url = 'https://abine.com' 

43 hexport = 'Settings: Export Data: Export Blur Data' 

44 himport = 'pass import blur file.json' 

45 ignore = {'id'} 

46 keys = { 

47 'title': 'label', 

48 'password': 'password', 

49 'login': 'username', 

50 'email': 'email', 

51 'url': 'domain', 

52 'comments': 'description' 

53 } 

54 json_header = { 

55 'dntmeExport': True, 

56 'accounts': list, 

57 'cards': list, 

58 'addresses': list, 

59 'notes': list, 

60 'identities': list, 

61 } 

62 

63 def parse(self): 

64 """Parse Blur JSON file.""" 

65 jsons = json.loads(self.file.read()) 

66 keys = self.invkeys() 

67 

68 items = [] 

69 for key in ['accounts', 'cards', 'addresses', 'notes', 'identities']: 

70 items.extend(jsons.get(key, [])) 

71 

72 for item in items: 

73 entry = {} 

74 for key, value in item.items(): 

75 if key in self.ignore or value == 'undefined': 

76 continue 

77 entry[keys.get(key, key)] = value 

78 self.data.append(entry) 

79 

80 

81register_managers(BlurCSV, BlurJSON)