def testDynamic(self):
     roll = GenericFunction(lambda vehicle:None)
     class Tricycle(HumanPowered,LandVehicle): pass
     roll[Signature(vehicle=Wheeled)] = lambda ob: "We're rolling"
     self.assertRaises(NoApplicableMethods, roll, Tricycle())
     declareImplementation(Tricycle,[Wheeled])
     self.assertEqual(roll(Tricycle()),"We're rolling")
    def testDynamic(self):
        roll = GenericFunction(lambda vehicle: None)

        class Tricycle(HumanPowered, LandVehicle):
            pass

        roll[Signature(vehicle=Wheeled)] = lambda ob: "We're rolling"
        self.assertRaises(NoApplicableMethods, roll, Tricycle())
        declareImplementation(Tricycle, [Wheeled])
        self.assertEqual(roll(Tricycle()), "We're rolling")
Ejemplo n.º 3
0
def register():
	for classObject, interfaceList in baseTypeImplements:
		declareImplementation(
			classObject,
			interfaceList,
		)
Ejemplo n.º 4
0
from protocols import protocolForType, protocolForURI, sequenceOf, advise
from protocols import declareImplementation, Variation
from UserDict import UserDict

IGetSetMapping = protocolForType(dict, ["__getitem__", "__setitem__"])
IGetMapping = protocolForType(dict, ["__getitem__"])

ISimpleReadFile = protocolForType(file, ["read"])
IImplicitRead = protocolForType(file, ["read"], implicit=True)

IProtocol1 = protocolForURI("http://peak.telecommunity.com/PyProtocols")

multimap = sequenceOf(IGetMapping)

declareImplementation(UserDict, [IGetSetMapping])

IMyUnusualMapping = Variation(IGetSetMapping)


class MyUserMapping(object):
    pass


declareImplementation(MyUserMapping, [IMyUnusualMapping])


class GenerationTests(TestCase):
    def checkTypeSubset(self):
        d = {}
        assert IGetSetMapping(d, None) is d
Ejemplo n.º 5
0
def register():
    for classObject, interfaceList in baseTypeImplements:
        declareImplementation(
            classObject,
            interfaceList,
        )
Ejemplo n.º 6
0
        self.Bind(wx.EVT_PAINT, self.on_paint)

class IDrawable(protocols.Interface):
    def draw(dc):
        pass

class IDrawingContext(protocols.Interface):
    def DrawText(text, x, y): pass
    def DrawBitmap(bmp, x, y): pass
    def DrawRoundedRectangleRect(rect, radius): pass

def wxPaintEventDrawingContextAdapter(event):
    if event.EventType == wx.EVT_PAINT:
        return wx.AutoBufferedPaintDC(event.GetEventObject())

protocols.declareImplementation(wx.DC, instancesProvide=[IDrawingContext])
protocols.declareAdapterForType(IDrawingContext, wxPaintEventDrawingContextAdapter, wx.Event)

class IRectagleFactory(protocols.Interface):
    def get_rect(x,y,w,h):
        pass

class wxRectangleFactory(protocols.Adapter):
    protocols.advise(instancesProvide=[IRectagleFactory],
                     asAdapterForTypes=[wx.DC])
    @staticmethod
    def get_rect(x,y,w,h):
        return wx.Rect(x,y,w,h)

class ServiceProviderGUIMetaIconUser(object):
    icon_cache = {}
Ejemplo n.º 7
0
from protocols import protocolForType, protocolForURI, sequenceOf, advise
from protocols import declareImplementation, Variation
from UserDict import UserDict

IGetSetMapping = protocolForType(dict, ['__getitem__', '__setitem__'])
IGetMapping = protocolForType(dict, ['__getitem__'])

ISimpleReadFile = protocolForType(file, ['read'])
IImplicitRead = protocolForType(file, ['read'], implicit=True)

IProtocol1 = protocolForURI("http://peak.telecommunity.com/PyProtocols")

multimap = sequenceOf(IGetMapping)

declareImplementation(UserDict, [IGetSetMapping])

IMyUnusualMapping = Variation(IGetSetMapping)


class MyUserMapping(object):
    pass


declareImplementation(MyUserMapping, [IMyUnusualMapping])


class GenerationTests(TestCase):
    def checkTypeSubset(self):
        d = {}
        assert IGetSetMapping(d, None) is d