Commit dd3afb14 authored by Arnaud Fontaine's avatar Arnaud Fontaine

TODO

parent 376bc263
......@@ -85,7 +85,7 @@ class TranslatedPropertyGetter(BaseGetter):
localizer = instance.getPortalObject().Localizer
message_catalog = getattr(localizer, domain, None)
if message_catalog is not None:
return message_catalog.gettext(unicode(value, 'utf8'), lang=self._language).encode('utf8')
return message_catalog.gettext(value, lang=self._language)
else:
return value
......
......@@ -98,8 +98,10 @@ def asString(value):
if value is None:
result = ''
else:
if isinstance(value, unicode):
if six.PY2 and isinstance(value, unicode):
result = value.encode('utf-8')
elif six.PY3 and isinstance(value, bytes):
result = value.decode('utf-8')
else:
result = str(value)
except TypeError:
......@@ -109,6 +111,8 @@ def asString(value):
def asList(value):
"""
Return the value as a list or a type-specific default value if it fails.
XXX-zope4py3: bytes()?
"""
if isinstance(value, (list, tuple)):
result = list(value)
......
......@@ -96,7 +96,7 @@ class TranslatedGetter(Getter):
state_id = wf._getWorkflowStateOf(instance, id_only=1)
warn('Translated workflow state getters, such as %s are deprecated' %
self._id, DeprecationWarning)
return portal.Localizer.erp5_ui.gettext(state_id).encode('utf8')
return portal.Localizer.erp5_ui.gettext(state_id)
psyco.bind(__call__)
......@@ -119,7 +119,7 @@ class TranslatedTitleGetter(TitleGetter):
if result == '':
result = localizer.erp5_ui.gettext(state_title,
lang=selected_language)
return result.encode('utf8')
return result
psyco.bind(__call__)
......
from zope.interface import implementer
import six
from Products.PortalTransforms.interfaces import IDataStream
@implementer(IDataStream)
class datastream:
"""A transformation datastream packet"""
__slots__ = ('name', '_data', '_metadata')
if six.PY2:
__slots__ = ('name', '_data', '_metadata')
def __init__(self, name):
self.__name__ = name
......
import re
import os
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:
# Need to be imported before win32api to avoid dll loading
......@@ -142,95 +144,95 @@ NASTY_TAGS = { 'script' : 1
class IllegalHTML( ValueError ):
pass
class StrippingParser( SGMLParser ):
""" Pass only allowed tags; raise exception for known-bad. """
# class StrippingParser( SGMLParser ):
# """ 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 )
self.result = ""
# SGMLParser.__init__( self )
# self.result = ""
def handle_data( self, data ):
# def handle_data( self, data ):
if data:
self.result = self.result + data
# if 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 self.entitydefs.has_key(name):
x = ';'
else:
# this breaks unstandard entities that end with ';'
x = ''
# if name in self.entitydefs:
# x = ';'
# else:
# # this breaks unstandard entities that end with ';'
# 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.
"""
if VALID_TAGS.has_key(tag):
# """ Delete all tags except for legal ones.
# """
# 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' ):
raise IllegalHTML('Javascipt event "%s" not allowed.' % k)
# if k.lower().startswith( 'on' ):
# raise IllegalHTML('Javascipt event "%s" not allowed.' % k)
if v.lower().startswith( 'javascript:' ):
raise IllegalHTML('Javascipt URI "%s" not allowed.' % v)
# if v.lower().startswith( 'javascript:' ):
# 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
if VALID_TAGS.get(tag):
self.result = self.result + '>'
else:
self.result = self.result + ' />'
# endTag = '</%s>' % tag
# if VALID_TAGS.get(tag):
# self.result = self.result + '>'
# else:
# self.result = self.result + ' />'
elif NASTY_TAGS.get( tag ):
raise IllegalHTML('Dynamic tag "%s" not allowed.' % tag)
# elif NASTY_TAGS.get( tag ):
# raise IllegalHTML('Dynamic tag "%s" not allowed.' % tag)
else:
pass # omit tag
# else:
# 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)
remTag = '</%s>' % tag
# self.result = "%s</%s>" % (self.result, tag)
# remTag = '</%s>' % tag
def parse_declaration(self, i):
"""Fix handling of CDATA sections. Code borrowed from BeautifulSoup.
"""
j = None
if self.rawdata[i:i+9] == '<![CDATA[':
k = self.rawdata.find(']]>', i)
if k == -1:
k = len(self.rawdata)
data = self.rawdata[i+9:k]
j = k+3
self.result.append("<![CDATA[%s]]>" % data)
else:
try:
j = SGMLParser.parse_declaration(self, i)
except SGMLParseError:
toHandle = self.rawdata[i:]
self.result.append(toHandle)
j = i + len(toHandle)
return j
# def parse_declaration(self, i):
# """Fix handling of CDATA sections. Code borrowed from BeautifulSoup.
# """
# j = None
# if self.rawdata[i:i+9] == '<![CDATA[':
# k = self.rawdata.find(']]>', i)
# if k == -1:
# k = len(self.rawdata)
# data = self.rawdata[i+9:k]
# j = k+3
# self.result.append("<![CDATA[%s]]>" % data)
# else:
# try:
# j = SGMLParser.parse_declaration(self, i)
# except SGMLParseError:
# toHandle = self.rawdata[i:]
# self.result.append(toHandle)
# j = i + len(toHandle)
# return j
def scrubHTML( html ):
""" Strip illegal HTML tags from string text. """
parser = StrippingParser()
parser.feed( html )
parser.close()
return parser.result
# def scrubHTML( html ):
# """ Strip illegal HTML tags from string text. """
# parser = StrippingParser()
# parser.feed( html )
# parser.close()
# return parser.result
......@@ -26,49 +26,30 @@ class TimerServer(threading.Thread):
interval)
def run(self):
try:
zopewsgi = sys.modules['Products.ERP5.bin.zopewsgi']
except KeyError:
# wait until the zhttp_server exist in socket_map
# because TimerService has to be started after the Zope HTTPServer
from asyncore import socket_map
ip = port = ''
while 1:
time.sleep(5)
for k, v in socket_map.items():
if hasattr(v, 'addr'):
# see Zope/lib/python/App/ApplicationManager.py: def getServers(self)
type = str(getattr(v, '__class__', 'unknown'))
if type == 'ZServer.HTTPServer.zhttp_server':
ip, port = v.addr
break
if port:
break
from ZServer.PubCore import handle
else:
while 1:
time.sleep(5)
try:
server = zopewsgi.server
break
except AttributeError:
pass
ip, port = server.addr
start_response = lambda *_: None
class handle(object):
def __init__(self, module_name, request, response):
self.service = partial(zopewsgi.publish_module,
request.environ,
start_response,
_module_name=module_name,
_request=request,
_response=response)
server.add_task(self)
def cancel(self):
pass
import Products.ERP5.bin.zopewsgi
while 1:
time.sleep(5)
try:
server = Products.ERP5.bin.zopewsgi.server
break
except AttributeError:
pass
ip, port = server.addr
start_response = lambda *_: None
class handle(object):
def __init__(self, module_name, request, response):
self.service = partial(Products.ERP5.bin.zopewsgi.publish_module,
request.environ,
start_response,
_module_name=module_name,
_request=request,
_response=response)
server.add_task(self)
def cancel(self):
pass
if ip == '0.0.0.0':
ip = socket.gethostbyname(socket.gethostname())
......
<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>
......@@ -41,7 +41,7 @@ except ImportError:
IColumnNode = None
def verifyClass(*args, **kw):
pass
implements = verifyClass
implements = verifyClass # XXX need to be reviewed as it is decorator now
@implementer(INode)
class Node(object):
......
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