~openerp-commiter/openobject-addons/extra-6.0

« back to all changes in this revision

Viewing changes to document_webdav_old/webdav/DAV/BufferingHTTPServer.py

  • Committer: Fabien Pinckaers
  • Date: 2008-12-12 09:09:57 UTC
  • Revision ID: fp@tinyerp.com-20081212090957-cson0n0jove7dt7i
document_webdav

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python
 
2
 
 
3
"""
 
4
    Buffering HTTP Server
 
5
    Copyright (C) 1999 Christian Scholz (ruebe@aachen.heimat.de)
 
6
 
 
7
    This library is free software; you can redistribute it and/or
 
8
    modify it under the terms of the GNU Library General Public
 
9
    License as published by the Free Software Foundation; either
 
10
    version 2 of the License, or (at your option) any later version.
 
11
 
 
12
    This library is distributed in the hope that it will be useful,
 
13
    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
15
    Library General Public License for more details.
 
16
 
 
17
    You should have received a copy of the GNU Library General Public
 
18
    License along with this library; if not, write to the Free
 
19
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
20
 
 
21
"""
 
22
 
 
23
 
 
24
from utils import VERSION, AUTHOR
 
25
__version__ = VERSION
 
26
__author__  = AUTHOR
 
27
 
 
28
from BaseHTTPServer import BaseHTTPRequestHandler
 
29
import os
 
30
class BufferedHTTPRequestHandler(BaseHTTPRequestHandler):
 
31
    """
 
32
    Buffering HTTP Request Handler
 
33
 
 
34
    This class is an extension to the BaseHTTPRequestHandler
 
35
    class which buffers the whole output and sends it at once
 
36
    after the processing if the request is finished.
 
37
 
 
38
    This makes it possible to work together with some clients
 
39
    which otherwise would break (e.g. cadaver)
 
40
 
 
41
    """
 
42
 
 
43
 
 
44
    def _init_buffer(self):
 
45
        """initialize the buffer.
 
46
 
 
47
        If you override the handle() method remember to call
 
48
        this (see below)
 
49
        """
 
50
        self.__buffer=""
 
51
        self.__outfp=os.tmpfile()
 
52
 
 
53
    def _append(self,s):
 
54
        """ append a string to the buffer """
 
55
        self.__buffer=self.__buffer+s
 
56
 
 
57
    def _flush(self):
 
58
        """ flush the buffer to wfile """
 
59
        self.wfile.write(self.__buffer)
 
60
        self.__outfp.write(self.__buffer)
 
61
        self.__outfp.flush()
 
62
        self.wfile.flush()
 
63
        self.__buffer=""
 
64
 
 
65
    def handle(self):
 
66
        """ Handle a HTTP request """
 
67
        self._init_buffer()
 
68
        BaseHTTPRequestHandler.handle(self)
 
69
        self._flush()
 
70
 
 
71
    def send_header(self, keyword, value):
 
72
        """Send a MIME header."""
 
73
        if self.request_version != 'HTTP/0.9':
 
74
            self._append("%s: %s\r\n" % (keyword, value))
 
75
 
 
76
    def end_headers(self):
 
77
        """Send the blank line ending the MIME headers."""
 
78
        if self.request_version != 'HTTP/0.9':
 
79
            self._append("\r\n")
 
80
 
 
81
    def send_response(self, code, message=None):
 
82
        self.log_request(code)
 
83
 
 
84
        if message is None:
 
85
            if self.responses.has_key(code):
 
86
                message = self.responses[code][0]
 
87
            else:
 
88
                message = ''
 
89
 
 
90
        if self.request_version != 'HTTP/0.9':
 
91
            self._append("%s %s %s\r\n" %
 
92
                    (self.protocol_version, str(code), message))
 
93
 
 
94
        self.send_header('Server', self.version_string())
 
95
        self.send_header('Connection', 'close')
 
96
        self.send_header('Date', self.date_time_string())
 
97
 
 
98
    protocol_version="HTTP/1.1"
 
99