~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/shellcomplete.py

  • Committer: v.ladeuil+lp at free
  • Date: 2006-12-01 15:06:29 UTC
  • mto: (2172.3.1 bzr.73948)
  • mto: This revision was merged to the branch mainline in revision 2181.
  • Revision ID: v.ladeuil+lp@free.fr-20061201150629-zjd2an87u0r7nhhw
The tests that would have help avoid bug #73948 and all that mess :)

* bzrlib/transport/http/response.py:
(handle_response): Translate a 416 http error code into a bzr
exception.

* bzrlib/transport/http/_urllib2_wrappers.py:
(HTTPDefaultErrorHandler.http_error_default): Translate a 416 http
error code into a bzr exception.

* bzrlib/transport/http/_pycurl.py:
(PyCurlTransport._curl_perform): It could happen that pycrul
itself detect a short read.

* bzrlib/transport/http/__init__.py:
(HttpTransportBase._retry_get): New method, factorizing the retry
logic.
(HttpTransportBase.readv): We can have exception during the
initial GET worth degrading the range requirements (i.e. retrying
the GET request with either single or not ranges).

* bzrlib/tests/test_transport_implementations.py:
(TransportTests.test_readv_short_read): InvalidRange can also be
raised.

* bzrlib/tests/test_http.py:
(TestRangeRequestServer.test_readv_invalid_ranges): Was named
test_readv_short_read, the new name make the intent
clearer. Depending of the code path used (urllib or pycurl), both
exceptions can be raised.

* bzrlib/tests/HttpServer.py:
(TestingHTTPRequestHandler.do_GET): If invalid ranges are
specified, returns a 416 instead of the whole file (both are valid
according to the RFC).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2006, 2007, 2009, 2010 Canonical Ltd
 
1
# Copyright (C) 2005, 2006 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
12
12
#
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
17
17
import sys
18
18
 
25
25
    else:
26
26
        shellcomplete_on_command(context, outfile = outfile)
27
27
 
28
 
 
29
 
def shellcomplete_on_command(cmdname, outfile=None):
 
28
def shellcomplete_on_command(cmdname, outfile = None):
30
29
    cmdname = str(cmdname)
31
30
 
32
31
    if outfile is None:
40
39
    if doc is None:
41
40
        raise NotImplementedError("sorry, no detailed shellcomplete yet for %r" % cmdname)
42
41
 
43
 
    shellcomplete_on_options(cmdobj.options().values(), outfile=outfile)
 
42
    shellcomplete_on_option(cmdobj.takes_options, outfile = None)
44
43
    for aname in cmdobj.takes_args:
45
44
        outfile.write(aname + '\n')
46
45
 
47
46
 
48
 
def shellcomplete_on_options(options, outfile=None):
49
 
    for opt in options:
50
 
        short_name = opt.short_name()
51
 
        if short_name:
52
 
            outfile.write('"(--%s -%s)"{--%s,-%s}\n'
53
 
                    % (opt.name, short_name, opt.name, short_name))
54
 
        else:
55
 
            outfile.write('--%s\n' % opt.name)
 
47
def shellcomplete_on_option(options, outfile=None):
 
48
    from bzrlib.option import Option
 
49
    if not options:
 
50
        return
 
51
    if outfile is None:
 
52
        outfile = sys.stdout
 
53
    for on in options:
 
54
        for shortname, longname in Option.SHORT_OPTIONS.items():
 
55
            if longname == on:
 
56
                l = '"(--' + on + ' -' + shortname + ')"{--' + on + ',-' + shortname + '}'
 
57
                break
 
58
            else:
 
59
                l = '--' + on
 
60
        outfile.write(l + '\n')
56
61
 
57
62
 
58
63
def shellcomplete_commands(outfile = None):
60
65
    import inspect
61
66
    import commands
62
67
    from inspect import getdoc
63
 
 
64
 
    commands.install_bzr_command_hooks()
65
 
 
 
68
    
66
69
    if outfile is None:
67
70
        outfile = sys.stdout
68
 
 
 
71
    
69
72
    cmds = []
70
 
    for cmdname in commands.all_command_names():
71
 
        cmd = commands.get_cmd_object(cmdname)
72
 
        cmds.append((cmdname, cmd))
73
 
        for alias in cmd.aliases:
74
 
            cmds.append((alias, cmd))
 
73
    for cmdname, cmdclass in commands.get_all_cmds():
 
74
        cmds.append((cmdname, cmdclass))
 
75
        for alias in cmdclass.aliases:
 
76
            cmds.append((alias, cmdclass))
75
77
    cmds.sort()
76
 
    for cmdname, cmd in cmds:
77
 
        if cmd.hidden:
 
78
    for cmdname, cmdclass in cmds:
 
79
        if cmdclass.hidden:
78
80
            continue
79
 
        doc = getdoc(cmd)
 
81
        doc = getdoc(cmdclass)
80
82
        if doc is None:
81
83
            outfile.write(cmdname + '\n')
82
84
        else: