1
# vim: shiftwidth=4 tabstop=4 expandtab
8
- Pyblosxom Core handles the Input and Process of the system and passes
9
the result of the process to the Renderers for output. All renderers
10
are child classes of RendererBase. RenderBase will contain the public
11
interfaces for all Renderer onject.
14
def __init__(self, request, stdoutput = sys.stdout):
16
Constructor: Initializes the Renderer
18
@param request: The L{libs.Request.Request} object
19
@type request: L{libs.Request.Request} object
20
@param out: File like object to print to.
23
self._request = request
27
self._needs_content_type = 1
31
def write(self, data):
33
Convenience method for programs to use instead of accessing
36
Other classes can override this if there is a unique way to
37
write out data, for example, a two stream output, e.g. one
38
output stream and one output log stream.
40
Another use for this could be a plugin that writes out binary
41
files, but because renderers and other frameworks may probably
42
not want you to write to C{stdout} directly, this method assists
43
you nicely. For example::
47
renderer = req['renderer']
49
if reqIsGif and gifFileExists(theGifFile):
51
data = file(theGifFile).read()
54
renderer.addHeader('Content-type', 'image/gif')
55
renderer.addHeader('Content-Length', len(data))
61
# Tell pyblosxom not to render anymore as data is
65
This simple piece of pseudocode explains what you could do with
66
this method, though I highly don't recommend this, unless
67
pyblosxom is running continuously.
69
@param data: Piece of string you want printed
75
def addHeader(self, *args):
77
Populates the HTTP header with lines of text
79
@param args: Paired list of headers
80
@type args: argument lists
81
@raises ValueError: This happens when the parameters are not correct
86
key = args.pop(0).strip()
87
if key.find(' ') != -1 or key.find(':') != -1:
88
raise ValueError, 'There should be no spaces in header keys'
89
value = args.pop(0).strip()
90
self._header.update({key: value})
92
raise ValueError, 'Headers recieved are not in the correct form'
95
def setContent(self, content):
99
@param content: What content are we to show?
100
@type content: C{list} List of entries to process or C{dict} Simple
101
dict containing at least 'title' and 'body'
103
self._content = content
106
def needsContentType(self, flag):
108
Use the renderer to determine 'Content-Type: x/x' default is to use the
109
renderer for Content-Type, set flag to None to indicate no Content-Type
112
@param flag: True of false value
114
self._needs_content_type = flag
117
def showHeaders(self):
119
Show HTTP Headers. Override this if your renderer uses headers in a
122
self.write('\n'.join(['%s: %s' % (x, self._header[x])
123
for x in self._header]))
127
def render(self, header = 1):
131
@param header: Do we want to show headers?
132
@type header: boolean
138
self.addHeader('Content-Type', 'text/plain')
142
self.write(self._content)
145
class Renderer(RendererBase):