Commit 74ac0363 authored by Sidnei da Silva's avatar Sidnei da Silva

- Merge remaining changes from gsoc-python-2.5 branch. We now 'work' on Python 2.6

parents 3e91dac6 a6c2abea
......@@ -219,6 +219,13 @@ Zope Changes
Bugs Fixed
- Launchpad #280334: Fixed problem with 'timeout'
argument/attribute missing in testbrowser tests.
- Launchpad #282677: fixed implementation of guarded_map and
provided tests and implementation for guarded_zip (RestrictedPython).
- Lauchpad #143736,#271395: fixed AttributeError' on _ltid in TempStorage
- 'AccessControl.ZopeGuards.guarded_import' mapped some Unauthorized
......@@ -475,6 +482,18 @@ Zope Changes
- Prevent ZPublisher from insering incorrect <base/> tags into the
headers of plain html files served from Zope3 resource directories.
- Changed the condition checking for setting status of
HTTPResponse from to account for new-style classes.
- The Wrapper_compare function from tp_compare to tp_richcompare.
Also another function Wrapper_richcompare is added.
- The doc test has been slightly changed in ZPublisher to get
the error message extracted correctly.
- The changes made in Acquisition.c in Implicit Acquisition
comparison made avail to Explicit Acquisition comparison also.
- zopedoctest no longer breaks if the URL contains more than one
question mark. It broke even when the second question mark was
......
......@@ -15,19 +15,21 @@
try:
from cAccessControl import rolesForPermissionOn, \
from AccessControl.cAccessControl import rolesForPermissionOn, \
PermissionRole, imPermissionRole, _what_not_even_god_should_do, \
RestrictedDTMLMixin, aq_validate, guarded_getattr, \
setDefaultBehaviors
from cAccessControl import ZopeSecurityPolicy as cZopeSecurityPolicy
from cAccessControl import SecurityManager as cSecurityManager
from AccessControl.cAccessControl import ZopeSecurityPolicy \
as cZopeSecurityPolicy
from AccessControl.cAccessControl import SecurityManager as cSecurityManager
except ImportError:
import sys
# make sure a partial import doesn't pollute sys.modules
del sys.modules[__name__]
from ImplPython import RestrictedDTML, SecurityManager, ZopeSecurityPolicy
raise
from AccessControl.ImplPython import RestrictedDTML
from AccessControl.ImplPython import SecurityManager, ZopeSecurityPolicy
class RestrictedDTML(RestrictedDTMLMixin, RestrictedDTML):
......
......@@ -30,7 +30,7 @@ try:
except ImportError:
_what_not_even_god_should_do = []
from AccessControl import SecurityManagement
from AccessControl.SecurityManagement import getSecurityManager
from AccessControl import Unauthorized
from AccessControl.interfaces import ISecurityPolicy
from AccessControl.interfaces import ISecurityManager
......@@ -721,7 +721,7 @@ def guarded_getattr(inst, name, default=_marker):
# See if we can get the value doing a filtered acquire.
# aq_acquire will either return the same value as held by
# v or it will return an Unauthorized raised by validate.
validate = SecurityManagement.getSecurityManager().validate
validate = getSecurityManager().validate
aq_acquire(inst, name, aq_validate, validate)
return v
......
......@@ -237,18 +237,18 @@ def guarded_reduce(f, seq, initial=_marker):
return reduce(f, guarded_iter(seq), initial)
safe_builtins['reduce'] = guarded_reduce
def guarded_max(item, *items):
def guarded_max(item, *items, **kw):
if items:
item = [item]
item.extend(items)
return max(guarded_iter(item))
return max(guarded_iter(item), **kw)
safe_builtins['max'] = guarded_max
def guarded_min(item, *items):
def guarded_min(item, *items, **kw):
if items:
item = [item]
item.extend(items)
return min(guarded_iter(item))
return min(guarded_iter(item), **kw)
safe_builtins['min'] = guarded_min
def guarded_map(f, *seqs):
......@@ -375,6 +375,17 @@ def builtin_guarded_apply(func, args=(), kws={}):
safe_builtins['apply'] = builtin_guarded_apply
# Similar to min and reduce, use guarded_iter on the sequence being
# tested and apply the original function.
if sys.version_info >= (2, 5):
def guarded_any(seq):
return any(guarded_iter(seq))
safe_builtins['any'] = guarded_any
def guarded_all(seq):
return all(guarded_iter(seq))
safe_builtins['all'] = guarded_all
# This metaclass supplies the security declarations that allow all
# attributes of a class and its instances to be read and written.
def _metaclass(name, bases, dict):
......
......@@ -14,18 +14,18 @@
from unauthorized import Unauthorized
# This has to happen early so things get initialized properly
from Implementation import setImplementation
from AccessControl.Implementation import setImplementation
from SecurityManagement import getSecurityManager, setSecurityPolicy
from SecurityInfo import ClassSecurityInfo, ModuleSecurityInfo
from SecurityInfo import ACCESS_PRIVATE
from SecurityInfo import ACCESS_PUBLIC
from SecurityInfo import ACCESS_NONE
from SecurityInfo import secureModule, allow_module, allow_class
from SimpleObjectPolicies import allow_type
from ZopeGuards import full_write_guard, safe_builtins
from AccessControl.SecurityManagement import getSecurityManager, setSecurityPolicy
from AccessControl.SecurityInfo import ClassSecurityInfo, ModuleSecurityInfo
from AccessControl.SecurityInfo import ACCESS_PRIVATE
from AccessControl.SecurityInfo import ACCESS_PUBLIC
from AccessControl.SecurityInfo import ACCESS_NONE
from AccessControl.SecurityInfo import secureModule, allow_module, allow_class
from AccessControl.SimpleObjectPolicies import allow_type
from AccessControl.ZopeGuards import full_write_guard, safe_builtins
ModuleSecurityInfo('AccessControl').declarePublic('getSecurityManager')
import DTML
from AccessControl import DTML
del DTML
......@@ -2301,7 +2301,7 @@ void initcAccessControl(void) {
/*| from logger_wrapper import warn
*/
IMPORT(module, "logger_wrapper");
IMPORT(module, "AccessControl.logger_wrapper");
GETATTR(module, warn);
Py_DECREF(module);
module = NULL;
......
......@@ -163,3 +163,14 @@ def f11():
x += 1
f11()
def f12():
assert all([True, True, True]) == True
assert all([True, False, True]) == False
f12()
def f13():
assert any([True, True, True]) == True
assert any([True, False, True]) == True
assert any([False, False, False]) == False
f13()
......@@ -31,6 +31,9 @@ from AccessControl.ZopeGuards \
get_iter, guarded_min, guarded_max, safe_builtins, guarded_enumerate, \
guarded_sum, guarded_apply, guarded_map, guarded_zip
if sys.version_info >= (2, 5):
from AccessControl.ZopeGuards import guarded_any, guarded_all
try:
__file__
except NameError:
......@@ -253,11 +256,26 @@ class TestBuiltinFunctionGuards(GuardTestCase):
[1,2,3], [3,2,1])
self.setSecurityManager(old)
if sys.version_info >= (2, 5):
def test_all_fails(self):
sm = SecurityManager(1) # rejects
old = self.setSecurityManager(sm)
self.assertRaises(Unauthorized, guarded_all, [True,True,False])
self.setSecurityManager(old)
def test_any_fails(self):
sm = SecurityManager(1) # rejects
old = self.setSecurityManager(sm)
self.assertRaises(Unauthorized, guarded_any, [True,True,False])
self.setSecurityManager(old)
def test_min_fails(self):
sm = SecurityManager(1) # rejects
old = self.setSecurityManager(sm)
self.assertRaises(Unauthorized, guarded_min, [1,2,3])
self.assertRaises(Unauthorized, guarded_min, 1,2,3)
self.assertRaises(Unauthorized, guarded_min,
[{'x':1},{'x':2}], operator.itemgetter('x'))
self.setSecurityManager(old)
def test_max_fails(self):
......@@ -265,6 +283,8 @@ class TestBuiltinFunctionGuards(GuardTestCase):
old = self.setSecurityManager(sm)
self.assertRaises(Unauthorized, guarded_max, [1,2,3])
self.assertRaises(Unauthorized, guarded_max, 1,2,3)
self.assertRaises(Unauthorized, guarded_max,
[{'x':1},{'x':2}], operator.itemgetter('x'))
self.setSecurityManager(old)
def test_enumerate_fails(self):
......@@ -295,11 +315,26 @@ class TestBuiltinFunctionGuards(GuardTestCase):
[4,4,4])
self.setSecurityManager(old)
if sys.version_info >= (2, 5):
def test_all_succeeds(self):
sm = SecurityManager() # accepts
old = self.setSecurityManager(sm)
self.assertEqual(guarded_all([True,True,False]), False)
self.setSecurityManager(old)
def test_any_succeeds(self):
sm = SecurityManager() # accepts
old = self.setSecurityManager(sm)
self.assertEquals(guarded_any([True,True,False]), True)
self.setSecurityManager(old)
def test_min_succeeds(self):
sm = SecurityManager() # accepts
old = self.setSecurityManager(sm)
self.assertEqual(guarded_min([1,2,3]), 1)
self.assertEqual(guarded_min(1,2,3), 1)
self.assertEqual(guarded_min({'x':1},{'x':2},
key=operator.itemgetter('x')), {'x':1})
self.setSecurityManager(old)
def test_max_succeeds(self):
......@@ -307,6 +342,8 @@ class TestBuiltinFunctionGuards(GuardTestCase):
old = self.setSecurityManager(sm)
self.assertEqual(guarded_max([1,2,3]), 3)
self.assertEqual(guarded_max(1,2,3), 3)
self.assertEqual(guarded_max({'x':1},{'x':2},
key=operator.itemgetter('x')), {'x':2})
self.setSecurityManager(old)
def test_enumerate_succeeds(self):
......
......@@ -103,6 +103,32 @@ CallMethodO(PyObject *self, PyObject *name,
#define Build Py_BuildValue
/* For obscure reasons, we need to use tp_richcompare instead of tp_compare.
* The comparisons here all most naturally compute a cmp()-like result.
* This little helper turns that into a bool result for rich comparisons.
*/
static PyObject *
diff_to_bool(int diff, int op)
{
PyObject *result;
int istrue;
switch (op) {
case Py_EQ: istrue = diff == 0; break;
case Py_NE: istrue = diff != 0; break;
case Py_LE: istrue = diff <= 0; break;
case Py_GE: istrue = diff >= 0; break;
case Py_LT: istrue = diff < 0; break;
case Py_GT: istrue = diff > 0; break;
default:
assert(! "op unknown");
istrue = 0; /* To shut up compiler */
}
result = istrue ? Py_True : Py_False;
Py_INCREF(result);
return result;
}
/* Declarations for objects of type Wrapper */
typedef struct {
......@@ -758,6 +784,13 @@ Wrapper_compare(Wrapper *self, PyObject *w)
return r;
}
static PyObject *
Wrapper_richcompare(Wrapper *self, PyObject *w, int op)
{
int diff = Wrapper_compare(self, w);
return diff_to_bool(diff, op);
}
static PyObject *
Wrapper_repr(Wrapper *self)
{
......@@ -1241,7 +1274,7 @@ static PyExtensionClass Wrappertype = {
(printfunc)0, /*tp_print*/
(getattrfunc)0, /*tp_getattr*/
(setattrfunc)0, /*tp_setattr*/
(cmpfunc)Wrapper_compare, /*tp_compare*/
(cmpfunc)0, /*tp_compare*/
(reprfunc)Wrapper_repr, /*tp_repr*/
&Wrapper_as_number, /*tp_as_number*/
&Wrapper_as_sequence, /*tp_as_sequence*/
......@@ -1259,7 +1292,7 @@ static PyExtensionClass Wrappertype = {
"Wrapper object for implicit acquisition", /* Documentation string */
/* tp_traverse */ (traverseproc)Wrapper_traverse,
/* tp_clear */ (inquiry)Wrapper_clear,
/* tp_richcompare */ (richcmpfunc)0,
/* tp_richcompare */ (richcmpfunc)Wrapper_richcompare,
/* tp_weaklistoffset */ (long)0,
/* tp_iter */ (getiterfunc)0,
/* tp_iternext */ (iternextfunc)0,
......@@ -1285,7 +1318,7 @@ static PyExtensionClass XaqWrappertype = {
(printfunc)0, /*tp_print*/
(getattrfunc)0, /*tp_getattr*/
(setattrfunc)0, /*tp_setattr*/
(cmpfunc)Wrapper_compare, /*tp_compare*/
(cmpfunc)0, /*tp_compare*/
(reprfunc)Wrapper_repr, /*tp_repr*/
&Wrapper_as_number, /*tp_as_number*/
&Wrapper_as_sequence, /*tp_as_sequence*/
......@@ -1303,7 +1336,7 @@ static PyExtensionClass XaqWrappertype = {
"Wrapper object for implicit acquisition", /* Documentation string */
/* tp_traverse */ (traverseproc)Wrapper_traverse,
/* tp_clear */ (inquiry)Wrapper_clear,
/* tp_richcompare */ (richcmpfunc)0,
/* tp_richcompare */ (richcmpfunc)Wrapper_richcompare,
/* tp_weaklistoffset */ (long)0,
/* tp_iter */ (getiterfunc)0,
/* tp_iternext */ (iternextfunc)0,
......
......@@ -14,9 +14,9 @@
$Id$"""
from DT_String import String, FileMixin
import DT_String, re
from DT_Util import ParseError, str
import re
from DocumentTemplate.DT_String import String, FileMixin
from DocumentTemplate.DT_Util import ParseError, str
class dtml_re_class:
""" This needs to be replaced before 2.4. It's a hackaround. """
......@@ -129,7 +129,7 @@ class dtml_re_class:
def start(self, *args):
return self._start
class HTML(DT_String.String):
class HTML(String):
"""HTML Document Templates
HTML Document templates use HTML server-side-include syntax,
......
......@@ -78,7 +78,7 @@ __doc__='''Conditional insertion
__rcs_id__='$Id$'
__version__='$Revision: 1.19 $'[11:-2]
from DT_Util import ParseError, parse_params, name_param, str
from DocumentTemplate.DT_Util import ParseError, parse_params, name_param, str
class If:
blockContinuations='else','elif'
......
......@@ -333,13 +333,17 @@ __rcs_id__='$Id$'
__version__='$Revision: 1.62 $'[11:-2]
import sys
from DT_Util import ParseError, parse_params, name_param, str, join_unicode
from DT_Util import render_blocks, InstanceDict, ValidationError, Eval
from DT_Util import simple_name, add_with_prefix
import re
from DT_InSV import sequence_variables, opt
TupleType=type(())
StringTypes = (type(''), type(u''))
from DocumentTemplate.DT_Util import ParseError, parse_params, name_param
from DocumentTemplate.DT_Util import str, join_unicode
from DocumentTemplate.DT_Util import render_blocks, InstanceDict
from DocumentTemplate.DT_Util import ValidationError, Eval
from DocumentTemplate.DT_Util import simple_name, add_with_prefix
from DocumentTemplate.DT_InSV import sequence_variables, opt
TupleType = tuple
StringTypes = (str, unicode)
class InFactory:
blockContinuations=('else',)
......
......@@ -18,12 +18,13 @@ __version__='$Revision: 1.22 $'[11:-2]
from math import sqrt
import re
TupleType=type(())
try:
import Missing
mv=Missing.Value
except: mv=None
TupleType = tuple
class sequence_variables:
......
......@@ -40,10 +40,11 @@
as desired.
'''
from DT_Util import render_blocks, Eval, ParseError
from DT_Util import str # Probably needed due to hysterical pickles.
import re
from DocumentTemplate.DT_Util import render_blocks, Eval, ParseError
from DocumentTemplate.DT_Util import str # Probably needed due to
# hysterical pickles.
class Let:
blockContinuations=()
......
......@@ -26,7 +26,11 @@
__rcs_id__='$Id$'
__version__='$Revision: 1.13 $'[11:-2]
from DT_Util import parse_params, name_param, render_blocks, str
from zExceptions import upgradeException
from DocumentTemplate.DT_Util import parse_params, name_param, render_blocks, str
class InvalidErrorTypeExpression(Exception):
pass
class Raise:
blockContinuations=()
......@@ -44,15 +48,17 @@ class Raise:
expr=self.expr
if expr is None:
t=self.__name__
if t[-5:]=='Error' and __builtins__.has_key(t):
t=__builtins__[t]
else:
try: t=expr.eval(md)
except: t='Invalid Error Type Expression'
except: t=InvalidErrorTypeExpression
try: v=render_blocks(self.section,md)
except: v='Invalid Error Value'
# String Exceptions are deprecated on Python 2.5 and
# plain won't work at all on Python 2.6. So try to upgrade it
# to a real exception.
t, v = upgradeException(t, v)
raise t, v
__call__=render
......@@ -12,7 +12,7 @@
##############################################################################
__version__='$Revision: 1.9 $'[11:-2]
from DT_Util import parse_params, name_param
from DocumentTemplate.DT_Util import parse_params, name_param
class ReturnTag:
name='return'
......
......@@ -16,9 +16,10 @@ import os
import thread
import re
from DT_Util import ParseError, InstanceDict, TemplateDict, render_blocks, str
from DT_Var import Var, Call, Comment
from DT_Return import ReturnTag, DTReturn
from DocumentTemplate.DT_Util import ParseError, InstanceDict
from DocumentTemplate.DT_Util import TemplateDict, render_blocks, str
from DocumentTemplate.DT_Var import Var, Call, Comment
from DocumentTemplate.DT_Return import ReturnTag, DTReturn
_marker = [] # Create a new marker object.
......
......@@ -13,9 +13,9 @@
import sys, traceback
from cStringIO import StringIO
from DT_Util import ParseError, parse_params, render_blocks
from DT_Util import namespace, InstanceDict
from DT_Return import DTReturn
from DocumentTemplate.DT_Util import ParseError, parse_params, render_blocks
from DocumentTemplate.DT_Util import namespace, InstanceDict
from DocumentTemplate.DT_Return import DTReturn
class Try:
"""Zope DTML Exception handling
......
......@@ -15,7 +15,7 @@ __doc__='''Machinery to support through-the-web editing
$Id$'''
__version__='$Revision: 1.15 $'[11:-2]
from DT_HTML import HTML
from DocumentTemplate.DT_HTML import HTML
FactoryDefaultString="Factory Default"
......
......@@ -16,12 +16,16 @@ $Id$"""
import re
from html_quote import html_quote, ustr # for import by other modules, dont remove!
# for import by other modules, dont remove!
from DocumentTemplate.html_quote import html_quote, ustr
from DocumentTemplate.cDocumentTemplate import InstanceDict, TemplateDict
from DocumentTemplate.cDocumentTemplate import render_blocks, safe_callable
from DocumentTemplate.cDocumentTemplate import join_unicode
from RestrictedPython.Guards import safe_builtins
from RestrictedPython.Utilities import utility_builtins
from RestrictedPython.Eval import RestrictionCapableEval
from cDocumentTemplate import InstanceDict, TemplateDict, \
render_blocks, safe_callable, join_unicode
test = utility_builtins['test'] # for backwards compatibility, dont remove!
......@@ -29,7 +33,9 @@ LIMITED_BUILTINS = 1
str=__builtins__['str'] # Waaaaa, waaaaaaaa needed for pickling waaaaa
ParseError='Document Template Parse Error'
class ParseError(Exception):
"""Document Template Parse Error"""
from zExceptions import Unauthorized as ValidationError
def int_param(params,md,name,default=0, st=type('')):
......@@ -235,37 +241,37 @@ def name_param(params,tag='',expr=0, attr='name', default_unnamed=1):
if v[:1]=='"' and v[-1:]=='"' and len(v) > 1: # expr shorthand
if used(attr):
raise ParseError, ('%s and expr given' % attr, tag)
raise ParseError('%s and expr given' % attr, tag)
if expr:
if used('expr'):
raise ParseError, ('two exprs given', tag)
raise ParseError('two exprs given', tag)
v=v[1:-1]
try: expr=Eval(v)
except SyntaxError, v:
raise ParseError, (
raise ParseError(
'<strong>Expression (Python) Syntax error</strong>:'
'\n<pre>\n%s\n</pre>\n' % v[0],
tag)
return v, expr
else: raise ParseError, (
else: raise ParseError(
'The "..." shorthand for expr was used in a tag '
'that doesn\'t support expr attributes.',
tag)
else: # name shorthand
if used(attr):
raise ParseError, ('Two %s values were given' % attr, tag)
raise ParseError('Two %s values were given' % attr, tag)
if expr:
if used('expr'):
# raise 'Waaaaaa', 'waaa'
raise ParseError, ('%s and expr given' % attr, tag)
raise ParseError('%s and expr given' % attr, tag)
return params[''],None
return params['']
elif used(attr):
if expr:
if used('expr'):
raise ParseError, ('%s and expr given' % attr, tag)
raise ParseError('%s and expr given' % attr, tag)
return params[attr],None
return params[attr]
elif expr and used('expr'):
......@@ -273,7 +279,7 @@ def name_param(params,tag='',expr=0, attr='name', default_unnamed=1):
expr=Eval(name)
return name, expr
raise ParseError, ('No %s given' % attr, tag)
raise ParseError('No %s given' % attr, tag)
Expr_doc="""
......@@ -386,11 +392,11 @@ def parse_params(text,
l=len(mo_unp.group(1))
if result:
if parms.has_key(name):
if parms[name] is None: raise ParseError, (
if parms[name] is None: raise ParseError(
'Attribute %s requires a value' % name, tag)
result[name]=parms[name]
else: raise ParseError, (
else: raise ParseError(
'Invalid attribute name, "%s"' % name, tag)
else:
result['']=name
......@@ -398,22 +404,22 @@ def parse_params(text,
elif mo_unq:
name=mo_unq.group(2)
l=len(mo_unq.group(1))
if result: raise ParseError, (
if result: raise ParseError(
'Invalid attribute name, "%s"' % name, tag)
else: result['']=name
return parse_params(text[l:],result,**parms)
else:
if not text or not text.strip(): return result
raise ParseError, ('invalid parameter: "%s"' % text, tag)
raise ParseError('invalid parameter: "%s"' % text, tag)
if not parms.has_key(name):
raise ParseError, (
raise ParseError(
'Invalid attribute name, "%s"' % name, tag)
if result.has_key(name):
p=parms[name]
if type(p) is not ListType or p:
raise ParseError, (
raise ParseError(
'Duplicate values for attribute "%s"' % name, tag)
result[name]=value
......
......@@ -151,14 +151,18 @@ Evaluating expressions without rendering results
''' # '
__rcs_id__='$Id$'
__version__='$Revision: 1.60 $'[11:-2]
import string, re, sys
from cgi import escape
import string, re, sys
from urllib import quote, quote_plus, unquote, unquote_plus
from DT_Util import parse_params, name_param, str, ustr
from html_quote import html_quote # for import by other modules, dont remove!
# for import by other modules, dont remove!
from DocumentTemplate.html_quote import html_quote
from DocumentTemplate.DT_Util import parse_params, name_param, str, ustr
from Acquisition import aq_base
from ZPublisher.TaintedString import TaintedString
from zope.structuredtext.html import HTMLWithImages, HTML
......
......@@ -36,8 +36,10 @@
__rcs_id__='$Id$'
__version__='$Revision: 1.15 $'[11:-2]
from DT_Util import parse_params, name_param, InstanceDict, render_blocks, str
from DT_Util import TemplateDict
from DocumentTemplate.DT_Util import parse_params, name_param
from DocumentTemplate.DT_Util import InstanceDict, render_blocks, str
from DocumentTemplate.DT_Util import TemplateDict
class With:
blockContinuations=()
name='with'
......
# alias module for backwards compatibility
from DT_Util import Eval
from DocumentTemplate.DT_Util import Eval
def careful_mul(env, *factors):
r = 1
......
......@@ -107,8 +107,8 @@ Document Templates may be created 4 ways:
__version__='$Revision: 1.14 $'[11:-2]
ParseError='Document Template Parse Error'
from DocumentTemplate.DT_Raise import ParseError
from DocumentTemplate.DT_String import String, File
from DocumentTemplate.DT_HTML import HTML, HTMLFile, HTMLDefault
from DT_String import String, File
from DT_HTML import HTML, HTMLFile, HTMLDefault
# import DT_UI # Install HTML editing
......@@ -18,4 +18,5 @@ segregated in a separate package.
$Id$'''
__version__='$Revision: 1.18 $'[11:-2]
from DocumentTemplate import String, File, HTML, HTMLDefault, HTMLFile
from DocumentTemplate.DT_String import String, File
from DocumentTemplate.DT_HTML import HTML, HTMLDefault, HTMLFile
......@@ -972,7 +972,7 @@ initcDocumentTemplate(void)
DictInstanceType.ob_type=&PyType_Type;
UNLESS (html_quote = PyImport_ImportModule("html_quote")) return;
UNLESS (html_quote = PyImport_ImportModule("DocumentTemplate.html_quote")) return;
ASSIGN(ustr, PyObject_GetAttrString(html_quote, "ustr"));
UNLESS (ustr) return;
ASSIGN(html_quote, PyObject_GetAttrString(html_quote, "html_quote"));
......
# split off into its own module for aliasing without circrefs
from cgi import escape
from ustr import ustr
from DocumentTemplate.ustr import ustr
def html_quote(v, name='(Unknown name)', md={}):
return escape(ustr(v), 1)
......@@ -20,7 +20,7 @@ __version__='$Revision: 1.42 $'[11:-2]
import sys, types
from types import StringType, UnicodeType, TupleType
from ustr import ustr
from DocumentTemplate.ustr import ustr
import warnings
warnings.warn('pDocumentTemplate is not longer in active use. '
......
......@@ -48,7 +48,7 @@ from OFS.interfaces import ICopyContainer
from OFS.interfaces import ICopySource
CopyError='Copy Error'
class CopyError(Exception): pass
copy_re = re.compile('^copy([0-9]*)_of_(.*)')
......
......@@ -36,7 +36,7 @@ from DocumentTemplate.html_quote import html_quote
from DocumentTemplate.ustr import ustr
from ExtensionClass import Base
from webdav.Resource import Resource
from zExceptions import Redirect
from zExceptions import Redirect, upgradeException
from zExceptions.ExceptionFormatter import format_exception
from zope.interface import implements
......@@ -181,16 +181,24 @@ class Item(Base, Resource, CopySource, App.Management.Tabs, Traversable,
elif type(tb) is type('') and not error_tb:
error_tb = tb
# turn error_type into a string
if hasattr(error_type, '__name__'):
error_type=error_type.__name__
# warn if error_type is a string
error_name = 'Unknown'
if isinstance(error_type, basestring):
# String Exceptions are deprecated on Python 2.5 and
# plain won't work at all on Python 2.6. So try to upgrade it
# to a real exception.
error_name = error_type
error_type, error_value = upgradeException(error_type, error_value)
else:
if hasattr(error_type, '__name__'):
error_name = error_type.__name__
if hasattr(self, '_v_eek'):
# Stop if there is recursion.
raise error_type, error_value, tb
self._v_eek=1
if str(error_type).lower() in ('redirect',):
if error_name.lower() in ('redirect',):
raise error_type, error_value, tb
if not error_message:
......@@ -216,7 +224,10 @@ class Item(Base, Resource, CopySource, App.Management.Tabs, Traversable,
else:
client = aq_parent(client)
s=getattr(client, 'standard_error_message')
kwargs = {'error_type': error_type,
# For backward compatibility, we pass 'error_name' as
# 'error_type' here as historically this has always
# been a string.
kwargs = {'error_type': error_name,
'error_value': error_value,
'error_tb': error_tb,
'error_traceback': error_tb,
......
......@@ -347,7 +347,7 @@ class TestCopySupportSecurity( CopySupportTestBase ):
if ce_regex is not None:
pattern = re.compile( ce_regex, re.DOTALL )
if pattern.search( e ) is None:
if pattern.search( e.args[0] ) is None:
self.fail( "Paste failed; didn't match pattern:\n%s" % e )
else:
......
......@@ -18,6 +18,8 @@ Mostly just copy and paste from zope.testbrowser.testing.
$Id$
"""
import sys
import socket
import urllib2
import mechanize
......@@ -29,7 +31,7 @@ import zope.publisher.http
class PublisherConnection(testing.PublisherConnection):
def __init__(self, host):
def __init__(self, host, timeout=None):
from Testing.ZopeTestCase.zopedoctest.functional import http
self.caller = http
self.host = host
......@@ -76,6 +78,10 @@ class PublisherHTTPHandler(urllib2.HTTPHandler):
def http_open(self, req):
"""Open an HTTP connection having a ``urllib2`` request."""
# Here we connect to the publisher.
if sys.version_info > (2, 6) and not hasattr(req, 'timeout'):
# Workaround mechanize incompatibility with Python
# 2.6. See: LP #280334
req.timeout = socket._GLOBAL_DEFAULT_TIMEOUT
return self.do_open(PublisherConnection, req)
......
......@@ -10,7 +10,7 @@
# FOR A PARTICULAR PURPOSE
#
##############################################################################
import os, unittest, warnings
import os, sys, unittest, warnings
from Products.PythonScripts.PythonScript import PythonScript
from AccessControl.SecurityManagement import newSecurityManager
......@@ -297,13 +297,19 @@ class TestPythonScriptGlobals(PythonScriptTestBase, WarningInterceptor):
f = self._filePS('class.__name__')
self.assertEqual(f(), ("'foo'>", "'string'"))
def test_filepath(self):
# This test is meant to raise a deprecation warning.
# It used to fail mysteriously instead.
self._trap_warning_output()
f = self._filePS('filepath')
self.assertEqual(f(), [0])
self._free_warning_output()
if sys.version_info < (2, 6):
def test_filepath(self):
# This test is meant to raise a deprecation warning.
# It used to fail mysteriously instead.
self._trap_warning_output()
f = self._filePS('filepath')
self.assertEqual(f(), [0])
self._free_warning_output()
else:
def test_filepath(self):
# On Python 2.6, this now raises a TypeError.
f = self._filePS('filepath')
self.assertRaises(TypeError, f)
class PythonScriptInterfaceConformanceTests(unittest.TestCase):
......
......@@ -61,9 +61,10 @@ __version__='$Revision: 1.15 $'[11:-2]
from DocumentTemplate.DT_Util import ParseError, parse_params, name_param
from string import find, split, join, atoi, atof
StringType=type('')
str=__builtins__['str']
StringType = str
str = __builtins__['str']
class SQLVar:
name='sqlvar'
......@@ -78,10 +79,10 @@ class SQLVar:
self.args=args
if not args.has_key('type'):
raise ParseError, ('the type attribute is required', 'dtvar')
raise ParseError('the type attribute is required', 'dtvar')
t=args['type']
if not valid_type(t):
raise ParseError, ('invalid type, %s' % t, 'dtvar')
raise ParseError('invalid type, %s' % t, 'dtvar')
def render(self, md):
name=self.__name__
......
......@@ -217,7 +217,7 @@ class HTTPResponse(BaseResponse):
# It has already been determined.
return
if (isinstance(status, types.ClassType)
if (isinstance(status, (type, types.ClassType))
and issubclass(status, Exception)):
status = status.__name__
......
......@@ -29,7 +29,8 @@ class Tracer:
exception = exceptions[0]
exceptions.remove(exception)
exceptionShortName = exception.__name__ # KISS
self.append('raising %s from %s' % (exceptionShortName, context))
exceptionShortName = exceptionShortName.split("'")[0]
self.append('raising %s from %s' % (exceptionShortName, context))
raise exception
......
......@@ -45,7 +45,8 @@ from HTTPResponse import make_response
from ZPublisher.HTTPRequest import HTTPRequest
from App.config import getConfiguration
from medusa.http_server import http_server,get_header, http_channel, VERSION_STRING
from medusa.http_server import http_server, get_header
from medusa.http_server import fifo, http_channel, VERSION_STRING
import asyncore
from medusa import counter, producers
from medusa.test import max_sockets
......@@ -334,6 +335,18 @@ class zhttp_channel(http_channel):
def __init__(self, server, conn, addr):
http_channel.__init__(self, server, conn, addr)
if isinstance(self.producer_fifo, fifo):
self.producer_fifo_push = self.producer_fifo.push
self.producer_fifo_first = self.producer_fifo.first
self.producer_fifo_pop = self.producer_fifo.pop
else:
self.producer_fifo_push = self.producer_fifo.append
def first():
return self.producer_fifo[0]
self.producer_fifo_first = first
def pop():
del self.producer_fifo[0]
self.producer_fifo_pop = pop
requestCloseOnExec(conn)
self.queue=[]
self.working=0
......@@ -345,7 +358,7 @@ class zhttp_channel(http_channel):
# producers by default
if self.closed:
return
self.producer_fifo.push(producer)
self.producer_fifo_push(producer)
if send: self.initiate_send()
push_with_producer=push
......@@ -381,10 +394,10 @@ class zhttp_channel(http_channel):
self.current_request.channel = None # break circ refs
self.current_request=None
while self.producer_fifo:
p=self.producer_fifo.first()
p=self.producer_fifo_first()
if p is not None and not isinstance(p, basestring):
p.more() # free up resources held by producer
self.producer_fifo.pop()
self.producer_fifo_pop()
dispatcher.close(self)
def done(self):
......
......@@ -528,25 +528,25 @@ class http_channel (asynchat.async_chat):
# no handlers, so complain
r.error (404)
def writable (self):
# this is just the normal async_chat 'writable', here for comparison
return self.ac_out_buffer or len(self.producer_fifo)
def writable_for_proxy (self):
# this version of writable supports the idea of a 'stalled' producer
# [i.e., it's not ready to produce any output yet] This is needed by
# the proxy, which will be waiting for the magic combination of
# 1) hostname resolved
# 2) connection made
# 3) data available.
if self.ac_out_buffer:
return 1
elif len(self.producer_fifo):
p = self.producer_fifo.first()
if hasattr (p, 'stalled'):
return not p.stalled()
else:
return 1
#def writable (self):
# # this is just the normal async_chat 'writable', here for comparison
# return self.ac_out_buffer or len(self.producer_fifo)
#def writable_for_proxy (self):
# # this version of writable supports the idea of a 'stalled' producer
# # [i.e., it's not ready to produce any output yet] This is needed by
# # the proxy, which will be waiting for the magic combination of
# # 1) hostname resolved
# # 2) connection made
# # 3) data available.
# if self.ac_out_buffer:
# return 1
# elif len(self.producer_fifo):
# p = self.producer_fifo.first()
# if hasattr (p, 'stalled'):
# return not p.stalled()
# else:
# return 1
# ===========================================================================
# HTTP Server Object
......
......@@ -207,8 +207,9 @@ class ZPublisherExceptionHook:
else:
error_log_url = log.raising((t, v, traceback))
if (getattr(REQUEST.get('RESPONSE', None), '_error_format', '')
!='text/html'):
if (REQUEST is None or
(getattr(REQUEST.get('RESPONSE', None), '_error_format', '')
!= 'text/html')):
raise t, v, traceback
# Lookup a view for the exception and render it, then
......
......@@ -118,12 +118,20 @@ class ExceptionHookTest(ExceptionHookTestCase):
def testStringException1(self):
def f():
raise 'unauthorized', 'x'
self.assertRaises('unauthorized', self.call, None, None, f)
if sys.version_info < (2, 6):
self.assertRaises('unauthorized', self.call, None, None, f)
else:
# Raising a string exception causes a TypeError on Python 2.6
self.assertRaises(TypeError, self.call, None, None, f)
def testStringException2(self):
def f():
raise 'redirect', 'x'
self.assertRaises('redirect', self.call, None, None, f)
if sys.version_info < (2, 6):
self.assertRaises('redirect', self.call, None, None, f)
else:
# Raising a string exception causes a TypeError on Python 2.6
self.assertRaises(TypeError, self.call, None, None, f)
def testSystemExit(self):
def f():
......
......@@ -18,12 +18,13 @@ application-specific packages.
$Id$
"""
from unauthorized import Unauthorized
import warnings
from zope.interface import implements
from zope.interface.common.interfaces import IException
from zope.publisher.interfaces import INotFound
from zope.security.interfaces import IForbidden
from zExceptions.unauthorized import Unauthorized
class BadRequest(Exception):
implements(IException)
......@@ -42,3 +43,29 @@ class MethodNotAllowed(Exception):
class Redirect(Exception):
pass
def upgradeException(t, v):
# If a string exception is found, convert it to an equivalent
# exception defined either in builtins or zExceptions. If none of
# that works, tehn convert it to an InternalError and keep the
# original exception name as part of the exception value.
import zExceptions
if not isinstance(t, basestring):
return t, v
warnings.warn('String exceptions are deprecated starting '
'with Python 2.5 and will be removed in a '
'future release', DeprecationWarning, stacklevel=2)
n = None
if __builtins__.has_key(t):
n = __builtins__[t]
elif hasattr(zExceptions, t):
n = getattr(zExceptions, t)
if n is not None and issubclass(n, Exception):
t = n
else:
v = t, v
t = InternalError
return t, v
......@@ -167,10 +167,10 @@ def get_inituser():
def write_inituser(fn, user, password):
import binascii
import sha
import hashlib
fp = open(fn, "w")
pw = binascii.b2a_base64(sha.new(password).digest())[:-1]
fp.write('%s:{SHA}%s\n' % (user, pw))
pw = binascii.b2a_base64(hashlib.sha256(password).digest())[:-1]
fp.write('%s:{SHA256}%s\n' % (user, pw))
fp.close()
os.chmod(fn, 0644)
......
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