[Tutor] chain gang revolt put down! (longish)
Kirk Bailey
idiot1 at netzero.net
Wed Aug 20 00:09:24 EDT 2003
YET AGAIN, is proven the power of DETERMINED AND UNRELENTING PERSISTANCE.
(Not to mention my need for a formal education in programming...)
ok. I whipped their assets. Experimenting, and reading between the lines, then
reading between the whitespaces, and then I clicked onto an intresting factoid.
Intresting little detail; with os.excecl() and all the others not ending in 'e',
the new program inherits the old program's environment. (~e() versions let you
define the environment the program will receive.) Hmmm...
EDITOR BACKGROUND
Here's how the editor works. It is 2 programs. The first receives the pagename
in the url, and sends out a perfectly normal form with a textarea, preloaded
with the raw page, and the pagename in a hidden input field. The server does not
save any sort of state in itself. You edit the page guts normally in your
browser's window- nothing fancy at all in any of this. You click SAVE (a submit
button) and using the post method, the form sends it to editor script #2, which
saves the data, overwriting the old file file with the new data in the named
file. This also sends the pagename as a hidden input field so it know's what
pagename it is talking about.
That last fact did sidetrack me for a spell, until I realized that such an
action did NOT preclude another simple action- tagging the pagename onto the end
of the url.
I wanted to use the existing reader to display the results of editing the page,
avoiding the need to have not one, but TWO wikicode interpeters. Therefore, the
second editor program must work with the demands of the existing
wikibrowser/interpeter OR I must change it to receive it's pagename 2 different
ways, which I was loathe to do 'cause it's DUMB.
WIKI BROWSER BACKGROUND
Wikinehesa.py get's it's page name in the url, which is passed to the program in
the environment by the web server, in a variable called PATH_INFO. When you
submit a url with data after a program name, seperated with a "/", the data is
saved to the $PATH_INFO environment variable. The variation on this theme is to
use the '?' followed by data; this is the classic GET method of cgi forms.
For instance, to read SandBox page:
http://www.tinylist.org/cgi-bin/wikinehesa.py/SandBox
That last part ('SandBox') is saved as PATH_INFO by the webserver. (The '/'
seperating the page name and the data is discarded.) That's how wikinehesa
works. In fact, this is how ALL wiki's work with either '/' or '?' preceeding
the pagename. Had I used '?pagename' it would have been saved as QUERY_STRING
but all else would be the same.
My task was to tailor editor script #2 so as to feed data to the reader script
using the existing mechenism so it would read the updated page and display it,
in effect serving both as browser and as edit result displayer. Therefore, the
second editor program had to feed the data to the browser in the environment. HOW?
Playing about with the environment is not my long suit, and not something I want
to bung up in a working server with 2 no kidding commercial sites in it.
Therefore, I added this to the form action which is generated by the FIRST
editor script (wikinehesaed1.py):
"(webpath)/wikinehesaed2.py/(pagename)"
That (pagename) gets saved in the environment as $PATH_INFO.
*** This is significant. ***
The second editor script as it's last act hands off to the reader with
os.execl(program), GIVING IT'S ENVIRONMENT TO THAT PROGRAM. The just loaded wiki
interpeter upon starting up looks in the environment it is handed, reads the
PATH_ INFO data, and opens that page normally. No change to the environment was
required, and only a small one in the FIRST editor script was demanded.
In it, I modified the ACTION so that after the name of the page is '/'+pagename+'">'
The program then sends a form with the action defined as
<FORM ACTION="http://www.tinylist.org/cgi-bin/wikinehesaed2.py/SandBox"
METHOD="Post">
The script still runs. The data is saved in the environment by the webserver.
The newly loaded wikireader gets the data and reads the page normally, then
terminates normally.
BIG WIN. I don't have to maintain 2 display engines, or import one, or play
games with the environment or anything else, I just hand the task FROM one
program TO the one browser engine and let it do the work, taking advantage of
how the operating system works and how python works. :-) That it is technically
GET and POST in the same form bothers me not a bit, how about you?
Now if I can only figure out how to get it to process the wikicode into html
perfectly, avoiding the strange chunks and errors it tosses out, I will have a
functional and rather nice looking wiki to give away to one and all. The reverse
search and titlelisting are already working just fine.
Now to see what is going on, take a look at this link:
http://www.tinylist.org/cgi-bin/piki.py/WikiNehesa
A page, rendered by a working wiki engine, named piki.
Here is the EXACT SAME PAGE rendered by wikinehesa:
http://www.tinylist.org/cgi-bin/wikinehesa.py/WikiNehesa
odd stuff, occasional strange bits and peices, handles punctuation following the
wikiwords poorly.
If you want to mess around with editing things, try it in the SandBox, that's
what it's there for.
http;//www.tinylist.org/cgi-bin/wikinehesa.py/SandBox
Click the EDIT PAGE button in the footer to bring up editor script #1 and it's
output of a edit webpage. Submitting that fires off at editor #2, which will
load the browser to display the results.
Now here is a link to examine the guts of the wikinehesa.py script:
http://www.tinylist.org/wikinehesa.txt
And editor #1:
http://www.tinylist.org/wikinehesaed1.txt
and editor #2:
http://www.tinylist.org/wikinehesaed2.txt
ALL are ln soft links leading directly to the scripts and are instantly updated
if the scripts are updated.
PLEASE feel free to laugh at my amateurish code and point out how much better it
could be if I just did (foo).
I will sleep well tonight,. Goodnight all.
--
end
ZZZZzzzz....
Kirk D Bailey
+ think +
http://www.howlermonkey.net +-----+ http://www.tinylist.org
http://www.listville.net | BOX | http://www.sacredelectron.org
Thou art free"-ERIS +-----+ 'Got a light?'-Promethieus
+ think +
Fnord.
More information about the Tutor
mailing list