Back to index

plone3  3.1.7
Public Member Functions | Public Attributes
PortalTransforms.libtransforms.utils.StrippingParser Class Reference
Inheritance diagram for PortalTransforms.libtransforms.utils.StrippingParser:
Inheritance graph
[legend]
Collaboration diagram for PortalTransforms.libtransforms.utils.StrippingParser:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def __init__
def handle_data
def handle_charref
def handle_entityref
def unknown_starttag
def unknown_endtag

Public Attributes

 result

Detailed Description

Pass only allowed tags;  raise exception for known-bad.  

Definition at line 145 of file utils.py.


Constructor & Destructor Documentation

Definition at line 150 of file utils.py.

00150 
00151     def __init__( self ):
00152 
00153         SGMLParser.__init__( self )
00154         self.result = ""


Member Function Documentation

Definition at line 160 of file utils.py.

00160 
00161     def handle_charref( self, name ):
00162 
00163         self.result = "%s&#%s;" % ( self.result, name )

Definition at line 155 of file utils.py.

00155 
00156     def handle_data( self, data ):
00157 
00158         if data:
00159             self.result = self.result + data

Definition at line 164 of file utils.py.

00164 
00165     def handle_entityref(self, name):
00166 
00167         if self.entitydefs.has_key(name):
00168             x = ';'
00169         else:
00170             # this breaks unstandard entities that end with ';'
00171             x = ''
00172 
00173         self.result = "%s&%s%s" % (self.result, name, x)

Definition at line 204 of file utils.py.

00204 
00205     def unknown_endtag(self, tag):
00206 
00207         if VALID_TAGS.get( tag ):
00208 
00209             self.result = "%s</%s>" % (self.result, tag)
00210             remTag = '</%s>' % tag
00211 

Delete all tags except for legal ones.

Definition at line 174 of file utils.py.

00174 
00175     def unknown_starttag(self, tag, attrs):
00176 
00177         """ Delete all tags except for legal ones.
00178         """
00179         if VALID_TAGS.has_key(tag):
00180 
00181             self.result = self.result + '<' + tag
00182 
00183             for k, v in attrs:
00184 
00185                 if k.lower().startswith( 'on' ):
00186                     raise IllegalHTML, 'Javascipt event "%s" not allowed.' % k
00187 
00188                 if v.lower().startswith( 'javascript:' ):
00189                     raise IllegalHTML, 'Javascipt URI "%s" not allowed.' % v
00190 
00191                 self.result = '%s %s="%s"' % (self.result, k, v)
00192 
00193             endTag = '</%s>' % tag
00194             if VALID_TAGS.get(tag):
00195                 self.result = self.result + '>'
00196             else:
00197                 self.result = self.result + ' />'
00198 
00199         elif NASTY_TAGS.get( tag ):
00200             raise IllegalHTML, 'Dynamic tag "%s" not allowed.' % tag
00201 
00202         else:
00203             pass    # omit tag


Member Data Documentation

Definition at line 153 of file utils.py.


The documentation for this class was generated from the following file: