~ubuntu-branches/ubuntu/natty/moin/natty-updates

« back to all changes in this revision

Viewing changes to MoinMoin/request/request_cli.py

  • Committer: Bazaar Package Importer
  • Author(s): Jonas Smedegaard
  • Date: 2008-06-22 21:17:13 UTC
  • mto: This revision was merged to the branch mainline in revision 18.
  • Revision ID: james.westby@ubuntu.com-20080622211713-inlv5k4eifxckelr
ImportĀ upstreamĀ versionĀ 1.7.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- coding: iso-8859-1 -*-
 
2
"""
 
3
    MoinMoin - CLI Request Implementation for commandline usage.
 
4
 
 
5
    @copyright: 2001-2003 Juergen Hermann <jh@web.de>,
 
6
                2003-2006 MoinMoin:ThomasWaldmann
 
7
    @license: GNU GPL, see COPYING for details.
 
8
"""
 
9
import sys
 
10
 
 
11
from MoinMoin import log
 
12
logging = log.getLogger(__name__)
 
13
 
 
14
from MoinMoin.request import RequestBase, RemoteClosedConnection
 
15
 
 
16
class Request(RequestBase):
 
17
    """ specialized on command line interface and script requests """
 
18
 
 
19
    def __init__(self, url='CLI', pagename='', properties={}):
 
20
        self.saved_cookie = ''
 
21
        self.path_info = '/' + pagename
 
22
        self.query_string = ''
 
23
        self.remote_addr = '127.0.0.1'
 
24
        self.is_ssl = 0
 
25
        self.http_user_agent = 'CLI/Script'
 
26
        self.url = url
 
27
        self.request_method = 'GET'
 
28
        self.request_uri = '/' + pagename # TODO check if /pagename works as URI for CLI usage
 
29
        self.http_host = 'localhost'
 
30
        self.http_referer = ''
 
31
        self.script_name = '.'
 
32
        self.content_length = None
 
33
        self.if_modified_since = None
 
34
        self.if_none_match = None
 
35
        RequestBase.__init__(self, properties)
 
36
        self.cfg.caching_formats = [] # don't spoil the cache
 
37
        self.initTheme() # usually request.run() does this, but we don't use it
 
38
 
 
39
    def _setup_args_from_cgi_form(self):
 
40
        """ Override to create cli form """
 
41
        #form = cgi.FieldStorage()
 
42
        #return RequestBase._setup_args_from_cgi_form(self, form)
 
43
        return {}
 
44
 
 
45
    def read(self, n):
 
46
        """ Read from input stream. """
 
47
        if n is None:
 
48
            logging.warning("calling request.read(None) might block")
 
49
            return sys.stdin.read()
 
50
        else:
 
51
            return sys.stdin.read(n)
 
52
 
 
53
    def write(self, *data):
 
54
        """ Write to output stream. """
 
55
        data = self.encode(data)
 
56
        try:
 
57
            sys.stdout.write(data)
 
58
        except IOError:
 
59
            raise RemoteClosedConnection()
 
60
 
 
61
    def flush(self):
 
62
        sys.stdout.flush()
 
63
 
 
64
    def finish(self):
 
65
        RequestBase.finish(self)
 
66
        # flush the output, ignore errors caused by the user closing the socket
 
67
        try:
 
68
            sys.stdout.flush()
 
69
        except IOError, ex:
 
70
            import errno
 
71
            if ex.errno != errno.EPIPE:
 
72
                raise
 
73
 
 
74
    def isForbidden(self):
 
75
        """ Nothing is forbidden """
 
76
        return 0
 
77
 
 
78
    # Accessors --------------------------------------------------------
 
79
 
 
80
    def getQualifiedURL(self, uri=None):
 
81
        """ Return a full URL starting with schema and host
 
82
 
 
83
        TODO: does this create correct pages when you render wiki pages
 
84
              within a cli request?!
 
85
        """
 
86
        return uri
 
87
 
 
88
    # Headers ----------------------------------------------------------
 
89
 
 
90
    def setHttpHeader(self, header):
 
91
        pass
 
92
 
 
93
    def _emit_http_headers(self, headers):
 
94
        """ private method to send out preprocessed list of HTTP headers """
 
95
        pass
 
96
 
 
97
    def http_redirect(self, url):
 
98
        """ Redirect to a fully qualified, or server-rooted URL
 
99
 
 
100
        TODO: Does this work for rendering redirect pages?
 
101
        """
 
102
        raise Exception("Redirect not supported for command line tools!")
 
103
 
 
104