/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/http_server.py

  • Committer: Robert Collins
  • Date: 2009-03-13 02:25:46 UTC
  • mfrom: (4133 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4183.
  • Revision ID: robertc@robertcollins.net-20090313022546-e7de5zsdkbay5okf
MergeĀ .dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
34
34
from bzrlib.transport import local
35
35
 
36
36
 
37
 
class WebserverNotAvailable(Exception):
38
 
    pass
39
 
 
40
 
 
41
37
class BadWebserverPath(ValueError):
42
38
    def __str__(self):
43
39
        return 'path %s is not in %s' % self.args
141
137
            # common)
142
138
            self.send_response(301)
143
139
            self.send_header("Location", self.path + "/")
144
 
            # Indicates that the body is empty for HTTP/1.1 clients 
 
140
            # Indicates that the body is empty for HTTP/1.1 clients
145
141
            self.send_header('Content-Length', '0')
146
142
            self.end_headers()
147
143
            return None
181
177
            content_length += self._header_line_length(
182
178
                'Content-Range', 'bytes %d-%d/%d' % (start, end, file_size))
183
179
            content_length += len('\r\n') # end headers
184
 
            content_length += end - start # + 1
 
180
            content_length += end - start + 1
185
181
        content_length += len(boundary_line)
186
182
        self.send_header('Content-length', content_length)
187
183
        self.end_headers()
324
320
 
325
321
    def tearDown(self):
326
322
         """Called to clean-up the server.
327
 
 
 
323
 
328
324
         Since the server may be (surely is, even) in a blocking listen, we
329
325
         shutdown its socket before closing it.
330
326
         """
347
343
             # WSAENOTCONN (10057) 'Socket is not connected' is harmless on
348
344
             # windows (occurs before the first connection attempt
349
345
             # vila--20071230)
350
 
             if not len(e.args) or e.args[0] != 10057:
 
346
 
 
347
             # 'Socket is not connected' can also occur on OSX, with a
 
348
             # "regular" ENOTCONN (when something went wrong during test case
 
349
             # setup leading to self.setUp() *not* being called but
 
350
             # self.tearDown() still being called -- vila20081106
 
351
             if not len(e.args) or e.args[0] not in (errno.ENOTCONN, 10057):
351
352
                 raise
352
353
         # Let the server properly close the socket
353
354
         self.server_close()
419
420
        # Allows tests to verify number of GET requests issued
420
421
        self.GET_request_nb = 0
421
422
 
 
423
    def create_httpd(self, serv_cls, rhandler_cls):
 
424
        return serv_cls((self.host, self.port), self.request_handler, self)
 
425
 
422
426
    def __repr__(self):
423
427
        return "%s(%s:%s)" % \
424
428
            (self.__class__.__name__, self.host, self.port)
440
444
            if serv_cls is None:
441
445
                raise httplib.UnknownProtocol(proto_vers)
442
446
            else:
443
 
                self._httpd = serv_cls((self.host, self.port), rhandler, self)
 
447
                self._httpd = self.create_httpd(serv_cls, rhandler)
444
448
            host, self.port = self._httpd.socket.getsockname()
445
449
        return self._httpd
446
450
 
499
503
 
500
504
    def setUp(self, backing_transport_server=None):
501
505
        """See bzrlib.transport.Server.setUp.
502
 
        
 
506
 
503
507
        :param backing_transport_server: The transport that requests over this
504
508
            protocol should be forwarded to. Note that this is currently not
505
509
            supported for HTTP.