/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:29:22 UTC
  • Revision ID: teddy@recompile.se-20150531152922-o1xv6qr3hbj1twm0
mandos: Use codecs.open() and print() for PID file.

Use more Pythonic code, closer to the Python 3 style.

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
2510
2511
            pidfilename = "/var/run/mandos.pid"
2511
2512
        pidfile = None
2512
2513
        try:
2513
 
            pidfile = open(pidfilename, "w")
 
2514
            pidfile = codecs.open(pidfilename, "w", encoding="utf-8")
2514
2515
        except IOError as e:
2515
2516
            logger.error("Could not open file %r", pidfilename,
2516
2517
                         exc_info=e)
2712
2713
    
2713
2714
    if not foreground:
2714
2715
        if pidfile is not None:
 
2716
            pid = os.getpid()
2715
2717
            try:
2716
2718
                with pidfile:
2717
 
                    pid = os.getpid()
2718
 
                    pidfile.write("{}\n".format(pid).encode("utf-8"))
 
2719
                    print(pid, file=pidfile)
2719
2720
            except IOError:
2720
2721
                logger.error("Could not write to file %r with PID %d",
2721
2722
                             pidfilename, pid)