/mandos/trunk

To get this branch, use:
bzr branch http://bzr.recompile.se/loggerhead/mandos/trunk

« back to all changes in this revision

Viewing changes to mandos

  • Committer: Teddy Hogeborn
  • Date: 2019-09-01 04:27:59 UTC
  • Revision ID: teddy@recompile.se-20190901042759-dgadz8cg7x9y83ci
Fix minor Python 3 bytes/str mixups

* mandos (PGPEngine.__init__): Use byte string literals, not strings,
                               when working with byte strings.
  (main): When restoring persistent state from a file created by
          Python 2, also convert the "checker_command" setting from a
          byte string to a string, the same as "name" and "host".

Show diffs side-by-side

added added

removed removed

Lines of Context:
203
203
            output = subprocess.check_output(["gpgconf"])
204
204
            for line in output.splitlines():
205
205
                name, text, path = line.split(b":")
206
 
                if name == "gpg":
 
206
                if name == b"gpg":
207
207
                    self.gpg = path
208
208
                    break
209
209
        except OSError as e:
214
214
                          '--force-mdc',
215
215
                          '--quiet']
216
216
        # Only GPG version 1 has the --no-use-agent option.
217
 
        if self.gpg == "gpg" or self.gpg.endswith("/gpg"):
 
217
        if self.gpg == b"gpg" or self.gpg.endswith(b"/gpg"):
218
218
            self.gnupgargs.append("--no-use-agent")
219
219
 
220
220
    def __enter__(self):
3251
3251
                             if isinstance(s, bytes)
3252
3252
                             else s) for s in
3253
3253
                            value["client_structure"]]
3254
 
                        # .name & .host
3255
 
                        for k in ("name", "host"):
 
3254
                        # .name, .host, and .checker_command
 
3255
                        for k in ("name", "host", "checker_command"):
3256
3256
                            if isinstance(value[k], bytes):
3257
3257
                                value[k] = value[k].decode("utf-8")
3258
3258
                        if "key_id" not in value:
3268
3268
                        for key, value in
3269
3269
                        bytes_old_client_settings.items()}
3270
3270
                    del bytes_old_client_settings
3271
 
                    # .host
 
3271
                    # .host and .checker_command
3272
3272
                    for value in old_client_settings.values():
3273
 
                        if isinstance(value["host"], bytes):
3274
 
                            value["host"] = (value["host"]
3275
 
                                             .decode("utf-8"))
 
3273
                        for attribute in ("host", "checker_command"):
 
3274
                            if isinstance(value[attribute], bytes):
 
3275
                                value[attribute] = (value[attribute]
 
3276
                                                    .decode("utf-8"))
3276
3277
            os.remove(stored_state_path)
3277
3278
        except IOError as e:
3278
3279
            if e.errno == errno.ENOENT: