~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/atomicfile.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, 2008, 2009, 2010 Canonical Ltd
 
1
# Copyright (C) 2004, 2005 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
 
18
18
import os
 
19
import sys
19
20
 
20
21
from bzrlib.lazy_import import lazy_import
21
22
lazy_import(globals(), """
50
51
        global _hostname
51
52
 
52
53
        self._fd = None
 
54
        assert mode in ('wb', 'wt'), \
 
55
            "invalid AtomicFile mode %r" % mode
53
56
 
54
57
        if _hostname is None:
55
 
            _hostname = osutils.get_host_name()
 
58
            _hostname = socket.gethostname()
56
59
 
57
 
        self.tmpfilename = '%s.%d.%s.%s.tmp' % (filename, _pid, _hostname,
58
 
                                                osutils.rand_chars(10))
 
60
        self.tmpfilename = '%s.%d.%s.tmp' % (filename, _pid, _hostname)
59
61
 
60
62
        self.realfilename = filename
61
 
 
62
 
        flags = os.O_EXCL | os.O_CREAT | os.O_WRONLY | osutils.O_NOINHERIT
 
63
        
 
64
        flags = os.O_EXCL | os.O_CREAT | os.O_WRONLY
63
65
        if mode == 'wb':
64
66
            flags |= osutils.O_BINARY
65
 
        elif mode != 'wt':
66
 
            raise ValueError("invalid AtomicFile mode %r" % mode)
67
67
 
68
68
        if new_mode is not None:
69
69
            local_mode = new_mode
70
70
        else:
71
71
            local_mode = 0666
72
 
 
 
72
        
73
73
        # Use a low level fd operation to avoid chmodding later.
74
74
        # This may not succeed, but it should help most of the time
75
75
        self._fd = os.open(self.tmpfilename, flags, local_mode)