Пример #1
0
    def eat(self):
        return "munch"

    def sleep(self):
        return "zzz"


class Dog(object):
    def wag(self):
        return "tail"

    def eat(self):
        return "slobber"


has_role(Dog, Bark, Animal)


class Doberman(Dog):
    pass


class DobermanPinscher(Doberman):
    pass


class NoRoles(object):
    pass


class NoRolesChild(NoRoles):
Пример #2
0
    def baz(self):
        return "rFoo::baz"

class rBar(Role):
    def bar(self): 
        return 'rBar::bar'
    def baz(self):
        return 'rBar::baz'


class FooBarWithConflict(object):
    pass

foobarwithconflict_conflicts = 0
try:
    has_role(FooBarWithConflict, rFoo, rBar)
except RoleConflictDetected:
    foobarwithconflict_conflicts = 1

assert foobarwithconflict_conflicts


class FooBarWithOutConflict(object):
    def baz(self):
        return "FooBar::With::Out::Conflict::baz"

foobarwithoutconflict_resolved = 1
try:
    has_role(FooBarWithOutConflict, rFoo, rBar)
except RoleConflictDetected:
    foobarwithoutconflict_resolved = 1
Пример #3
0
        return "woof"

class Animal(Role):
    def eat(self):
        return "munch"
    def sleep(self):
        return "zzz"


class Dog(object):
    def wag(self):
        return "tail"
    def eat(self):
        return "slobber"

has_role(Dog, Bark, Animal)

class Doberman(Dog):
    pass

class DobermanPinscher(Doberman):
    pass

class NoRoles(object):
    pass

class NoRolesChild(NoRoles):
    pass
  
for dog_type in (Dog, ): #Doberman, DobermanPinscher):
        for dog in (dog_type, dog_type()):
Пример #4
0
class rBar(Role):
    def bar(self):
        return 'rBar::bar'

    def baz(self):
        return 'rBar::baz'


class FooBarWithConflict(object):
    pass


foobarwithconflict_conflicts = 0
try:
    has_role(FooBarWithConflict, rFoo, rBar)
except RoleConflictDetected:
    foobarwithconflict_conflicts = 1

assert foobarwithconflict_conflicts


class FooBarWithOutConflict(object):
    def baz(self):
        return "FooBar::With::Out::Conflict::baz"


foobarwithoutconflict_resolved = 1
try:
    has_role(FooBarWithOutConflict, rFoo, rBar)
except RoleConflictDetected: