Python & CGI Programming


CommonRoutines.py


import string

def HTTPText(text):
    """Make HTML changes so the screen can be displayed from the
    CGI directory"""

    text = text.strip()
    text = text.replace('href="', 'href="../')
    text = text.replace('src="', 'src="../')

    return text


def StringReplace (text, oldstr, newstr):
    """Replaces the string variable with the new string"""
    if (newstr == None):
        text = text.replace(oldstr, '')
    else:
        text = text.replace(oldstr, newstr)
                    
    return text


def ValueReplace(text, formvalue, value):
    """Replace a value on a form field"""
    
    if (value == None):
        text = StringReplace (text, formvalue, '')
    else:
        val  = 'value="' + value + '"'
        text = StringReplace (text, formvalue, val)

    return text