Re: Stupid Newbie Question Concerning CGI and Reading Forward Slashes



Joey C. wrote:
Hi, I want to make a configuration script for something and it needs to
read inputs from an HTML file.  A couple of these inputs are textboxes
that the user inputs a path in.  For example:
Your Home Directory:
[/home/me/public_html/]

So, I'm using Python to read these inputs and store them in a
configuration file.  However, I cannot get the CGI to read the forward
slashes (/).  It just leaves a blank area.  So, for example:
Input: /usr/bin/sendmail
Reads: sendmail

Input: /home/me/public_html/
Reads: (Nothing.)

In which case you must be doing something wrong, as this mechanism is pretty much tried and tested, with no such oddities recorded.

params = cgi.FieldStorage()

def writep(key, name):
  if params.has_key(key):
    fconfig.write(name + ": " + os.path.split(params[key].value)[1] +
";\n")

You do, I suppose, realize that os.path.split(...)[1] will specifically remove the leading components of the path?

^ This is the function for handling a key that is read by the cgi.  The
"name" is the name that it stores the key under so the configuration
file looks like:
name: key;[Line Break]

This all seems as expected.

Surely it should be the *key* (i.e. the name of the field in the HTML file) that you use to store the whole value, i.e.:

def writep(key, name):
  if params.has_key(key):
    fconfig.write("%s: %s" % (name, params[key].value)

However, is there a way to get it to read the forward slashes?  If
there isn't do you suggest having the user use a different character
and adding a function in the script to substitute a forward slash for
that character?

I tried looking for this for a long while, but maybe I didn't search
enough.  Thanks for all of your help and I'm sorry if this is a
question that has been asked 15 million times.

Joey C.

It's not a common question, but it's relatively easily answered. You are splitting everything but the filename off with os.path.split and then complaining about the result! Once you stop doing that your problem is solved.

regards
 Steve
--
Steve Holden        +1 703 861 4237  +1 800 494 3119
Holden Web LLC             http://www.holdenweb.com/
Python Web Programming  http://pydish.holdenweb.com/

.



Relevant Pages

  • Re: Variables interpolated in character classes?
    ... by generating an html file with the same content, ... Here's an edited-for-brevity ... Then I realized, the regex contains "$_", which was embedding ... I had thought that character classes removed the special ...
    (comp.lang.perl.misc)
  • Re: c# .net write html to word special characters not writing
    ... In this case, you're lucky because Word has a lot of code in it to deal with users that lie to it, so once it fails to open the file you gave it as an actual Word document, it goes through other file formats it understands, detects the data as HTML, and interprets it that way. ... Given what little code you've posted, there's no reason that the character entities such as "™" shouldn't be preserved correctly. ... If the "existing html file" is not in fact exactly the same characters you wind up writing to the new ".doc" file, then any number of differences in the way that Word ultimately winds up parsing the file data could explain what you're seeing. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Problem round-tripping with xml.dom.minidom pretty-printer
    ... I have run into a problem using minidom. ... I have an HTML file that I ... If you toprettyxml an XML document twice in a row, then the second one will also add newlines and tabs around the newlines and tabs added by the first. ... Finally, normalizeis supposed to merge consecutive sibling character nodes, however it will never remove character contents even if they are blank. ...
    (comp.lang.python)
  • Re: Junk characters when using StreamReader and StreamWriter
    ... is just a single-byte ASCII character and Word just puts it into ... I have a VB.Net application that parses an HTML file. ... I use a StreamReader to read in the file...regular expressions to parse ... Dim sr As New StreamReader ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Allowing for Negative Numbers
    ... > user inputs to a textbox. ... If the user attempts to enter a non-numeric character ... signs and the non-first character condition in one test). ...
    (microsoft.public.vb.general.discussion)