Commit c67fa730 authored by Jim Fulton's avatar Jim Fulton

initial

parent a84477cc
from ExtensionClass import *
class foo(Base):
def __add__(self,other): print 'add called'
foo()+foo()
from ExtensionClass import Base
from MethodObject import Method
class foo(Method):
def __call__(self,ob,*args,**kw): print 'called', ob, args, kw
class bar(Base):
hi=foo()
x=bar()
hi=x.hi
print hi
hi(1,2,3,name='spam')
from ExtensionClass import Base
import Acquisition
class B(Base):
color='red'
class A(Acquisition.Explicit):
def hi(self): print self, self.acquire('color')
b=B()
b.a=A()
b.a.hi()
b.a.color='green'
b.a.hi()
try:
A().hi()
raise 'Program error', 'spam'
except AttributeError: pass
#! /usr/bin/env python
"""Test function attributes
Jim Fulton
"""
verbose=1
from ExtensionClass import Base
def f(a): return a*a
class C(Base):
def m(self, a): return a*a
m.spam='eggs'
i=C()
if verbose: print 'Trying function wo attributes'
if f(2) != 4: print 'failed'
if verbose: print 'Trying method wo attributes'
if i.m(2) != 4: print 'failed'
if verbose: print 'Trying setting function attribute'
f.spam='eggs'
if verbose: print 'Trying function w attributes'
if f(2) != 4: print 'failed'
if verbose: print 'Trying method w attributes'
if i.m(2) != 4: print 'failed'
if verbose: print 'Trying method getattr'
try:
if i.m.spam != 'eggs': print 'failed'
except AttributeError: print 'failed'
try:
i.m.foo
print 'failed'
except AttributeError: pass
if verbose: print 'Trying setting built-in function attribute'
max.color='red'
if max.color != 'red': print 'failed'
if max(1,2) != 2: print 'failed'
if verbose: print 'Trying setting built-in method attribute'
import sys
try:
sys.stdout.write.color='green'
print 'failed'
except TypeError: pass
import ExtensionClass
class C(ExtensionClass.Base):
def __call_method__(self,meth,args,kw={}):
print 'give us a hook, hook, hook...'
apply(meth,args,kw)
def hi(self,*args,**kw): print self, args, kw
c=C()
c.hi()
c.hi(1,2,3)
c.hi(1,2,spam='eggs')
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