/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: 2015-05-31 15:56:58 UTC
  • Revision ID: teddy@recompile.se-20150531155658-l7znu7zlqr2dmuwd
mandos: Generate better messages in exceptions.

mandos (ProxyClient.__init__): Include fingerprint in KeyError().
(rfc3339_duration_to_delta): Include duration in ValueError().

Show diffs side-by-side

added added

removed removed

Lines of Context:
78
78
import tempfile
79
79
import itertools
80
80
import collections
 
81
import codecs
81
82
 
82
83
import dbus
83
84
import dbus.service
1671
1672
        self._pipe = child_pipe
1672
1673
        self._pipe.send(('init', fpr, address))
1673
1674
        if not self._pipe.recv():
1674
 
            raise KeyError()
 
1675
            raise KeyError(fpr)
1675
1676
    
1676
1677
    def __getattribute__(self, name):
1677
1678
        if name == '_pipe':
2253
2254
                break
2254
2255
        else:
2255
2256
            # No currently valid tokens were found
2256
 
            raise ValueError("Invalid RFC 3339 duration")
 
2257
            raise ValueError("Invalid RFC 3339 duration: {!r}"
 
2258
                             .format(duration))
2257
2259
    # End token found
2258
2260
    return value
2259
2261
 
2510
2512
            pidfilename = "/var/run/mandos.pid"
2511
2513
        pidfile = None
2512
2514
        try:
2513
 
            pidfile = open(pidfilename, "w")
 
2515
            pidfile = codecs.open(pidfilename, "w", encoding="utf-8")
2514
2516
        except IOError as e:
2515
2517
            logger.error("Could not open file %r", pidfilename,
2516
2518
                         exc_info=e)
2712
2714
    
2713
2715
    if not foreground:
2714
2716
        if pidfile is not None:
 
2717
            pid = os.getpid()
2715
2718
            try:
2716
2719
                with pidfile:
2717
 
                    pid = os.getpid()
2718
 
                    pidfile.write("{}\n".format(pid).encode("utf-8"))
 
2720
                    print(pid, file=pidfile)
2719
2721
            except IOError:
2720
2722
                logger.error("Could not write to file %r with PID %d",
2721
2723
                             pidfilename, pid)