(self, data, **kwargs)
| 92 | self.totp_label = '' # custom label on the v3 oneTimeCode field |
| 93 | |
| 94 | def load(self, data, **kwargs): |
| 95 | self.version = kwargs.get('version', 2) |
| 96 | if 'title' in data: |
| 97 | self.title = Record.xstr(data['title']).strip() |
| 98 | if 'notes' in data: |
| 99 | self.notes = Record.xstr(data['notes']) |
| 100 | |
| 101 | if self.version in (1, 2): |
| 102 | self.record_type = 'general' |
| 103 | if 'secret1' in data: |
| 104 | self.login = Record.xstr(data['secret1']) |
| 105 | if 'secret2' in data: |
| 106 | self.password = Record.xstr(data['secret2']) |
| 107 | if 'link' in data: |
| 108 | self.login_url = Record.xstr(data['link']) |
| 109 | if 'custom' in data: |
| 110 | self.custom_fields = data['custom'] or [] |
| 111 | if 'extra' in kwargs and kwargs['extra']: |
| 112 | extra = kwargs['extra'] |
| 113 | self.attachments = extra.get('files') |
| 114 | if 'fields' in extra: |
| 115 | for field in extra['fields']: |
| 116 | if field['field_type'] == 'totp': |
| 117 | self.totp = field['data'] |
| 118 | elif self.version in (3, 5, 6): |
| 119 | self.record_type = data.get('type', 'login') |
| 120 | for field in itertools.chain(data['fields'], data.get('custom') or []): |
| 121 | field_label = field.get('label', '') |
| 122 | field_type = field.get('type', '') |
| 123 | field_value = field.get('value', '') |
| 124 | if isinstance(field_value, list): |
| 125 | if len(field_value) == 1: |
| 126 | field_value = field_value[0] |
| 127 | elif len(field_value) == 0: |
| 128 | field_value = None |
| 129 | if field_value: |
| 130 | if isinstance(field_value, str): |
| 131 | if field_type == 'login' and not self.login: |
| 132 | self.login = field_value |
| 133 | self.login_label = field_label |
| 134 | continue |
| 135 | if field_type == 'password' and not self.password: |
| 136 | self.password = field_value |
| 137 | self.password_label = field_label |
| 138 | continue |
| 139 | if field_type == 'url' and not self.login_url: |
| 140 | self.login_url = field_value |
| 141 | self.url_label = field_label |
| 142 | continue |
| 143 | if field_type == 'oneTimeCode' and not self.totp: |
| 144 | self.totp = field_value |
| 145 | self.totp_label = field_label |
| 146 | continue |
| 147 | |
| 148 | if field_type: |
| 149 | # Only include colon separator if there's a label |
| 150 | field_name = f'{field_type}:{field_label}' if field_label else field_type |
| 151 | elif field_label: |
no test coverage detected