Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
f66cccf5
Kaydet (Commit)
f66cccf5
authored
Eki 17, 2002
tarafından
Guido van Rossum
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Restructure: move all wiki code into a separate module.
üst
26a1ac46
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
116 additions
and
113 deletions
+116
-113
cgi3.py
Demo/cgi/cgi3.py
+1
-113
wiki.py
Demo/cgi/wiki.py
+115
-0
No files found.
Demo/cgi/cgi3.py
Dosyayı görüntüle @
f66cccf5
...
...
@@ -4,119 +4,7 @@
import
cgitb
;
cgitb
.
enable
()
import
os
,
re
,
cgi
,
sys
escape
=
cgi
.
escape
def
main
():
form
=
cgi
.
FieldStorage
()
print
"Content-type: text/html"
print
cmd
=
form
.
getvalue
(
"cmd"
,
"view"
)
page
=
form
.
getvalue
(
"page"
,
"FrontPage"
)
wiki
=
WikiPage
(
page
)
wiki
.
load
()
method
=
getattr
(
wiki
,
'cmd_'
+
cmd
,
None
)
or
wiki
.
cmd_view
method
(
form
)
class
WikiPage
:
homedir
=
"/tmp"
scripturl
=
os
.
path
.
basename
(
sys
.
argv
[
0
])
def
__init__
(
self
,
name
):
if
not
self
.
iswikiword
(
name
):
raise
ValueError
,
"page name is not a wiki word"
self
.
name
=
name
self
.
load
()
def
cmd_view
(
self
,
form
):
print
"<h1>"
,
escape
(
self
.
splitwikiword
(
self
.
name
)),
"</h1>"
print
"<p>"
for
line
in
self
.
data
.
splitlines
():
line
=
line
.
rstrip
()
if
not
line
:
print
"<p>"
continue
words
=
re
.
split
(
'(
\
W+)'
,
line
)
for
i
in
range
(
len
(
words
)):
word
=
words
[
i
]
if
self
.
iswikiword
(
word
):
if
os
.
path
.
isfile
(
self
.
mkfile
(
word
)):
word
=
self
.
mklink
(
"view"
,
word
,
word
)
else
:
word
=
self
.
mklink
(
"new"
,
word
,
word
+
"*"
)
else
:
word
=
escape
(
word
)
words
[
i
]
=
word
print
""
.
join
(
words
)
print
"<hr>"
print
"<p>"
,
self
.
mklink
(
"edit"
,
self
.
name
,
"Edit this page"
)
+
";"
print
self
.
mklink
(
"view"
,
"FrontPage"
,
"go to front page"
)
+
"."
def
cmd_edit
(
self
,
form
,
label
=
"Change"
):
print
"<h1>"
,
label
,
self
.
name
,
"</h1>"
print
'<form method="POST" action="
%
s">'
%
self
.
scripturl
s
=
'<textarea cols="70" rows="20" name="text">
%
s</textarea>'
print
s
%
self
.
data
print
'<input type="hidden" name="cmd" value="create">'
print
'<input type="hidden" name="page" value="
%
s">'
%
self
.
name
print
'<br>'
print
'<input type="submit" value="
%
s Page">'
%
label
print
"</form>"
def
cmd_create
(
self
,
form
):
self
.
data
=
form
.
getvalue
(
"text"
,
""
)
.
strip
()
error
=
self
.
store
()
if
error
:
print
"<h1>I'm sorry. That didn't work</h1>"
print
"<p>An error occurred while attempting to write the file:"
print
"<p>"
,
escape
(
error
)
else
:
self
.
cmd_view
(
form
)
def
cmd_new
(
self
,
form
):
self
.
cmd_edit
(
form
,
label
=
"Create Page"
)
def
iswikiword
(
self
,
word
):
return
re
.
match
(
"[A-Z][a-z]+([A-Z][a-z]*)+"
,
word
)
def
splitwikiword
(
self
,
word
):
chars
=
[]
for
c
in
word
:
if
chars
and
c
.
isupper
():
chars
.
append
(
' '
)
chars
.
append
(
c
)
return
""
.
join
(
chars
)
def
mkfile
(
self
,
name
=
None
):
if
name
is
None
:
name
=
self
.
name
return
os
.
path
.
join
(
self
.
homedir
,
name
)
def
mklink
(
self
,
cmd
,
page
,
text
):
link
=
self
.
scripturl
+
"?cmd="
+
cmd
+
"&page="
+
page
return
'<a href="
%
s">
%
s</a>'
%
(
link
,
text
)
def
load
(
self
):
try
:
f
=
open
(
self
.
mkfile
())
data
=
f
.
read
()
.
strip
()
f
.
close
()
except
IOError
:
data
=
""
self
.
data
=
data
def
store
(
self
):
data
=
self
.
data
try
:
f
=
open
(
self
.
mkfile
(),
"w"
)
f
.
write
(
data
)
if
data
and
not
data
.
endswith
(
'
\n
'
):
f
.
write
(
'
\n
'
)
f
.
close
()
return
""
except
IOError
,
err
:
return
"IOError:
%
s"
%
str
(
err
)
from
wiki
import
main
if
__name__
==
"__main__"
:
main
()
Demo/cgi/wiki.py
0 → 100644
Dosyayı görüntüle @
f66cccf5
"""Wiki main program. Imported and run by cgi3.py."""
import
os
,
re
,
cgi
,
sys
escape
=
cgi
.
escape
def
main
():
form
=
cgi
.
FieldStorage
()
print
"Content-type: text/html"
print
cmd
=
form
.
getvalue
(
"cmd"
,
"view"
)
page
=
form
.
getvalue
(
"page"
,
"FrontPage"
)
wiki
=
WikiPage
(
page
)
wiki
.
load
()
method
=
getattr
(
wiki
,
'cmd_'
+
cmd
,
None
)
or
wiki
.
cmd_view
method
(
form
)
class
WikiPage
:
homedir
=
"/tmp"
scripturl
=
os
.
path
.
basename
(
sys
.
argv
[
0
])
def
__init__
(
self
,
name
):
if
not
self
.
iswikiword
(
name
):
raise
ValueError
,
"page name is not a wiki word"
self
.
name
=
name
self
.
load
()
def
cmd_view
(
self
,
form
):
print
"<h1>"
,
escape
(
self
.
splitwikiword
(
self
.
name
)),
"</h1>"
print
"<p>"
for
line
in
self
.
data
.
splitlines
():
line
=
line
.
rstrip
()
if
not
line
:
print
"<p>"
continue
words
=
re
.
split
(
'(
\
W+)'
,
line
)
for
i
in
range
(
len
(
words
)):
word
=
words
[
i
]
if
self
.
iswikiword
(
word
):
if
os
.
path
.
isfile
(
self
.
mkfile
(
word
)):
word
=
self
.
mklink
(
"view"
,
word
,
word
)
else
:
word
=
self
.
mklink
(
"new"
,
word
,
word
+
"*"
)
else
:
word
=
escape
(
word
)
words
[
i
]
=
word
print
""
.
join
(
words
)
print
"<hr>"
print
"<p>"
,
self
.
mklink
(
"edit"
,
self
.
name
,
"Edit this page"
)
+
";"
print
self
.
mklink
(
"view"
,
"FrontPage"
,
"go to front page"
)
+
"."
def
cmd_edit
(
self
,
form
,
label
=
"Change"
):
print
"<h1>"
,
label
,
self
.
name
,
"</h1>"
print
'<form method="POST" action="
%
s">'
%
self
.
scripturl
s
=
'<textarea cols="70" rows="20" name="text">
%
s</textarea>'
print
s
%
self
.
data
print
'<input type="hidden" name="cmd" value="create">'
print
'<input type="hidden" name="page" value="
%
s">'
%
self
.
name
print
'<br>'
print
'<input type="submit" value="
%
s Page">'
%
label
print
"</form>"
def
cmd_create
(
self
,
form
):
self
.
data
=
form
.
getvalue
(
"text"
,
""
)
.
strip
()
error
=
self
.
store
()
if
error
:
print
"<h1>I'm sorry. That didn't work</h1>"
print
"<p>An error occurred while attempting to write the file:"
print
"<p>"
,
escape
(
error
)
else
:
self
.
cmd_view
(
form
)
def
cmd_new
(
self
,
form
):
self
.
cmd_edit
(
form
,
label
=
"Create Page"
)
def
iswikiword
(
self
,
word
):
return
re
.
match
(
"[A-Z][a-z]+([A-Z][a-z]*)+"
,
word
)
def
splitwikiword
(
self
,
word
):
chars
=
[]
for
c
in
word
:
if
chars
and
c
.
isupper
():
chars
.
append
(
' '
)
chars
.
append
(
c
)
return
""
.
join
(
chars
)
def
mkfile
(
self
,
name
=
None
):
if
name
is
None
:
name
=
self
.
name
return
os
.
path
.
join
(
self
.
homedir
,
name
+
".txt"
)
def
mklink
(
self
,
cmd
,
page
,
text
):
link
=
self
.
scripturl
+
"?cmd="
+
cmd
+
"&page="
+
page
return
'<a href="
%
s">
%
s</a>'
%
(
link
,
text
)
def
load
(
self
):
try
:
f
=
open
(
self
.
mkfile
())
data
=
f
.
read
()
.
strip
()
f
.
close
()
except
IOError
:
data
=
""
self
.
data
=
data
def
store
(
self
):
data
=
self
.
data
try
:
f
=
open
(
self
.
mkfile
(),
"w"
)
f
.
write
(
data
)
if
data
and
not
data
.
endswith
(
'
\n
'
):
f
.
write
(
'
\n
'
)
f
.
close
()
return
""
except
IOError
,
err
:
return
"IOError:
%
s"
%
str
(
err
)
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