Exemplo n.º 1
0
class Garment(item.Item, Enhancement):
    implements(iimaginary.IClothing, iimaginary.IDescriptionContributor)
    powerupInterfaces = (iimaginary.IClothing,
                         iimaginary.IDescriptionContributor)

    thing = attributes.reference()

    # templated / constant stuff
    garmentSlots = attributes.textlist(allowNone=False)
    bulk = attributes.integer(allowNone=False, default=1)
    garmentDescription = attributes.text(doc="""
    Description of this as an individual garment.
    """,
                                         allowNone=False)

    # transient / mutable stuff
    wearer = attributes.reference()
    wearLevel = attributes.integer(default=0)

    def conceptualize(self):
        return language.ExpressString(u'This can be worn.')

    def expressTo(self, observer):
        """
        Describe the garment as it looks when it is worn.

        The garment's normal description is C{self.thing.description} or
        somesuch.
        """
        return self.garmentDescription
Exemplo n.º 2
0
class Product(Item):
    """
    I represent a collection of powerups to install on a user store. When a
    user is to be endowed with the functionality described here, an
    Installation is created in its store based on me.
    """

    types = textlist()

    def installProductOn(self, userstore):
        """
        Creates an Installation in this user store for our collection
        of powerups, and then install those powerups on the user's
        store.
        """

        def install():
            i = Installation(store=userstore)
            i.types = self.types
            i.install()
        userstore.transact(install)

    def removeProductFrom(self, userstore):
        """
        Uninstall all the powerups this product references and remove
        the Installation item from the user's store. Doesn't remove
        the actual powerups currently, but /should/ reactivate them if
        this product is reinstalled.
        """
        def uninstall():
            #this is probably highly insufficient, but i don't know the
            #requirements
            i = userstore.findFirst(Installation,
                                    Installation.types == self.types)
            i.uninstall()
            i.deleteFromStore()
        userstore.transact(uninstall)

    def installOrResume(self, userstore):
        """
        Install this product on a user store. If this product has been
        installed on the user store already and the installation is suspended,
        it will be resumed. If it exists and is not suspended, an error will be
        raised.
        """
        for i in userstore.query(Installation, Installation.types == self.types):
            if i.suspended:
                unsuspendTabProviders(i)
                return
            else:
                raise RuntimeError("installOrResume called for an"
                                   " installation that isn't suspended")
        else:
            self.installProductOn(userstore)
Exemplo n.º 3
0
class KitchenSink(Item):
    """
    An item with one of everything, more or less.
    """
    t = text()
    i = integer()
    ts = timestamp()
    tl = textlist()
    d = ieee754_double()
    p1d = point1decimal()
    m = money()
Exemplo n.º 4
0
class Installation(Item):
    """
    I represent a collection of functionality installed on a user store. I
    reference a collection of powerups, probably designated by a Product.
    """

    types = textlist()
    _items = textlist()
    suspended = boolean(default=False)

    def items(self):
        """
        Loads the items this Installation refers to.
        """
        for id in self._items:
            yield self.store.getItemByID(int(id))
    items = property(items)
    def allPowerups(self):
        return set(chain(self.items, *[installedRequirements(self.store, i) for
                                       i in self.items]))
    allPowerups = property(allPowerups)

    def install(self):
        """
        Called when installed on the user store. Installs my powerups.
        """
        items = []
        for typeName in self.types:
            it = self.store.findOrCreate(namedAny(typeName))
            installOn(it, self.store)
            items.append(str(it.storeID).decode('ascii'))
        self._items = items

    def uninstall(self):
        """
        Called when uninstalled from the user store. Uninstalls all my
        powerups.
        """
        for item in self.items:
            uninstallFrom(item, self.store)
        self._items = []
Exemplo n.º 5
0
class FlavorPermission(Item):
    """
    I am associated with a top-level Blurb and specify the associated roles for
    all of its children.  For example: if there is a top-level blurb X with the
    BLOG flavor, there might be a FlavorPermission associated with it that
    makes reference to a 'writer staff' role for the BLOG_POST flavor, which
    has permissions IViewable, ICommentable - but conspicuously omits
    IEditable.  That collection of properties means that when posts are made on
    blog X they will be viewable and commentable by the writer staff, but not
    editable by them.  A separate flavor permission might deal with the
    editorial staff.

    Each permission is a zope Interface object.
    """
    # XXX "FlavorPermission" is a terrible name for this class, but I hope this
    # docstring is explanitory enough that someone else might help me think of
    # a better one.  at any rate, it's *mainly* an implementation detail,
    # although there does need to be some UI for managing this.

    typeName = 'hyperbola_flavor_permission'

    flavor = text(doc="""
        The 'flavor' attribute is the name of the flavor of a potential child
        of the blurb this permission applies to.

        For example, if this permission controls comments on a blurb that has
        the flavor FLAVOR.BLOG_POST, this attribute will be
        FLAVOR.BLOG_COMMENT.
        """)

    blurb = reference(doc="""
        The 'blurb' attribute is a reference to a L{Blurb}, whose children this
        object is controlling the permissions of.
        """)

    role = reference(doc="""
        The 'role' attribute is a reference to a L{Role}, which is the role
        that the permissions will be shared to.
        """)

    # XXX TODO -- right now sharing has a list of interfaces, axiom.dependecy
    # has a list of typeclasses, and hyperbola has this list of interfaces that
    # are slightly different than sharing's.  we should implement a "list of
    # interface objects" attribute, and a "list of typeName" attribute, so the
    # logic around this can be more abstract.

    permissions = textlist(doc="""
        A list of the names of Python interfaces that will be exposed to this
        permission's role.
        """)
Exemplo n.º 6
0
class TaggedListyThing(Item):
    strlist = textlist()
Exemplo n.º 7
0
class Dummy(Item):
    typeName = 'axiom_textlist_dummy'
    schemaVersion = 1

    attribute = textlist(doc="a textlist")
Exemplo n.º 8
0
class _DummyItem(Item):
    i = integer(default=5)
    t = text(doc=u'param t')
    tl = textlist(doc=u'param tl')
Exemplo n.º 9
0
class IRCBotConfig(Item):
    typeName = 'eridanus_ircbotconfig'
    schemaVersion = 5

    name = text(doc="""
    The name of the network this config is for.
    """)

    hostname = bytes(doc="""
    The hostname of the IRC server to connect to.
    """)

    portNumber = integer(doc="""
    The port to connect to the IRC server on.
    """)

    nickname = text(doc="""
    The bot's nickname.
    """)

    channels = textlist(doc="""
    A C{list} of channels the bot should join.
    """, default=[])

    ignores = textlist(doc="""
    A C{list} of masks to ignore.
    """, default=[])

    modes = bytes(doc="""
    A string of user modes to set after successfully connecting to C{hostname}.
    """, default='B')

    def addChannel(self, channel):
        if channel not in self.channels:
            self.channels = self.channels + [channel]


    def removeChannel(self, channel):
        channels = self.channels
        while channel in channels:
            channels.remove(channel)
        self.channels = channels


    def isIgnored(self, mask):
        mask = util.normalizeMask(mask)
        for ignore in self.ignores:
            ignore = util.normalizeMask(ignore)
            if util.hostMatches(mask, ignore):
                return True

        return False


    def addIgnore(self, mask):
        mask = util.normalizeMask(mask)
        if mask not in self.ignores:
            self.ignores = self.ignores + [mask]
            return mask
        return None


    def removeIgnore(self, mask):
        def removeIgnores(mask):
            for ignore in self.ignores:
                normalizedIgnore = util.normalizeMask(ignore)
                if not util.hostMatches(normalizedIgnore, mask):
                    yield ignore

        mask = util.normalizeMask(mask)
        newIgnores = list(removeIgnores(mask))
        diff = set(self.ignores) - set(newIgnores)
        self.ignores = newIgnores
        return list(diff) or None
Exemplo n.º 10
0
class Garment(item.Item, Enhancement):
    """
    An enhancement for a L{Thing} representing its utility as an article of
    clothing.
    """
    implements(iimaginary.IClothing, iimaginary.IDescriptionContributor,
               iimaginary.IMovementRestriction)

    powerupInterfaces = (iimaginary.IClothing,
                         iimaginary.IDescriptionContributor,
                         iimaginary.IMovementRestriction)

    thing = attributes.reference()

    # templated / constant stuff
    garmentSlots = attributes.textlist(allowNone=False)
    bulk = attributes.integer(allowNone=False, default=1)
    garmentDescription = attributes.text(doc="""
    Description of this as an individual garment.
    """,
                                         allowNone=False)

    # transient / mutable stuff
    wearer = attributes.reference()
    wearLevel = attributes.integer(default=0)

    def contributeDescriptionFrom(self, paths):
        return language.ExpressString(u'This can be worn.')

    def expressTo(self, observer):
        """
        Describe the garment as it looks when it is worn.

        The garment's normal description is C{self.thing.description} or
        somesuch.
        """
        return self.garmentDescription

    def nowWornBy(self, wearer):
        """
        This garment is now worn by the given wearer.  As this garment is now
        on top, set its C{wearLevel} to be higher than any other L{Garment}
        related to the new C{wearer}.
        """
        self.wearer = wearer
        self.wearLevel = wearer.store.query(
            Garment, Garment.wearer
            == wearer).getColumn("wearLevel").max(default=0) + 1

    def noLongerWorn(self):
        """
        This garment is no longer being worn by anyone.
        """
        self.wearer = None
        self.wearLevel = None

    def movementImminent(self, movee, destination):
        """
        Something is trying to move.  Don't allow it if I'm currently worn.
        """
        if self.wearer is not None and movee is self.thing:
            raise ActionFailure(
                ThatDoesntWork(
                    # XXX I don't actually know who is performing the action
                    # :-(.
                    actor=self.wearer.thing,
                    actorMessage=[
                        "You can't move ",
                        language.Noun(self.thing).definiteNounPhrase(),
                        " without removing it first."
                    ]))