Problems with exec scoping (solved)

Delaney, Timothy tdelaney at avaya.com
Mon Jun 3 02:51:24 EDT 2002


> From: Erik Walthinsen [mailto:omega at temple-baptist.com]
> 
> Well, it turns out that I was being an idiot and not checking 
> the source
> of the returned HTML page.  When repr() is run on an object, 
> it returns a
> string such as:
> 
> <captiveclient.CaptiveClient instance at 0x8189264>
> 
> ...which conveniently doesn't get displayed as text in a 
> browser, looking
> as much like HTML as it does.  I discovered this as I wrote a 
> __repr__()
> function for the class and had large chunks of the page 
> disappear because
> I didnt stick a trailing ">" on the returned string.  
> Switching to "[]"
> solved the problem.
> 
> I will now go and see about writing a HTML-textizer for use in such
> situations.

Here's a very simple one ...

entitydefs = {}

for k, v in htmlentitydefs.entitydefs.items():
    entitydefs[v] = '&' + k + ';'

def htmlEncode (str):
    """"""

    str = string.replace(str, '&', '&')

    for k, v in entitydefs.items():
        if v != '&':
            str = string.replace(str, k, v)

    return str

def htmlDecode (str):
    """"""
    for k, v in entitydefs.items():
        if v != '&':
            str = string.replace(str, v, k)
    
    str = string.replace(str, '&', '&')
    return str





More information about the Python-list mailing list