1
2
3
4
5
6
7
8
9
10
11 """
12 This is the debug renderer. This is very useful for debugging plugins
13 and templates.
14 """
15
16 __revision__ = "$Id: debug.py 1043 2007-06-20 16:23:30Z willhelm $"
17
18 from Pyblosxom.renderers.base import RendererBase
19 from Pyblosxom import tools
20
22 """
23 Takes in a value. If it's not a string, we repr it and turn it into
24 a string. Then we escape it so it can be printed in HTML safely.
25
26 @param s: any value
27 @type s: varies
28
29 @returns: a safe-to-print-in-html string representation of the value
30 @rtype: string
31 """
32 if not s:
33 return ""
34
35 if not isinstance(s, str):
36 s = repr(s)
37
38 return s.replace("&", "&").replace(">", ">").replace("<", "<")
39
41 """
42 Takes a map of keys to values and applies the function f to a pretty
43 printed version of each key/value pair.
44
45 @param printfunc: function for printing
46 @type printfunc: function
47
48 @param keymap: a mapping of key/value pairs
49 @type keymap: map
50 """
51 keys = keymap.keys()
52 keys.sort()
53 for key in keys:
54 printfunc("<font color=\"#0000ff\">%s</font> -> %s\n" % \
55 (escv(key), escv(keymap[key])))
56
58 """
59 This is the debug renderer. This is very useful for debugging plugins
60 and templates.
61 """
63 """
64 Renders a PyBlosxom request after we've gone through all the
65 motions of converting data and getting entries to render.
66
67 @param header: either prints (1) or does not print (0) the http
68 headers.
69 @type header: boolean
70 """
71 pyhttp = self._request.getHttp()
72 config = self._request.getConfiguration()
73 data = self._request.getData()
74 printout = self.write
75
76 hbar = "------------------------------------------------------\n"
77
78
79 if header:
80 self.addHeader('Content-type', 'text/html')
81 self.showHeaders()
82
83 printout("<html>")
84 printout("<body>")
85 printout("<pre>")
86 printout("Welcome to debug mode!\n")
87 printout("You requested the %(flavour)s flavour.\n" % data)
88
89 printout(hbar)
90 printout("The HTTP Return codes are:\n")
91 printout(hbar)
92 for k, v in self._header:
93 printout("<font color=\"#0000ff\">%s</font> -> %s\n" % \
94 (escv(k), escv(v)))
95
96 printout(hbar)
97 printout("The OS environment contains:\n")
98 printout(hbar)
99 import os
100 print_map(printout, os.environ)
101
102 printout(hbar)
103 printout("Request.getHttp() dict contains:\n")
104 printout(hbar)
105 print_map(printout, pyhttp)
106
107 printout(hbar)
108 printout("Request.getConfiguration() dict contains:\n")
109 printout(hbar)
110 print_map(printout, config)
111
112 printout(hbar)
113 printout("Request.getData() dict contains:\n")
114 printout(hbar)
115 print_map(printout, data)
116
117 printout(hbar)
118 printout("Entries to process:\n")
119 printout(hbar)
120 for content in self._content:
121 if not isinstance(content, str):
122 printout("%s\n" %
123 escv(content.get('filename', 'No such file\n')))
124
125 printout(hbar)
126 printout("Entries processed:\n")
127 printout(hbar)
128 for content in self._content:
129 if not isinstance(content, str):
130 printout(hbar)
131 emsg = escv(content.get('filename', 'No such file\n'))
132 printout("Items for %s:\n" % emsg)
133 printout(hbar)
134 print_map(printout, content)
135
136 printout(hbar)
137 if not config.has_key("cacheDriver"):
138 printout("No cache driver configured.")
139 else:
140 printout("Cached Titles:\n")
141 printout(hbar)
142 cache = tools.get_cache(self._request)
143 for content in self._content:
144 if not isinstance(content, str):
145 filename = content['filename']
146
147 if cache.has_key(filename):
148 printout("%s\n" % escv(cache[filename]['title']))
149 cache.close()
150
151 printout(hbar)
152 printout("Cached Entry Bodies:\n")
153 printout(hbar)
154 for content in self._content:
155 if not isinstance(content, str):
156 filename = content['filename']
157 if cache.has_key(filename):
158 printout("%s\n" % escv(cache[filename]['title']))
159 printout(hbar.replace("-", "="))
160 printout("%s\n" % escv(cache[filename]['body']))
161 else:
162 printout("Contents of %s is not cached\n" % \
163 escv(filename))
164 cache.close()
165 printout(hbar)
166
167 printout("</body>")
168 printout("</html>")
169