Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
3c3354c0
Commit
3c3354c0
authored
May 21, 1997
by
Guido van Rossum
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Crude but functional, except for adding new entries.
parent
d6a111e2
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
172 additions
and
46 deletions
+172
-46
Tools/faqwiz/faqmain.py
Tools/faqwiz/faqmain.py
+172
-46
No files found.
Tools/faqwiz/faqmain.py
View file @
3c3354c0
...
@@ -21,14 +21,16 @@ class FAQServer:
...
@@ -21,14 +21,16 @@ class FAQServer:
else
:
else
:
method
()
method
()
KEYS
=
[
'req'
,
'query'
,
'name'
,
'text'
,
'commit'
,
'title'
]
KEYS
=
[
'req'
,
'query'
,
'name'
,
'text'
,
'commit'
,
'title'
,
'author'
,
'email'
,
'log'
]
def
__getattr__
(
self
,
key
):
def
__getattr__
(
self
,
key
):
if
key
not
in
self
.
KEYS
:
if
key
not
in
self
.
KEYS
:
raise
AttributeError
raise
AttributeError
if
self
.
form
.
has_key
(
key
)
:
try
:
item
=
self
.
form
[
key
]
item
=
self
.
form
[
key
]
return
item
.
value
return
item
.
value
except
KeyError
:
return
''
return
''
def
do_frontpage
(
self
):
def
do_frontpage
(
self
):
...
@@ -38,8 +40,8 @@ class FAQServer:
...
@@ -38,8 +40,8 @@ class FAQServer:
<UL>
<UL>
<LI><A HREF="faq.py?req=search">Search the FAQ</A>
<LI><A HREF="faq.py?req=search">Search the FAQ</A>
<LI><A HREF="faq.py?req=browse">Browse the FAQ</A>
<LI><A HREF="faq.py?req=browse">Browse the FAQ</A>
<LI><A HREF="faq.py?req=submit">Submit a new FAQ entry</A>
<LI><A HREF="faq.py?req=submit">Submit a new FAQ entry</A>
(not yet)
<LI><A HREF="faq.py?req=roulette">
Random FAQ entry
</A>
<LI><A HREF="faq.py?req=roulette">
FAQ roulette
</A>
</UL>
</UL>
<FORM ACTION="faq.py?req=query">
<FORM ACTION="faq.py?req=query">
...
@@ -62,9 +64,9 @@ class FAQServer:
...
@@ -62,9 +64,9 @@ class FAQServer:
names
.
sort
()
names
.
sort
()
n
=
0
n
=
0
for
name
in
names
:
for
name
in
names
:
headers
,
body
=
self
.
read
(
name
)
headers
,
text
=
self
.
read
(
name
)
if
headers
:
if
headers
:
self
.
show
(
name
,
headers
,
body
,
1
)
self
.
show
(
name
,
headers
[
'title'
],
text
,
1
)
n
=
n
+
1
n
=
n
+
1
if
not
n
:
if
not
n
:
print
"No FAQ entries?!?!"
print
"No FAQ entries?!?!"
...
@@ -82,9 +84,9 @@ class FAQServer:
...
@@ -82,9 +84,9 @@ class FAQServer:
names
=
os
.
listdir
(
os
.
curdir
)
names
=
os
.
listdir
(
os
.
curdir
)
while
names
:
while
names
:
name
=
whrandom
.
choice
(
names
)
name
=
whrandom
.
choice
(
names
)
headers
,
body
=
self
.
read
(
name
)
headers
,
text
=
self
.
read
(
name
)
if
headers
:
if
headers
:
self
.
show
(
name
,
headers
,
body
,
1
)
self
.
show
(
name
,
headers
[
'title'
],
text
,
1
)
print
'<P><A HREF="faq.py?req=roulette">Show another one</A>'
print
'<P><A HREF="faq.py?req=roulette">Show another one</A>'
break
break
else
:
else
:
...
@@ -118,18 +120,18 @@ class FAQServer:
...
@@ -118,18 +120,18 @@ class FAQServer:
print
"<HR>"
print
"<HR>"
n
=
0
n
=
0
for
name
in
names
:
for
name
in
names
:
headers
,
body
=
self
.
read
(
name
)
headers
,
text
=
self
.
read
(
name
)
if
headers
:
if
headers
:
title
=
headers
[
'title'
]
title
=
headers
[
'title'
]
if
p
.
search
(
title
)
>=
0
or
p
.
search
(
body
)
>=
0
:
if
p
.
search
(
title
)
>=
0
or
p
.
search
(
text
)
>=
0
:
self
.
show
(
name
,
headers
,
body
,
1
)
self
.
show
(
name
,
title
,
text
,
1
)
n
=
n
+
1
n
=
n
+
1
if
not
n
:
if
not
n
:
print
"No hits."
print
"No hits."
def
do_edit
(
self
):
def
do_edit
(
self
):
name
=
self
.
name
name
=
self
.
name
headers
,
body
=
self
.
read
(
name
)
headers
,
text
=
self
.
read
(
name
)
if
not
headers
:
if
not
headers
:
print
"Invalid file name"
,
name
print
"Invalid file name"
,
name
return
return
...
@@ -137,32 +139,26 @@ class FAQServer:
...
@@ -137,32 +139,26 @@ class FAQServer:
<TITLE>Python FAQ Edit Form</TITLE>
<TITLE>Python FAQ Edit Form</TITLE>
<H1>Python FAQ Edit Form</H1>
<H1>Python FAQ Edit Form</H1>
"""
"""
self
.
showheaders
(
headers
)
title
=
headers
[
'title'
]
title
=
headers
[
'title'
]
print
"<FORM METHOD=POST ACTION=faq.py>"
self
.
showedit
(
name
,
headers
,
text
)
print
"""
print
"""
<FORM METHOD=POST ACTION=faq.py>
<INPUT TYPE=text SIZE=80 NAME=title VALUE="%s"<BR>
<TEXTAREA COLS=80 ROWS=20 NAME=text>"""
%
title
print
cgi
.
escape
(
string
.
strip
(
body
))
print
"""</TEXTAREA>
<BR>
<INPUT TYPE=submit VALUE="Review Edit">
<INPUT TYPE=submit VALUE="Review Edit">
<INPUT TYPE=hidden NAME=req VALUE=review>
<INPUT TYPE=hidden NAME=req VALUE=review>
<INPUT TYPE=hidden NAME=name VALUE=%s>
<INPUT TYPE=hidden NAME=name VALUE=%s>
</FORM>
</FORM>
<HR>
<HR>
"""
%
name
"""
%
name
self
.
show
(
name
,
headers
,
body
)
self
.
show
(
name
,
title
,
text
)
def
do_review
(
self
):
def
do_review
(
self
):
if
self
.
commit
:
self
.
checkin
()
return
name
=
self
.
name
name
=
self
.
name
text
=
self
.
text
text
=
self
.
text
commit
=
self
.
commit
title
=
self
.
title
title
=
self
.
title
if
commit
:
headers
,
oldtext
=
self
.
read
(
name
)
self
.
precheckin
(
name
,
text
,
title
)
return
headers
,
body
=
self
.
read
(
name
)
if
not
headers
:
if
not
headers
:
print
"Invalid file name"
,
name
print
"Invalid file name"
,
name
return
return
...
@@ -170,19 +166,26 @@ class FAQServer:
...
@@ -170,19 +166,26 @@ class FAQServer:
<TITLE>Python FAQ Review Form</TITLE>
<TITLE>Python FAQ Review Form</TITLE>
<H1>Python FAQ Review Form</H1>
<H1>Python FAQ Review Form</H1>
"""
"""
self
.
show
(
name
,
{
'title'
:
title
},
text
)
self
.
show
(
name
,
title
,
text
)
print
"<FORM METHOD=POST ACTION=faq.py>"
if
self
.
log
and
self
.
author
and
'@'
in
self
.
email
:
print
"""
print
"""
<FORM METHOD=POST ACTION=faq.py>
<INPUT TYPE=submit NAME=commit VALUE="Commit">
<INPUT TYPE=submit NAME=commit VALUE="Commit">
Click this button to commit the change.
<P>
<P>
<HR>
<HR>
<P>
"""
"""
self
.
showheaders
(
headers
)
else
:
print
"""
To commit this change, please enter your name,
email and a log message in the form below.
<P>
<HR>
<P>
"""
self
.
showedit
(
name
,
headers
,
text
)
print
"""
print
"""
<INPUT TYPE=text SIZE=80 NAME=title VALUE="%s"<BR>
<TEXTAREA COLS=80 ROWS=20 NAME=text>"""
%
title
print
cgi
.
escape
(
string
.
strip
(
text
))
print
"""</TEXTAREA>
<BR>
<BR>
<INPUT TYPE=submit VALUE="Review Edit">
<INPUT TYPE=submit VALUE="Review Edit">
<INPUT TYPE=hidden NAME=req VALUE=review>
<INPUT TYPE=hidden NAME=req VALUE=review>
...
@@ -191,8 +194,126 @@ class FAQServer:
...
@@ -191,8 +194,126 @@ class FAQServer:
<HR>
<HR>
"""
%
name
"""
%
name
def
precheckin
(
self
,
name
,
text
,
title
):
def
checkin
(
self
):
import
regsub
,
time
,
tempfile
name
=
self
.
name
headers
,
oldtext
=
self
.
read
(
name
)
if
not
headers
:
print
"Invalid file name"
,
name
return
text
=
self
.
text
title
=
self
.
title
author
=
self
.
author
email
=
self
.
email
log
=
self
.
log
text
=
regsub
.
gsub
(
"
\
r
\
n
"
,
"
\
n
"
,
text
)
log
=
regsub
.
gsub
(
"
\
r
\
n
"
,
"
\
n
"
,
log
)
author
=
string
.
join
(
string
.
split
(
author
))
email
=
string
.
join
(
string
.
split
(
email
))
title
=
string
.
join
(
string
.
split
(
title
))
oldtitle
=
headers
[
'title'
]
oldtitle
=
string
.
join
(
string
.
split
(
oldtitle
))
text
=
string
.
strip
(
text
)
oldtext
=
string
.
strip
(
oldtext
)
if
text
==
oldtext
and
title
==
oldtitle
:
print
"No changes."
# XXX Should exit more ceremoniously
return
# Check that the question number didn't change
if
string
.
split
(
title
)[:
1
]
!=
string
.
split
(
oldtitle
)[:
1
]:
print
"Don't change the question number please."
# XXX Should exit more ceremoniously
return
remhost
=
os
.
environ
[
"REMOTE_HOST"
]
remaddr
=
os
.
environ
[
"REMOTE_ADDR"
]
try
:
os
.
unlink
(
name
+
"~"
)
except
os
.
error
:
pass
pass
try
:
os
.
rename
(
name
,
name
+
"~"
)
except
os
.
error
:
pass
try
:
os
.
unlink
(
name
)
except
os
.
error
:
pass
try
:
f
=
open
(
name
,
"w"
)
except
IOError
,
msg
:
print
"Can't open"
,
name
,
"for writing:"
,
cgi
.
escape
(
str
(
msg
))
# XXX Should exit more ceremoniously
return
now
=
time
.
ctime
(
time
.
time
())
f
.
write
(
"Title: %s
\
n
"
%
title
)
f
.
write
(
"Last-Changed-Date: %s
\
n
"
%
now
)
f
.
write
(
"Last-Changed-Author: %s
\
n
"
%
author
)
f
.
write
(
"Last-Changed-Email: %s
\
n
"
%
email
)
f
.
write
(
"Last-Changed-Remote-Host: %s
\
n
"
%
remhost
)
f
.
write
(
"Last-Changed-Remote-Address: %s
\
n
"
%
remaddr
)
keys
=
headers
.
keys
()
keys
.
sort
()
keys
.
remove
(
'title'
)
for
key
in
keys
:
if
key
[:
13
]
!=
'last-changed-'
:
f
.
write
(
"%s: %s
\
n
"
%
(
string
.
capwords
(
key
,
'-'
),
headers
[
key
]))
f
.
write
(
"
\
n
"
)
f
.
write
(
text
)
f
.
write
(
"
\
n
"
)
f
.
close
()
tfn
=
tempfile
.
mktemp
()
f
=
open
(
tfn
,
"w"
)
f
.
write
(
"Last-Changed-Date: %s
\
n
"
%
now
)
f
.
write
(
"Last-Changed-Author: %s
\
n
"
%
author
)
f
.
write
(
"Last-Changed-Email: %s
\
n
"
%
email
)
f
.
write
(
"Last-Changed-Remote-Host: %s
\
n
"
%
remhost
)
f
.
write
(
"Last-Changed-Remote-Address: %s
\
n
"
%
remaddr
)
f
.
write
(
"
\
n
"
)
f
.
write
(
log
)
f
.
write
(
"
\
n
"
)
f
.
close
()
p
=
os
.
popen
(
"""
/depot/gnu/plat/bin/rcs -l %s </dev/null 2>&1
/depot/gnu/plat/bin/ci -u %s <%s 2>&1
rm -f %s
"""
%
(
name
,
name
,
tfn
,
tfn
))
output
=
p
.
read
()
sts
=
p
.
close
()
if
not
sts
:
print
"""
<H1>Python FAQ Entry Edited</H1>
<HR>
"""
self
.
show
(
name
,
title
,
text
,
1
)
if
output
:
print
"<PRE>%s</PRE>"
%
cgi
.
escape
(
output
)
else
:
print
"""
<H1>Python FAQ Entry Commit Failed</H1>
Exit status 0x%04x
"""
%
sts
if
output
:
print
"<PRE>%s</PRE>"
%
cgi
.
escape
(
output
)
def
showedit
(
self
,
name
,
headers
,
text
):
title
=
headers
[
'title'
]
print
"""
Title: <INPUT TYPE=text SIZE=70 NAME=title VALUE="%s"<BR>
<TEXTAREA COLS=80 ROWS=20 NAME=text>"""
%
title
print
cgi
.
escape
(
string
.
strip
(
text
))
print
"""</TEXTAREA>
<BR>
Please provide the following information for logging purposes:
<BR>
<CODE>Name : </CODE><INPUT TYPE=text SIZE=70 NAME=author VALUE="%s"<BR>
<CODE>Email: </CODE><INPUT TYPE=text SIZE=70 NAME=email VALUE="%s"<BR>
Log message (reason for the change):<BR>
<TEXTAREA COLS=80 ROWS=5 NAME=log>
\
n
%s
\
n
</TEXTAREA>
"""
%
(
self
.
author
,
self
.
email
,
self
.
log
)
def
showheaders
(
self
,
headers
):
def
showheaders
(
self
,
headers
):
print
"<UL>"
print
"<UL>"
...
@@ -209,17 +330,16 @@ class FAQServer:
...
@@ -209,17 +330,16 @@ class FAQServer:
return
None
,
None
return
None
,
None
f
=
open
(
name
)
f
=
open
(
name
)
headers
=
rfc822
.
Message
(
f
)
headers
=
rfc822
.
Message
(
f
)
body
=
f
.
read
()
text
=
f
.
read
()
f
.
close
()
f
.
close
()
return
headers
,
body
return
headers
,
text
def
show
(
self
,
name
,
headers
,
body
,
edit
=
0
):
def
show
(
self
,
name
,
title
,
text
,
edit
=
0
):
# XXX Should put <A> tags around recognizable URLs
# XXX Should put <A> tags around recognizable URLs
# XXX Should also turn "see section N" into hyperlinks
# XXX Should also turn "see section N" into hyperlinks
title
=
headers
[
'title'
]
print
"<H2>%s</H2>"
%
title
print
"<H2>%s</H2>"
%
title
pre
=
0
pre
=
0
for
line
in
string
.
split
(
body
,
'
\
n
'
):
for
line
in
string
.
split
(
text
,
'
\
n
'
):
if
not
string
.
strip
(
line
):
if
not
string
.
strip
(
line
):
if
pre
:
if
pre
:
print
'</PRE>'
print
'</PRE>'
...
@@ -227,7 +347,7 @@ class FAQServer:
...
@@ -227,7 +347,7 @@ class FAQServer:
else
:
else
:
print
'<P>'
print
'<P>'
else
:
else
:
if
line
==
string
.
lstrip
(
line
):
if
line
==
string
.
lstrip
(
line
):
# I.e., no leading whitespace
if
pre
:
if
pre
:
print
'</PRE>'
print
'</PRE>'
pre
=
0
pre
=
0
...
@@ -247,9 +367,15 @@ class FAQServer:
...
@@ -247,9 +367,15 @@ class FAQServer:
print
"Content-type: text/html
\
n
"
print
"Content-type: text/html
\
n
"
dt
=
0
try
:
try
:
import
time
t1
=
time
.
time
()
x
=
FAQServer
()
x
=
FAQServer
()
x
.
main
()
x
.
main
()
t2
=
time
.
time
()
dt
=
t2
-
t1
except
:
except
:
print
"<HR>Sorry, an error occurred"
print
"<HR>Sorry, an error occurred"
cgi
.
print_exception
()
cgi
.
print_exception
()
print
"<!-- dt = %s -->"
%
str
(
round
(
dt
,
3
))
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment