Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
hannosch committed Jul 10, 2010
1 parent 6cb8dc3 commit 8fb45e6
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 135 deletions.
53 changes: 0 additions & 53 deletions src/Products/ExternalMethod/CHANGES.txt

This file was deleted.

80 changes: 39 additions & 41 deletions src/Products/ExternalMethod/ExternalMethod.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,10 @@
This product provides support for external methods, which allow
domain-specific customization of web environments.
"""
__version__='$Revision: 1.52 $'[11:-2]

import os
import stat
import sys
import traceback

from AccessControl.class_init import InitializeClass
from AccessControl.Permissions import change_external_methods
Expand All @@ -29,21 +27,19 @@
from AccessControl.SecurityInfo import ClassSecurityInfo
from Acquisition import Acquired
from Acquisition import Explicit
from App.Dialogs import MessageDialog
from App.Extensions import getObject
from App.Extensions import getPath
from App.Extensions import FuncCode
from App.special_dtml import DTMLFile
from App.special_dtml import HTML
from OFS.role import RoleManager
from OFS.SimpleItem import Item
from OFS.SimpleItem import pretty_tb
from Persistence import Persistent
from App.Management import Navigation
from ComputedAttribute import ComputedAttribute

manage_addExternalMethodForm=DTMLFile('dtml/methodAdd', globals())


def manage_addExternalMethod(self, id, title, module, function, REQUEST=None):
"""Add an external method to a folder
Expand All @@ -64,22 +60,23 @@ def manage_addExternalMethod(self, id, title, module, function, REQUEST=None):
However, the file name may have a prefix of
'product.', indicating that it should be found in a product
directory.
For example, if the module is: 'ACMEWidgets.foo', then an
attempt will first be made to use the file
'lib/python/Products/ACMEWidgets/Extensions/foo.py'. If this
failes, then the file 'Extensions/ACMEWidgets.foo.py' will be
used.
"""
id=str(id)
title=str(title)
module=str(module)
function=str(function)
id = str(id)
title = str(title)
module = str(module)
function = str(function)

i=ExternalMethod(id,title,module,function)
self._setObject(id,i)
i = ExternalMethod(id, title, module, function)
self._setObject(id, i)
if REQUEST is not None:
return self.manage_main(self,REQUEST)
return self.manage_main(self, REQUEST)


class ExternalMethod(Item, Persistent, Explicit,
RoleManager, Navigation):
Expand Down Expand Up @@ -108,17 +105,16 @@ class ExternalMethod(Item, Persistent, Explicit,
func_defaults = ComputedAttribute(lambda self: self.getFuncDefaults())
func_code = ComputedAttribute(lambda self: self.getFuncCode())


ZopeTime = Acquired
HelpSys = Acquired
manage_page_header = Acquired

manage_options=(
(
{'label':'Properties', 'action':'manage_main',
'help':('ExternalMethod','External-Method_Properties.stx')},
{'label':'Test', 'action':'',
'help':('ExternalMethod','External-Method_Try-It.stx')},
{'label': 'Properties', 'action': 'manage_main',
'help': ('ExternalMethod', 'External-Method_Properties.stx')},
{'label': 'Test', 'action': '',
'help': ('ExternalMethod', 'External-Method_Try-It.stx')},
)
+ Item.manage_options
+ RoleManager.manage_options
Expand Down Expand Up @@ -155,18 +151,18 @@ def manage_edit(self, title, module, function, REQUEST=None):
self.getFunction(1)
if REQUEST:
message="External Method Uploaded."
return self.manage_main(self,REQUEST,manage_tabs_message=message)
return self.manage_main(self, REQUEST, manage_tabs_message=message)

def getFunction(self, reload=0):
f = getObject(self._module, self._function, reload)
if hasattr(f, 'im_func'):
ff = f.im_func
else:
ff = f

f=getObject(self._module, self._function, reload)
if hasattr(f,'im_func'): ff=f.im_func
else: ff=f

self._v_func_defaults = ff.func_defaults
self._v_func_code = FuncCode(ff,f is not ff)

self._v_f=f
self._v_func_defaults = ff.func_defaults
self._v_func_code = FuncCode(ff, f is not ff)
self._v_f = f

return f

Expand Down Expand Up @@ -217,45 +213,47 @@ def __call__(self, *args, **kw):

filePath = self.filepath()
if filePath==None:
raise RuntimeError,\
"external method could not be called " \
"because it is None"
raise RuntimeError("external method could not be called "
"because it is None")

if not os.path.exists(filePath):
raise RuntimeError,\
"external method could not be called " \
"because the file does not exist"
raise RuntimeError("external method could not be called "
"because the file does not exist")

if Globals.DevelopmentMode:
self.reloadIfChanged()

if hasattr(self, '_v_f'):
f=self._v_f
f = self._v_f
else:
f=self.getFunction()
f = self.getFunction()

__traceback_info__=args, kw, self._v_func_defaults

try: return f(*args, **kw)
try:
return f(*args, **kw)
except TypeError, v:
tb=sys.exc_info()[2]
tb = sys.exc_info()[2]
try:
if ((self._v_func_code.co_argcount-
len(self._v_func_defaults or ()) - 1 == len(args))
and self._v_func_code.co_varnames[0]=='self'):
return f(self.aq_parent.this(), *args, **kw)

raise TypeError, v, tb
finally: tb=None
finally:
tb = None

def function(self):
return self._function

def function(self): return self._function
def module(self): return self._module
def module(self):
return self._module

def filepath(self):
if not hasattr(self, '_v_filepath'):
self._v_filepath=getPath('Extensions', self._module,
suffixes=('','py','pyc','pyp'))
suffixes=('', 'py', 'pyc', 'pyp'))
return self._v_filepath

InitializeClass(ExternalMethod)
6 changes: 0 additions & 6 deletions src/Products/ExternalMethod/README.txt

This file was deleted.

7 changes: 1 addition & 6 deletions src/Products/ExternalMethod/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,11 @@
# FOR A PARTICULAR PURPOSE
#
##############################################################################
__doc__='''External Method Product Initialization
$Id$'''
__version__='$Revision: 1.15 $'[11:-2]

import ExternalMethod

# This is the new way to initialize products. It is hoped
# that this more direct mechanism will be more understandable.
def initialize(context):

def initialize(context):
context.registerClass(
ExternalMethod.ExternalMethod,
constructors=(ExternalMethod.manage_addExternalMethodForm,
Expand Down
3 changes: 2 additions & 1 deletion src/Products/ExternalMethod/tests/Extensions/Test.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from math import sqrt

def testf(arg1, sqrt = sqrt):

def testf(arg1, sqrt=sqrt):
return sqrt(arg1)
4 changes: 0 additions & 4 deletions src/Products/ExternalMethod/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,3 @@
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""
$Id$
"""
38 changes: 15 additions & 23 deletions src/Products/ExternalMethod/tests/testExternalMethod.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,30 @@
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""
Revision information:
$Id$
"""

import math
import os
import sys
import unittest

import ZODB # dead goat
import Products.ExternalMethod.tests
from Products.ExternalMethod.ExternalMethod import ExternalMethod
import App.config


def package_home(globals_dict):
__name__ = globals_dict['__name__']
m = sys.modules[__name__]
if hasattr(m, '__path__'):
r = m.__path__[0]
elif "." in __name__:
r = sys.modules[__name__.split('.', 1)[0]].__path__[0]
else:
r = __name__
return os.path.abspath(r)


class TestExternalMethod(unittest.TestCase):

def setUp(self):
Expand All @@ -45,7 +54,7 @@ def testStorage(self):
em2 = ExternalMethod.__basicnew__()
em2.__setstate__(state)
self.assertEqual(em2(9), math.sqrt(9))
self.failIf(state.has_key('func_defaults'))
self.failIf('func_defaults' in state)

def test_mapply(self):
from ZPublisher.mapply import mapply
Expand All @@ -58,22 +67,5 @@ def test_mapply(self):
self.assertEqual(mapply(em1, (), {'arg1': 9}), math.sqrt(9))



def test_suite():
return unittest.makeSuite(TestExternalMethod)


def package_home(globals_dict):
__name__=globals_dict['__name__']
m=sys.modules[__name__]
if hasattr(m,'__path__'):
r=m.__path__[0]
elif "." in __name__:
r=sys.modules[__name__.split('.',1)[0]].__path__[0]
else:
r=__name__
return os.path.abspath(r)


if __name__=='__main__':
unittest.main(defaultTest='test_suite')
1 change: 0 additions & 1 deletion src/Products/ExternalMethod/version.txt

This file was deleted.

0 comments on commit 8fb45e6

Please sign in to comment.