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
e1c3f36c
Kaydet (Commit)
e1c3f36c
authored
Eyl 09, 1996
tarafından
Jack Jansen
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Documented preliminary CGI applet.
üst
09da209c
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
86 additions
and
0 deletions
+86
-0
cgi.html
Mac/Demo/cgi.html
+86
-0
No files found.
Mac/Demo/cgi.html
0 → 100644
Dosyayı görüntüle @
e1c3f36c
<HTML><HEAD><TITLE>
Using python to create CGI scripts
</TITLE></HEAD>
<BODY>
<H1>
Using python to create CGI scripts
</H1>
<HR>
In this document we will (eventually) explain how to create Python CGI scripts
for use with NetPresenz and probably other Mac-based HTTP servers too.
Since CGI scripts are AppleEvent servers on the mac we will also learn
a little about general AppleEvent server programming and about applet
debugging.
<p>
<blockquote>
Note that the current setup is very preliminary, and hence
itis probably not wise to base your strategic products on the information
in this document:-) In stead, play with the code here and join the
<a
href=
"mailto:pythonmac-sig-request@python.org"
>
pythonmac-sig
</a>
, where
we I would like to have a discussion on a real design for a Mac CGI framework
(preferrably something that will make CGI scripts portable to unix and other
platforms).
</blockquote>
<h2>
AppleEvent servers
</h2>
Since AppleEvent clients are easier to write and understand than servers
you should probably read the section on
<a
href=
"applescript.html"
>
Open Scripting
clients in Python
</a>
first.
<p>
Next, let us have a look at the AE Server framework,
<a
href=
"../Lib/toolbox/MiniAEFrame.py"
>
MiniAEFrame.py
</a>
.
This file contains two classes,
<code>
MiniApplication
</code>
and
<code>
AEServer
</code>
.
MiniApplication is a tiny replacement for
<code>
FrameWork.Application
</code>
,
suitable if your application does not need windows and such.
<blockquote>
Actually, Framework.Application has a problem for AE Servers,
due to the way it expects to be quit through an exception, and raising an exception
while inside an Apple Event handler is a very bad idea. This will be fixed.
</blockquote>
AEServer is a bit of glue that does part of the appleevent decoding for you. You
call
<code>
installaehandler
</code>
passing it the class and id (4-char strings)
of the event you have a handler for and the handler callback routine. When the
appleevent occurs your callback is called with the right arguments. For now,
your argument names are the 4-char values used internally by Open Scripting,
eventually there will be a translation similar to what the generated OSA client
suites provide.
<p>
You can test AEServer by double-clicking it. It will react to the standard
run/open/print/quit OSA commands. If it is running as a normal python script and you
drag a file onto the interpreter the script will tell you what event is got.
<p>
<h2>
A Minimal CGI script
</h2>
To try a CGI script you will first need a http server. I have used the
shareware
<a
href=
"http://www.share.com/peterlewis/netpresenz/netpresenz.html"
>
NetPresenz
</a>
by
<a
href=
"http://www.share.com/peterlewis/"
>
Peter Lewis
</a>
(don't forget to pay if you give it more than a test run!). Install your
http server, and make sure that it can serve textual documents.
<p>
Next, let us have a look at our example CGI scripts. CGI scripts have to be
applications, so we will have to make an applet as explained in
<a
href=
"example2.html"
>
example 2
</a>
. Our applet code,
<a
href=
"cgi/cgitest.cgi.py"
>
cgitest.cgi.py
</a>
is a rather minimal
<code>
execfile
</code>
statement. The reason for this is debugging: the real code is in
<a
href=
"cgi/realcgitest.py"
>
realcgitest.py
</a>
, and this way you do not have
to run mkapplet again every time you change the code. Rename realcgitest.py
to cgitest.cgi.py once you are satisfied that it works.
<p>
The resource file is not very special, with one exception: since we want to do
our own appleevent handling we don't want the Python initialization code to
create argc and argv for use, since this might gobble up any appleevents we are
interested in. For this reason we have included a 'Popt' resource that disables
the argv initialization. An easy way to create this resource is to drop
the
<code>
.rsrc
</code>
file (or the finished applet, if you like) onto
<code>
EditPythonPrefs
</code>
and set the "no argv processing" option.
<p>
The code itself is actually not too complicated either. We install handlers
for "open application" and "quit" (stolen from the test code in MiniAEFrame)
and the
<code>
"WWW\275"/"sdoc"
</code>
event, the event sent on CGI execution.
The cgi handler pretty-prints the CGI arguments in HTML and returns the whole
string that is to be passed to the client. The actual parameters passed
are explained in
<a
href=
"http://www.biap.com/datapig/mrwheat/cgi_params.html"
>
http://www.biap.com/datapig/mrwheat/cgi_params.html
</a>
.
<p>
To test the script drop
<code>
cgitest.cgi.py
</code>
onto
<code>
mkapplet
</code>
,
move the resulting
<code>
cgitest.cgi
</code>
to somewhere where it is reachable
by NetPresenz, and point your web browser towards it.
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