Commit f85b3c7a authored by Arnaud Fontaine's avatar Arnaud Fontaine Committed by Jérome Perrin

WIP: zope4py3 TODO.

parent f224f1c2
...@@ -40,7 +40,9 @@ ...@@ -40,7 +40,9 @@
from Acquisition import aq_base, aq_inner from Acquisition import aq_base, aq_inner
from collections import OrderedDict from collections import OrderedDict
from io import BytesIO from io import BytesIO
from zodbpickle.pickle import Pickler # XXX-zope4py3: Python3 C implementation does not have Unpickler.dispatch
# attribute. dispatch_table should be used instead.
from zodbpickle.slowpickle import Pickler
from xml.sax.saxutils import escape, unescape from xml.sax.saxutils import escape, unescape
from lxml import etree from lxml import etree
from lxml.etree import Element, SubElement from lxml.etree import Element, SubElement
......
...@@ -15,8 +15,9 @@ ...@@ -15,8 +15,9 @@
"""Provide conversion between Python pickles and XML """Provide conversion between Python pickles and XML
""" """
# Python3 C implementation does not have Unpickler.dispatch attribute # XXX-zope4py3: Python3 C implementation does not have Unpickler.dispatch
from zodbpickle.pickle import * # attribute. dispatch_table should be used instead.
from zodbpickle.slowpickle import *
import struct import struct
import base64 import base64
......
import re import re
import os import os
import sys import sys
from sgmllib import SGMLParser, SGMLParseError # XXX-zope4py3: sgmllib removed from standard library in favor of
# html.parser.HTMLParser
#from sgmllib import SGMLParser, SGMLParseError
try: try:
# Need to be imported before win32api to avoid dll loading # Need to be imported before win32api to avoid dll loading
...@@ -142,95 +144,95 @@ NASTY_TAGS = { 'script' : 1 ...@@ -142,95 +144,95 @@ NASTY_TAGS = { 'script' : 1
class IllegalHTML( ValueError ): class IllegalHTML( ValueError ):
pass pass
class StrippingParser( SGMLParser ): # class StrippingParser( SGMLParser ):
""" Pass only allowed tags; raise exception for known-bad. """ # """ Pass only allowed tags; raise exception for known-bad. """
from htmlentitydefs import entitydefs # replace entitydefs from sgmllib # from html.entities import entitydefs # replace entitydefs from sgmllib
def __init__( self ): # def __init__( self ):
SGMLParser.__init__( self ) # SGMLParser.__init__( self )
self.result = "" # self.result = ""
def handle_data( self, data ): # def handle_data( self, data ):
if data: # if data:
self.result = self.result + data # self.result = self.result + data
def handle_charref( self, name ): # def handle_charref( self, name ):
self.result = "%s&#%s;" % ( self.result, name ) # self.result = "%s&#%s;" % ( self.result, name )
def handle_entityref(self, name): # def handle_entityref(self, name):
if name in self.entitydefs: # if name in self.entitydefs:
x = ';' # x = ';'
else: # else:
# this breaks unstandard entities that end with ';' # # this breaks unstandard entities that end with ';'
x = '' # x = ''
self.result = "%s&%s%s" % (self.result, name, x) # self.result = "%s&%s%s" % (self.result, name, x)
def unknown_starttag(self, tag, attrs): # def unknown_starttag(self, tag, attrs):
""" Delete all tags except for legal ones. # """ Delete all tags except for legal ones.
""" # """
if tag in VALID_TAGS: # if tag in VALID_TAGS:
self.result = self.result + '<' + tag # self.result = self.result + '<' + tag
for k, v in attrs: # for k, v in attrs:
if k.lower().startswith( 'on' ): # if k.lower().startswith( 'on' ):
raise IllegalHTML('Javascipt event "%s" not allowed.' % k) # raise IllegalHTML('Javascipt event "%s" not allowed.' % k)
if v.lower().startswith( 'javascript:' ): # if v.lower().startswith( 'javascript:' ):
raise IllegalHTML('Javascipt URI "%s" not allowed.' % v) # raise IllegalHTML('Javascipt URI "%s" not allowed.' % v)
self.result = '%s %s="%s"' % (self.result, k, v) # self.result = '%s %s="%s"' % (self.result, k, v)
endTag = '</%s>' % tag # endTag = '</%s>' % tag
if VALID_TAGS.get(tag): # if VALID_TAGS.get(tag):
self.result = self.result + '>' # self.result = self.result + '>'
else: # else:
self.result = self.result + ' />' # self.result = self.result + ' />'
elif NASTY_TAGS.get( tag ): # elif NASTY_TAGS.get( tag ):
raise IllegalHTML('Dynamic tag "%s" not allowed.' % tag) # raise IllegalHTML('Dynamic tag "%s" not allowed.' % tag)
else: # else:
pass # omit tag # pass # omit tag
def unknown_endtag(self, tag): # def unknown_endtag(self, tag):
if VALID_TAGS.get( tag ): # if VALID_TAGS.get( tag ):
self.result = "%s</%s>" % (self.result, tag) # self.result = "%s</%s>" % (self.result, tag)
remTag = '</%s>' % tag # remTag = '</%s>' % tag
def parse_declaration(self, i): # def parse_declaration(self, i):
"""Fix handling of CDATA sections. Code borrowed from BeautifulSoup. # """Fix handling of CDATA sections. Code borrowed from BeautifulSoup.
""" # """
j = None # j = None
if self.rawdata[i:i+9] == '<![CDATA[': # if self.rawdata[i:i+9] == '<![CDATA[':
k = self.rawdata.find(']]>', i) # k = self.rawdata.find(']]>', i)
if k == -1: # if k == -1:
k = len(self.rawdata) # k = len(self.rawdata)
data = self.rawdata[i+9:k] # data = self.rawdata[i+9:k]
j = k+3 # j = k+3
self.result.append("<![CDATA[%s]]>" % data) # self.result.append("<![CDATA[%s]]>" % data)
else: # else:
try: # try:
j = SGMLParser.parse_declaration(self, i) # j = SGMLParser.parse_declaration(self, i)
except SGMLParseError: # except SGMLParseError:
toHandle = self.rawdata[i:] # toHandle = self.rawdata[i:]
self.result.append(toHandle) # self.result.append(toHandle)
j = i + len(toHandle) # j = i + len(toHandle)
return j # return j
def scrubHTML( html ): # def scrubHTML( html ):
""" Strip illegal HTML tags from string text. """ # """ Strip illegal HTML tags from string text. """
parser = StrippingParser() # parser = StrippingParser()
parser.feed( html ) # parser.feed( html )
parser.close() # parser.close()
return parser.result # return parser.result
<component>
<import package="ZServer" />
<sectiontype name="timer-server"
datatype="Products.TimerService.timerserver.TimerServerFactory"
implements="ZServer.server">
<key name="interval" datatype="float" default="600">
<description>
Interval in seconds. Supports fractions of a second.
</description>
</key>
</sectiontype>
</component>
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment