We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
netbsd: no readline
Python build missing readline, likely:
```
    def import_paperkey(self, args):
        # imported here because it has global side effects
>       import readline
E       ImportError: No module named 'readline'

.tox/py34/lib/python3.4/site-packages/borg/crypto/keymanager.py:146: ImportError
```

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `src/borg/crypto/keymanager.py`
Content:
```
1 import binascii
2 import pkgutil
3 import textwrap
4 from binascii import unhexlify, a2b_base64, b2a_base64
5 from hashlib import sha256
6 
7 from ..helpers import Manifest, NoManifestError, Error, yes, bin_to_hex, dash_open
8 from ..repository import Repository
9 
10 from .key import KeyfileKey, KeyfileNotFoundError, KeyBlobStorage, identify_key
11 
12 
13 class UnencryptedRepo(Error):
14     """Keymanagement not available for unencrypted repositories."""
15 
16 
17 class UnknownKeyType(Error):
18     """Keytype {0} is unknown."""
19 
20 
21 class RepoIdMismatch(Error):
22     """This key backup seems to be for a different backup repository, aborting."""
23 
24 
25 class NotABorgKeyFile(Error):
26     """This file is not a borg key backup, aborting."""
27 
28 
29 def sha256_truncated(data, num):
30     h = sha256()
31     h.update(data)
32     return h.hexdigest()[:num]
33 
34 
35 class KeyManager:
36     def __init__(self, repository):
37         self.repository = repository
38         self.keyblob = None
39         self.keyblob_storage = None
40 
41         try:
42             manifest_data = self.repository.get(Manifest.MANIFEST_ID)
43         except Repository.ObjectNotFound:
44             raise NoManifestError
45 
46         key = identify_key(manifest_data)
47         self.keyblob_storage = key.STORAGE
48         if self.keyblob_storage == KeyBlobStorage.NO_STORAGE:
49             raise UnencryptedRepo()
50 
51     def load_keyblob(self):
52         if self.keyblob_storage == KeyBlobStorage.KEYFILE:
53             k = KeyfileKey(self.repository)
54             target = k.find_key()
55             with open(target, 'r') as fd:
56                 self.keyblob = ''.join(fd.readlines()[1:])
57 
58         elif self.keyblob_storage == KeyBlobStorage.REPO:
59             self.keyblob = self.repository.load_key().decode()
60 
61     def store_keyblob(self, args):
62         if self.keyblob_storage == KeyBlobStorage.KEYFILE:
63             k = KeyfileKey(self.repository)
64             try:
65                 target = k.find_key()
66             except KeyfileNotFoundError:
67                 target = k.get_new_target(args)
68 
69             self.store_keyfile(target)
70         elif self.keyblob_storage == KeyBlobStorage.REPO:
71             self.repository.save_key(self.keyblob.encode('utf-8'))
72 
73     def get_keyfile_data(self):
74         data = '%s %s\n' % (KeyfileKey.FILE_ID, bin_to_hex(self.repository.id))
75         data += self.keyblob
76         if not self.keyblob.endswith('\n'):
77             data += '\n'
78         return data
79 
80     def store_keyfile(self, target):
81         with open(target, 'w') as fd:
82             fd.write(self.get_keyfile_data())
83 
84     def export(self, path):
85         self.store_keyfile(path)
86 
87     def export_qr(self, path):
88         with open(path, 'wb') as fd:
89             key_data = self.get_keyfile_data()
90             html = pkgutil.get_data('borg', 'paperkey.html')
91             html = html.replace(b'</textarea>', key_data.encode() + b'</textarea>')
92             fd.write(html)
93 
94     def export_paperkey(self, path):
95         def grouped(s):
96             ret = ''
97             i = 0
98             for ch in s:
99                 if i and i % 6 == 0:
100                     ret += ' '
101                 ret += ch
102                 i += 1
103             return ret
104 
105         export = 'To restore key use borg key import --paper /path/to/repo\n\n'
106 
107         binary = a2b_base64(self.keyblob)
108         export += 'BORG PAPER KEY v1\n'
109         lines = (len(binary) + 17) // 18
110         repoid = bin_to_hex(self.repository.id)[:18]
111         complete_checksum = sha256_truncated(binary, 12)
112         export += 'id: {0:d} / {1} / {2} - {3}\n'.format(lines,
113                                        grouped(repoid),
114                                        grouped(complete_checksum),
115                                        sha256_truncated((str(lines) + '/' + repoid + '/' + complete_checksum).encode('ascii'), 2))
116         idx = 0
117         while len(binary):
118             idx += 1
119             binline = binary[:18]
120             checksum = sha256_truncated(idx.to_bytes(2, byteorder='big') + binline, 2)
121             export += '{0:2d}: {1} - {2}\n'.format(idx, grouped(bin_to_hex(binline)), checksum)
122             binary = binary[18:]
123 
124         if path:
125             with open(path, 'w') as fd:
126                 fd.write(export)
127         else:
128             print(export)
129 
130     def import_keyfile(self, args):
131         file_id = KeyfileKey.FILE_ID
132         first_line = file_id + ' ' + bin_to_hex(self.repository.id) + '\n'
133         with dash_open(args.path, 'r') as fd:
134             file_first_line = fd.read(len(first_line))
135             if file_first_line != first_line:
136                 if not file_first_line.startswith(file_id):
137                     raise NotABorgKeyFile()
138                 else:
139                     raise RepoIdMismatch()
140             self.keyblob = fd.read()
141 
142         self.store_keyblob(args)
143 
144     def import_paperkey(self, args):
145         # imported here because it has global side effects
146         import readline
147 
148         repoid = bin_to_hex(self.repository.id)[:18]
149         try:
150             while True:  # used for repeating on overall checksum mismatch
151                 # id line input
152                 while True:
153                     idline = input('id: ').replace(' ', '')
154                     if idline == "":
155                         if yes("Abort import? [yN]:"):
156                             raise EOFError()
157 
158                     try:
159                         (data, checksum) = idline.split('-')
160                     except ValueError:
161                         print("each line must contain exactly one '-', try again")
162                         continue
163                     try:
164                         (id_lines, id_repoid, id_complete_checksum) = data.split('/')
165                     except ValueError:
166                         print("the id line must contain exactly three '/', try again")
167                         continue
168                     if sha256_truncated(data.lower().encode('ascii'), 2) != checksum:
169                         print('line checksum did not match, try same line again')
170                         continue
171                     try:
172                         lines = int(id_lines)
173                     except ValueError:
174                         print('internal error while parsing length')
175 
176                     break
177 
178                 if repoid != id_repoid:
179                     raise RepoIdMismatch()
180 
181                 result = b''
182                 idx = 1
183                 # body line input
184                 while True:
185                     inline = input('{0:2d}: '.format(idx))
186                     inline = inline.replace(' ', '')
187                     if inline == "":
188                         if yes("Abort import? [yN]:"):
189                             raise EOFError()
190                     try:
191                         (data, checksum) = inline.split('-')
192                     except ValueError:
193                         print("each line must contain exactly one '-', try again")
194                         continue
195                     try:
196                         part = unhexlify(data)
197                     except binascii.Error:
198                         print("only characters 0-9 and a-f and '-' are valid, try again")
199                         continue
200                     if sha256_truncated(idx.to_bytes(2, byteorder='big') + part, 2) != checksum:
201                         print('line checksum did not match, try line {0} again'.format(idx))
202                         continue
203                     result += part
204                     if idx == lines:
205                         break
206                     idx += 1
207 
208                 if sha256_truncated(result, 12) != id_complete_checksum:
209                     print('The overall checksum did not match, retry or enter a blank line to abort.')
210                     continue
211 
212                 self.keyblob = '\n'.join(textwrap.wrap(b2a_base64(result).decode('ascii'))) + '\n'
213                 self.store_keyblob(args)
214                 break
215 
216         except EOFError:
217             print('\n - aborted')
218             return
219
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/src/borg/crypto/keymanager.py b/src/borg/crypto/keymanager.py
--- a/src/borg/crypto/keymanager.py
+++ b/src/borg/crypto/keymanager.py
@@ -142,8 +142,11 @@
         self.store_keyblob(args)
 
     def import_paperkey(self, args):
-        # imported here because it has global side effects
-        import readline
+        try:
+            # imported here because it has global side effects
+            import readline
+        except ImportError:
+            print('Note: No line editing available due to missing readline support')
 
         repoid = bin_to_hex(self.repository.id)[:18]
         try:
@@ -151,8 +154,8 @@
                 # id line input
                 while True:
                     idline = input('id: ').replace(' ', '')
-                    if idline == "":
-                        if yes("Abort import? [yN]:"):
+                    if idline == '':
+                        if yes('Abort import? [yN]:'):
                             raise EOFError()
 
                     try:
@@ -184,8 +187,8 @@
                 while True:
                     inline = input('{0:2d}: '.format(idx))
                     inline = inline.replace(' ', '')
-                    if inline == "":
-                        if yes("Abort import? [yN]:"):
+                    if inline == '':
+                        if yes('Abort import? [yN]:'):
                             raise EOFError()
                     try:
                         (data, checksum) = inline.split('-')

{"golden_diff": "diff --git a/src/borg/crypto/keymanager.py b/src/borg/crypto/keymanager.py\n--- a/src/borg/crypto/keymanager.py\n+++ b/src/borg/crypto/keymanager.py\n@@ -142,8 +142,11 @@\n         self.store_keyblob(args)\n \n     def import_paperkey(self, args):\n-        # imported here because it has global side effects\n-        import readline\n+        try:\n+            # imported here because it has global side effects\n+            import readline\n+        except ImportError:\n+            print('Note: No line editing available due to missing readline support')\n \n         repoid = bin_to_hex(self.repository.id)[:18]\n         try:\n@@ -151,8 +154,8 @@\n                 # id line input\n                 while True:\n                     idline = input('id: ').replace(' ', '')\n-                    if idline == \"\":\n-                        if yes(\"Abort import? [yN]:\"):\n+                    if idline == '':\n+                        if yes('Abort import? [yN]:'):\n                             raise EOFError()\n \n                     try:\n@@ -184,8 +187,8 @@\n                 while True:\n                     inline = input('{0:2d}: '.format(idx))\n                     inline = inline.replace(' ', '')\n-                    if inline == \"\":\n-                        if yes(\"Abort import? [yN]:\"):\n+                    if inline == '':\n+                        if yes('Abort import? [yN]:'):\n                             raise EOFError()\n                     try:\n                         (data, checksum) = inline.split('-')\n", "issue": "netbsd: no readline\nPython build missing readline, likely:\r\n```\r\n    def import_paperkey(self, args):\r\n        # imported here because it has global side effects\r\n>       import readline\r\nE       ImportError: No module named 'readline'\r\n\r\n.tox/py34/lib/python3.4/site-packages/borg/crypto/keymanager.py:146: ImportError\r\n```\n", "before_files": [{"content": "import binascii\nimport pkgutil\nimport textwrap\nfrom binascii import unhexlify, a2b_base64, b2a_base64\nfrom hashlib import sha256\n\nfrom ..helpers import Manifest, NoManifestError, Error, yes, bin_to_hex, dash_open\nfrom ..repository import Repository\n\nfrom .key import KeyfileKey, KeyfileNotFoundError, KeyBlobStorage, identify_key\n\n\nclass UnencryptedRepo(Error):\n    \"\"\"Keymanagement not available for unencrypted repositories.\"\"\"\n\n\nclass UnknownKeyType(Error):\n    \"\"\"Keytype {0} is unknown.\"\"\"\n\n\nclass RepoIdMismatch(Error):\n    \"\"\"This key backup seems to be for a different backup repository, aborting.\"\"\"\n\n\nclass NotABorgKeyFile(Error):\n    \"\"\"This file is not a borg key backup, aborting.\"\"\"\n\n\ndef sha256_truncated(data, num):\n    h = sha256()\n    h.update(data)\n    return h.hexdigest()[:num]\n\n\nclass KeyManager:\n    def __init__(self, repository):\n        self.repository = repository\n        self.keyblob = None\n        self.keyblob_storage = None\n\n        try:\n            manifest_data = self.repository.get(Manifest.MANIFEST_ID)\n        except Repository.ObjectNotFound:\n            raise NoManifestError\n\n        key = identify_key(manifest_data)\n        self.keyblob_storage = key.STORAGE\n        if self.keyblob_storage == KeyBlobStorage.NO_STORAGE:\n            raise UnencryptedRepo()\n\n    def load_keyblob(self):\n        if self.keyblob_storage == KeyBlobStorage.KEYFILE:\n            k = KeyfileKey(self.repository)\n            target = k.find_key()\n            with open(target, 'r') as fd:\n                self.keyblob = ''.join(fd.readlines()[1:])\n\n        elif self.keyblob_storage == KeyBlobStorage.REPO:\n            self.keyblob = self.repository.load_key().decode()\n\n    def store_keyblob(self, args):\n        if self.keyblob_storage == KeyBlobStorage.KEYFILE:\n            k = KeyfileKey(self.repository)\n            try:\n                target = k.find_key()\n            except KeyfileNotFoundError:\n                target = k.get_new_target(args)\n\n            self.store_keyfile(target)\n        elif self.keyblob_storage == KeyBlobStorage.REPO:\n            self.repository.save_key(self.keyblob.encode('utf-8'))\n\n    def get_keyfile_data(self):\n        data = '%s %s\\n' % (KeyfileKey.FILE_ID, bin_to_hex(self.repository.id))\n        data += self.keyblob\n        if not self.keyblob.endswith('\\n'):\n            data += '\\n'\n        return data\n\n    def store_keyfile(self, target):\n        with open(target, 'w') as fd:\n            fd.write(self.get_keyfile_data())\n\n    def export(self, path):\n        self.store_keyfile(path)\n\n    def export_qr(self, path):\n        with open(path, 'wb') as fd:\n            key_data = self.get_keyfile_data()\n            html = pkgutil.get_data('borg', 'paperkey.html')\n            html = html.replace(b'</textarea>', key_data.encode() + b'</textarea>')\n            fd.write(html)\n\n    def export_paperkey(self, path):\n        def grouped(s):\n            ret = ''\n            i = 0\n            for ch in s:\n                if i and i % 6 == 0:\n                    ret += ' '\n                ret += ch\n                i += 1\n            return ret\n\n        export = 'To restore key use borg key import --paper /path/to/repo\\n\\n'\n\n        binary = a2b_base64(self.keyblob)\n        export += 'BORG PAPER KEY v1\\n'\n        lines = (len(binary) + 17) // 18\n        repoid = bin_to_hex(self.repository.id)[:18]\n        complete_checksum = sha256_truncated(binary, 12)\n        export += 'id: {0:d} / {1} / {2} - {3}\\n'.format(lines,\n                                       grouped(repoid),\n                                       grouped(complete_checksum),\n                                       sha256_truncated((str(lines) + '/' + repoid + '/' + complete_checksum).encode('ascii'), 2))\n        idx = 0\n        while len(binary):\n            idx += 1\n            binline = binary[:18]\n            checksum = sha256_truncated(idx.to_bytes(2, byteorder='big') + binline, 2)\n            export += '{0:2d}: {1} - {2}\\n'.format(idx, grouped(bin_to_hex(binline)), checksum)\n            binary = binary[18:]\n\n        if path:\n            with open(path, 'w') as fd:\n                fd.write(export)\n        else:\n            print(export)\n\n    def import_keyfile(self, args):\n        file_id = KeyfileKey.FILE_ID\n        first_line = file_id + ' ' + bin_to_hex(self.repository.id) + '\\n'\n        with dash_open(args.path, 'r') as fd:\n            file_first_line = fd.read(len(first_line))\n            if file_first_line != first_line:\n                if not file_first_line.startswith(file_id):\n                    raise NotABorgKeyFile()\n                else:\n                    raise RepoIdMismatch()\n            self.keyblob = fd.read()\n\n        self.store_keyblob(args)\n\n    def import_paperkey(self, args):\n        # imported here because it has global side effects\n        import readline\n\n        repoid = bin_to_hex(self.repository.id)[:18]\n        try:\n            while True:  # used for repeating on overall checksum mismatch\n                # id line input\n                while True:\n                    idline = input('id: ').replace(' ', '')\n                    if idline == \"\":\n                        if yes(\"Abort import? [yN]:\"):\n                            raise EOFError()\n\n                    try:\n                        (data, checksum) = idline.split('-')\n                    except ValueError:\n                        print(\"each line must contain exactly one '-', try again\")\n                        continue\n                    try:\n                        (id_lines, id_repoid, id_complete_checksum) = data.split('/')\n                    except ValueError:\n                        print(\"the id line must contain exactly three '/', try again\")\n                        continue\n                    if sha256_truncated(data.lower().encode('ascii'), 2) != checksum:\n                        print('line checksum did not match, try same line again')\n                        continue\n                    try:\n                        lines = int(id_lines)\n                    except ValueError:\n                        print('internal error while parsing length')\n\n                    break\n\n                if repoid != id_repoid:\n                    raise RepoIdMismatch()\n\n                result = b''\n                idx = 1\n                # body line input\n                while True:\n                    inline = input('{0:2d}: '.format(idx))\n                    inline = inline.replace(' ', '')\n                    if inline == \"\":\n                        if yes(\"Abort import? [yN]:\"):\n                            raise EOFError()\n                    try:\n                        (data, checksum) = inline.split('-')\n                    except ValueError:\n                        print(\"each line must contain exactly one '-', try again\")\n                        continue\n                    try:\n                        part = unhexlify(data)\n                    except binascii.Error:\n                        print(\"only characters 0-9 and a-f and '-' are valid, try again\")\n                        continue\n                    if sha256_truncated(idx.to_bytes(2, byteorder='big') + part, 2) != checksum:\n                        print('line checksum did not match, try line {0} again'.format(idx))\n                        continue\n                    result += part\n                    if idx == lines:\n                        break\n                    idx += 1\n\n                if sha256_truncated(result, 12) != id_complete_checksum:\n                    print('The overall checksum did not match, retry or enter a blank line to abort.')\n                    continue\n\n                self.keyblob = '\\n'.join(textwrap.wrap(b2a_base64(result).decode('ascii'))) + '\\n'\n                self.store_keyblob(args)\n                break\n\n        except EOFError:\n            print('\\n - aborted')\n            return\n", "path": "src/borg/crypto/keymanager.py"}], "after_files": [{"content": "import binascii\nimport pkgutil\nimport textwrap\nfrom binascii import unhexlify, a2b_base64, b2a_base64\nfrom hashlib import sha256\n\nfrom ..helpers import Manifest, NoManifestError, Error, yes, bin_to_hex, dash_open\nfrom ..repository import Repository\n\nfrom .key import KeyfileKey, KeyfileNotFoundError, KeyBlobStorage, identify_key\n\n\nclass UnencryptedRepo(Error):\n    \"\"\"Keymanagement not available for unencrypted repositories.\"\"\"\n\n\nclass UnknownKeyType(Error):\n    \"\"\"Keytype {0} is unknown.\"\"\"\n\n\nclass RepoIdMismatch(Error):\n    \"\"\"This key backup seems to be for a different backup repository, aborting.\"\"\"\n\n\nclass NotABorgKeyFile(Error):\n    \"\"\"This file is not a borg key backup, aborting.\"\"\"\n\n\ndef sha256_truncated(data, num):\n    h = sha256()\n    h.update(data)\n    return h.hexdigest()[:num]\n\n\nclass KeyManager:\n    def __init__(self, repository):\n        self.repository = repository\n        self.keyblob = None\n        self.keyblob_storage = None\n\n        try:\n            manifest_data = self.repository.get(Manifest.MANIFEST_ID)\n        except Repository.ObjectNotFound:\n            raise NoManifestError\n\n        key = identify_key(manifest_data)\n        self.keyblob_storage = key.STORAGE\n        if self.keyblob_storage == KeyBlobStorage.NO_STORAGE:\n            raise UnencryptedRepo()\n\n    def load_keyblob(self):\n        if self.keyblob_storage == KeyBlobStorage.KEYFILE:\n            k = KeyfileKey(self.repository)\n            target = k.find_key()\n            with open(target, 'r') as fd:\n                self.keyblob = ''.join(fd.readlines()[1:])\n\n        elif self.keyblob_storage == KeyBlobStorage.REPO:\n            self.keyblob = self.repository.load_key().decode()\n\n    def store_keyblob(self, args):\n        if self.keyblob_storage == KeyBlobStorage.KEYFILE:\n            k = KeyfileKey(self.repository)\n            try:\n                target = k.find_key()\n            except KeyfileNotFoundError:\n                target = k.get_new_target(args)\n\n            self.store_keyfile(target)\n        elif self.keyblob_storage == KeyBlobStorage.REPO:\n            self.repository.save_key(self.keyblob.encode('utf-8'))\n\n    def get_keyfile_data(self):\n        data = '%s %s\\n' % (KeyfileKey.FILE_ID, bin_to_hex(self.repository.id))\n        data += self.keyblob\n        if not self.keyblob.endswith('\\n'):\n            data += '\\n'\n        return data\n\n    def store_keyfile(self, target):\n        with open(target, 'w') as fd:\n            fd.write(self.get_keyfile_data())\n\n    def export(self, path):\n        self.store_keyfile(path)\n\n    def export_qr(self, path):\n        with open(path, 'wb') as fd:\n            key_data = self.get_keyfile_data()\n            html = pkgutil.get_data('borg', 'paperkey.html')\n            html = html.replace(b'</textarea>', key_data.encode() + b'</textarea>')\n            fd.write(html)\n\n    def export_paperkey(self, path):\n        def grouped(s):\n            ret = ''\n            i = 0\n            for ch in s:\n                if i and i % 6 == 0:\n                    ret += ' '\n                ret += ch\n                i += 1\n            return ret\n\n        export = 'To restore key use borg key import --paper /path/to/repo\\n\\n'\n\n        binary = a2b_base64(self.keyblob)\n        export += 'BORG PAPER KEY v1\\n'\n        lines = (len(binary) + 17) // 18\n        repoid = bin_to_hex(self.repository.id)[:18]\n        complete_checksum = sha256_truncated(binary, 12)\n        export += 'id: {0:d} / {1} / {2} - {3}\\n'.format(lines,\n                                       grouped(repoid),\n                                       grouped(complete_checksum),\n                                       sha256_truncated((str(lines) + '/' + repoid + '/' + complete_checksum).encode('ascii'), 2))\n        idx = 0\n        while len(binary):\n            idx += 1\n            binline = binary[:18]\n            checksum = sha256_truncated(idx.to_bytes(2, byteorder='big') + binline, 2)\n            export += '{0:2d}: {1} - {2}\\n'.format(idx, grouped(bin_to_hex(binline)), checksum)\n            binary = binary[18:]\n\n        if path:\n            with open(path, 'w') as fd:\n                fd.write(export)\n        else:\n            print(export)\n\n    def import_keyfile(self, args):\n        file_id = KeyfileKey.FILE_ID\n        first_line = file_id + ' ' + bin_to_hex(self.repository.id) + '\\n'\n        with dash_open(args.path, 'r') as fd:\n            file_first_line = fd.read(len(first_line))\n            if file_first_line != first_line:\n                if not file_first_line.startswith(file_id):\n                    raise NotABorgKeyFile()\n                else:\n                    raise RepoIdMismatch()\n            self.keyblob = fd.read()\n\n        self.store_keyblob(args)\n\n    def import_paperkey(self, args):\n        try:\n            # imported here because it has global side effects\n            import readline\n        except ImportError:\n            print('Note: No line editing available due to missing readline support')\n\n        repoid = bin_to_hex(self.repository.id)[:18]\n        try:\n            while True:  # used for repeating on overall checksum mismatch\n                # id line input\n                while True:\n                    idline = input('id: ').replace(' ', '')\n                    if idline == '':\n                        if yes('Abort import? [yN]:'):\n                            raise EOFError()\n\n                    try:\n                        (data, checksum) = idline.split('-')\n                    except ValueError:\n                        print(\"each line must contain exactly one '-', try again\")\n                        continue\n                    try:\n                        (id_lines, id_repoid, id_complete_checksum) = data.split('/')\n                    except ValueError:\n                        print(\"the id line must contain exactly three '/', try again\")\n                        continue\n                    if sha256_truncated(data.lower().encode('ascii'), 2) != checksum:\n                        print('line checksum did not match, try same line again')\n                        continue\n                    try:\n                        lines = int(id_lines)\n                    except ValueError:\n                        print('internal error while parsing length')\n\n                    break\n\n                if repoid != id_repoid:\n                    raise RepoIdMismatch()\n\n                result = b''\n                idx = 1\n                # body line input\n                while True:\n                    inline = input('{0:2d}: '.format(idx))\n                    inline = inline.replace(' ', '')\n                    if inline == '':\n                        if yes('Abort import? [yN]:'):\n                            raise EOFError()\n                    try:\n                        (data, checksum) = inline.split('-')\n                    except ValueError:\n                        print(\"each line must contain exactly one '-', try again\")\n                        continue\n                    try:\n                        part = unhexlify(data)\n                    except binascii.Error:\n                        print(\"only characters 0-9 and a-f and '-' are valid, try again\")\n                        continue\n                    if sha256_truncated(idx.to_bytes(2, byteorder='big') + part, 2) != checksum:\n                        print('line checksum did not match, try line {0} again'.format(idx))\n                        continue\n                    result += part\n                    if idx == lines:\n                        break\n                    idx += 1\n\n                if sha256_truncated(result, 12) != id_complete_checksum:\n                    print('The overall checksum did not match, retry or enter a blank line to abort.')\n                    continue\n\n                self.keyblob = '\\n'.join(textwrap.wrap(b2a_base64(result).decode('ascii'))) + '\\n'\n                self.store_keyblob(args)\n                break\n\n        except EOFError:\n            print('\\n - aborted')\n            return\n", "path": "src/borg/crypto/keymanager.py"}]}