@@ -12,60 +12,61 @@ def writeContent(self):
1212 wr = self .writeln
1313 action = self .request ().field ("action" , None )
1414
15- if action is None :
16- wr ('''<form action="AppControl" method="post">
15+ match action :
16+ case None :
17+ wr ('''<form action="AppControl" method="post">
1718<table>
1819<tr><td><input type="submit" name="action" value="Clear cache"></td>
1920<td>Clear the class and instance caches of each servlet factory.</td>
2021</tr><tr>
2122<td><input type="submit" name="action" value="Reload"></td>
2223<td>Reload the selected Python modules. Be careful!</td></tr>''' )
23- wr ('<tr><td></td><td>' )
24- for n in sorted (sys .modules ):
25- m = sys .modules [n ]
26- if (not n .endswith ('__init__' ) and not hasattr (m , '__path__' )
27- and not hasattr (m , '__orig_file__' )):
28- # show only the easily reloadable modules
29- wr (f'<input type="checkbox" name="reloads" value="{ n } ">'
30- f' { n } <br>' )
31- wr ('</td></tr>\n </table>\n </form>' )
24+ wr ('<tr><td></td><td>' )
25+ for n in sorted (sys .modules ):
26+ m = sys .modules [n ]
27+ if (not n .endswith ('__init__' ) and not hasattr (m , '__path__' )
28+ and not hasattr (m , '__orig_file__' )):
29+ # show only the easily reloadable modules
30+ wr (f'<input type="checkbox" name="reloads" value="{ n } ">'
31+ f' { n } <br>' )
32+ wr ('</td></tr>\n </table>\n </form>' )
3233
33- elif action == "Clear cache" :
34- from URLParser import ServletFactoryManager
35- factories = [f for f in ServletFactoryManager ._factories
36- if f ._classCache ]
37- wr ('<p>' )
38- for factory in factories :
39- wr (f'Flushing cache of { factory .name ()} ...<br>' )
40- factory .flushCache ()
41- wr ('</p>' )
42- wr ('<p style="color:green">The caches of all factories'
43- ' have been flushed.</p>' )
44- wr ('<p>Click here to view the Servlet cache:'
45- ' <a href="ServletCache">Servlet Cache</a></p>' )
34+ case "Clear cache" :
35+ from URLParser import ServletFactoryManager
36+ factories = [f for f in ServletFactoryManager ._factories
37+ if f ._classCache ]
38+ wr ('<p>' )
39+ for factory in factories :
40+ wr (f'Flushing cache of { factory .name ()} ...<br>' )
41+ factory .flushCache ()
42+ wr ('</p>' )
43+ wr ('<p style="color:green">The caches of all factories'
44+ ' have been flushed.</p>' )
45+ wr ('<p>Click here to view the Servlet cache:'
46+ ' <a href="ServletCache">Servlet Cache</a></p>' )
4647
47- elif action == "Reload" :
48- wr ('<p>Reloading selected modules. Any existing classes'
49- ' will continue to use the old module definitions,'
50- ' as will any functions/variables imported using "from".'
51- ' Use "Clear Cache" to clean out any servlets'
52- ' in this condition.<p>' )
53- reloadNames = req .field ("reloads" , None )
54- if not isinstance (reloadNames , list ):
55- reloadNames = [reloadNames ]
56- wr ('<p>' )
57- for n in reloadNames :
58- m = sys .modules .get (n )
59- if m :
60- wr (f"Reloading { self .htmlEncode (str (m ))} ...<br>" )
61- try :
62- reload (m )
63- except Exception as e :
64- wr ('<span style="color:red">Could not reload, '
65- f'error was "{ e } ".</span><br>' )
66- wr ('</p>' )
67- wr ('<p style="color:green">The selected modules'
68- ' have been reloaded.</p>' )
48+ case "Reload" :
49+ wr ('<p>Reloading selected modules. Any existing classes'
50+ ' will continue to use the old module definitions,'
51+ ' as will any functions/variables imported using "from".'
52+ ' Use "Clear Cache" to clean out any servlets'
53+ ' in this condition.<p>' )
54+ reloadNames = req .field ("reloads" , None )
55+ if not isinstance (reloadNames , list ):
56+ reloadNames = [reloadNames ]
57+ wr ('<p>' )
58+ for n in reloadNames :
59+ m = sys .modules .get (n )
60+ if m :
61+ wr (f"Reloading { self .htmlEncode (str (m ))} ...<br>" )
62+ try :
63+ reload (m )
64+ except Exception as e :
65+ wr ('<span style="color:red">Could not reload, '
66+ f'error was "{ e } ".</span><br>' )
67+ wr ('</p>' )
68+ wr ('<p style="color:green">The selected modules'
69+ ' have been reloaded.</p>' )
6970
70- else :
71- wr (f'<p>Cannot perform "{ action } ".</p>' )
71+ case _ :
72+ wr (f'<p>Cannot perform "{ action } ".</p>' )
0 commit comments