Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d1c1ec8

Browse files
committed
- Suppress the visible text in the epilogue when "edit=no" is specified.
- Add translation of *foobar* into <I>foobar</I> (but not inside <PRE>). - Optimization for the translation: only translate when @ or / or * seen. - Add some layout to front page lay-out.
1 parent 4888c7e commit d1c1ec8

1 file changed

Lines changed: 38 additions & 9 deletions

File tree

Tools/faqwiz/faqmain.py

Lines changed: 38 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
NAMEPAT = "faq??.???.htp"
2828
NAMEREG = "^faq\([0-9][0-9]\)\.\([0-9][0-9][0-9]\)\.htp$"
2929

30+
# Like so many other things, this should come from a file.
3031
SECTIONS = {
3132
"1": "General information and availability",
3233
"2": "Python in the real world",
@@ -85,14 +86,18 @@ def do_frontpage(self):
8586
<LI><A HREF="faq.py?req=delete">Delete a FAQ entry</A>
8687
</UL>
8788
89+
<HR>
90+
8891
<H2>Search the FAQ</H2>
8992
9093
<FORM ACTION="faq.py?req=query">
9194
<INPUT TYPE=text NAME=query>
92-
<INPUT TYPE=submit VALUE="Search">
95+
<INPUT TYPE=submit VALUE="Search"><BR>
96+
(Case insensitive regular expressions.)
9397
<INPUT TYPE=hidden NAME=req VALUE=query>
9498
</FORM>
95-
99+
<HR>
100+
<P>
96101
Disclaimer: these pages are intended to be edited by anyone.
97102
Please exercise discretion when editing, don't be rude, etc.
98103
"""
@@ -605,7 +610,11 @@ def show(self, name, title, text, edit=1):
605610
if not pre:
606611
print '<PRE>'
607612
pre = 1
608-
print self.translate(line)
613+
if '/' in line or '@' in line:
614+
line = self.translate(line)
615+
if not pre and '*' in line:
616+
line = self.emphasize(line)
617+
print line
609618
if pre:
610619
print '</PRE>'
611620
pre = 0
@@ -663,12 +672,18 @@ def error(self, *messages):
663672
print
664673

665674
def epilogue(self):
675+
if self.edit == 'no':
676+
global wanttime
677+
wanttime = 0
678+
else:
679+
print '''
680+
<P>
681+
<HR>
682+
<A HREF="http://www.python.org">Python home</A> /
683+
<A HREF="faq.py">FAQ home</A> /
684+
Feedback to <A HREF="mailto:[email protected]">GvR</A>
685+
'''
666686
print '''
667-
<P>
668-
<HR>
669-
<A HREF="http://www.python.org">Python home</A> /
670-
<A HREF="faq.py">FAQ home</A> /
671-
Feedback to <A HREF="mailto:[email protected]">GvR</A>
672687
</BODY>
673688
</HTML>
674689
'''
@@ -705,8 +720,21 @@ def translate(self, text):
705720
list.append(cgi.escape(text[i:j]))
706721
return string.join(list, '')
707722

723+
emphasize_prog = None
724+
725+
def emphasize(self, line):
726+
import regsub
727+
if not self.emphasize_prog:
728+
import regex
729+
pat = "\*\([a-zA-Z]+\)\*"
730+
self.emphasize_prog = prog = regex.compile(pat)
731+
else:
732+
prog = self.emphasize_prog
733+
return regsub.gsub(prog, "<I>\\1</I>", line)
734+
708735
print "Content-type: text/html"
709736
dt = 0
737+
wanttime = 1
710738
try:
711739
import time
712740
t1 = time.time()
@@ -718,7 +746,8 @@ def translate(self, text):
718746
except:
719747
print "\n<HR>Sorry, an error occurred"
720748
cgi.print_exception()
721-
print "<P>(running time = %s seconds)" % str(round(dt, 3))
749+
if wanttime:
750+
print "<BR>(running time = %s seconds)" % str(round(dt, 3))
722751

723752
# The following bootstrap script must be placed in cgi-bin/faq.py:
724753
BOOTSTRAP = """

0 commit comments

Comments
 (0)