~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/gpg.py

  • Committer: Jan Balster
  • Date: 2006-08-15 13:13:27 UTC
  • mto: This revision was merged to the branch mainline in revision 1928.
  • Revision ID: jan@merlinux.de-20060815131327-c6db553def157b26
added .perf-history to the ignore file

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005 Canonical Ltd
 
1
# Copyright (C) 2005 by Canonical Ltd
2
2
#   Authors: Robert Collins <robert.collins@canonical.com>
3
3
#
4
4
# This program is free software; you can redistribute it and/or modify
13
13
#
14
14
# You should have received a copy of the GNU General Public License
15
15
# along with this program; if not, write to the Free Software
16
 
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
16
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17
17
 
18
18
"""GPG signing and checking logic."""
19
19
 
 
20
import errno
20
21
import os
21
 
import sys
22
 
 
23
 
from bzrlib.lazy_import import lazy_import
24
 
lazy_import(globals(), """
25
 
import errno
26
22
import subprocess
27
23
 
28
24
from bzrlib import (
29
25
    errors,
30
26
    trace,
31
 
    ui,
32
27
    )
33
 
""")
34
28
 
35
29
 
36
30
class DisabledGPGStrategy(object):
50
44
        """Real strategies take a configuration."""
51
45
 
52
46
    def sign(self, content):
53
 
        return ("-----BEGIN PSEUDO-SIGNED CONTENT-----\n" + content +
54
 
                "-----END PSEUDO-SIGNED CONTENT-----\n")
 
47
        return content
55
48
 
56
49
 
57
50
def _set_gpg_tty():
69
62
 
70
63
class GPGStrategy(object):
71
64
    """GPG Signing and checking facilities."""
72
 
 
 
65
        
73
66
    def _command_line(self):
74
67
        return [self._config.gpg_signing_command(), '--clearsign']
75
68
 
77
70
        self._config = config
78
71
 
79
72
    def sign(self, content):
80
 
        if isinstance(content, unicode):
81
 
            raise errors.BzrBadParameterUnicode('content')
82
 
        ui.ui_factory.clear_term()
83
 
 
84
 
        preexec_fn = _set_gpg_tty
85
 
        if sys.platform == 'win32':
86
 
            # Win32 doesn't support preexec_fn, but wouldn't support TTY anyway.
87
 
            preexec_fn = None
88
73
        try:
89
74
            process = subprocess.Popen(self._command_line(),
90
75
                                       stdin=subprocess.PIPE,
91
76
                                       stdout=subprocess.PIPE,
92
 
                                       preexec_fn=preexec_fn)
 
77
                                       preexec_fn=_set_gpg_tty)
93
78
            try:
94
79
                result = process.communicate(content)[0]
95
80
                if process.returncode is None: