Beispiel #1
0
    def add(self, obj, recog, max_length=60):
        """
        Assign a custom recog (nick) to the given object.

        Args:
            obj (Object): The object ot associate with the recog
                string. This is usually determined from the sdesc in the
                room by a call to parse_sdescs_and_recogs, but can also be
                given.
            recog (str): The replacement string to use with this object.
            max_length (int, optional): The max length of the recog string.

        Returns:
            recog (str): The (possibly cleaned up) recog string actually set.

        Raises:
            SdescError: When recog could not be set or sdesc longer
                than `max_length`.

        """
        # strip emote components from recog
        recog = _RE_REF.sub(
            r"\1",
            _RE_REF_LANG.sub(
                r"\1",
                _RE_SELF_REF.sub(
                    r"",
                    _RE_LANGUAGE.sub(r"", _RE_OBJ_REF_START.sub(r"", recog)))))

        # make an recog clean of ANSI codes
        cleaned_recog = ansi.strip_ansi(recog)
        if len(cleaned_recog) > max_length:
            raise RecogError("Too long recog")

        # mapping #dbref:obj
        key = "#%i" % obj.id
        self.obj.db._recog_ref2recog[key] = recog
        self.obj.db._recog_obj2recog[obj] = recog
        regex = ordered_permutation_regex(cleaned_recog)
        self.obj.db._recog_obj2regex[obj] = regex
        # local caching
        self.ref2recog[key] = recog
        self.obj2recog[obj] = recog
        self.obj2regex[obj] = re.compile(regex, _RE_FLAGS)
        return recog
Beispiel #2
0
    def add(self, obj, recog, max_length=60):
        """
        Assign a custom recog (nick) to the given object.

        Args:
            obj (Object): The object ot associate with the recog
                string. This is usually determined from the sdesc in the
                room by a call to parse_sdescs_and_recogs, but can also be
                given.
            recog (str): The replacement string to use with this object.
            max_length (int, optional): The max length of the recog string.

        Returns:
            recog (str): The (possibly cleaned up) recog string actually set.

        Raises:
            SdescError: When recog could not be set or sdesc longer
                than `max_length`.

        """
        # strip emote components from recog
        recog = _RE_REF.sub(r"\1",
                _RE_REF_LANG.sub(r"\1",
                _RE_SELF_REF.sub(r"",
                _RE_LANGUAGE.sub(r"",
                _RE_OBJ_REF_START.sub(r"", recog)))))

        # make an recog clean of ANSI codes
        cleaned_recog = ansi.strip_ansi(recog)
        if len(cleaned_recog) > max_length:
            raise RecogError("Too long recog")

        # mapping #dbref:obj
        key = "#%i" % obj.id
        self.obj.attributes.get("_recog_ref2recog", default={})[key] = recog
        self.obj.attributes.get("_recog_obj2recog", default={})[obj] = recog
        regex = ordered_permutation_regex(cleaned_recog)
        self.obj.attributes.get("_recog_obj2regex", default={})[obj] = regex
        # local caching
        self.ref2recog[key] = recog
        self.obj2recog[obj] = recog
        self.obj2regex[obj] = re.compile(regex, _RE_FLAGS)
        return recog
Beispiel #3
0
    def add(self, sdesc, max_length=60):
        """
        Add a new sdesc to object, replacing the old one.

        Args:
            sdesc (str): The sdesc to set. This may be stripped
                of control sequences before setting.
            max_length (int, optional): The max limit of the sdesc.

        Returns:
            sdesc (str): The actually set sdesc.

        Raises:
            SdescError: If the sdesc can not be set or is longer than
            `max_length`.

        """
        # strip emote components from sdesc
        sdesc = _RE_REF.sub(
            r"\1",
            _RE_REF_LANG.sub(
                r"\1",
                _RE_SELF_REF.sub(
                    r"",
                    _RE_LANGUAGE.sub(r"", _RE_OBJ_REF_START.sub(r"", sdesc)))))

        # make an sdesc clean of ANSI codes
        cleaned_sdesc = ansi.strip_ansi(sdesc)
        if len(cleaned_sdesc) > max_length:
            raise SdescError("Too long sdesc")

        # store to attributes
        sdesc_regex = ordered_permutation_regex(cleaned_sdesc)
        self.obj.attributes.add("_sdesc", sdesc)
        self.obj.attributes.add("_sdesc_regex", sdesc_regex)
        # local caching
        self.sdesc = sdesc
        self.sdesc_regex = re.compile(sdesc_regex, _RE_FLAGS)

        return sdesc
Beispiel #4
0
    def add(self, sdesc, max_length=60):
        """
        Add a new sdesc to object, replacing the old one.

        Args:
            sdesc (str): The sdesc to set. This may be stripped
                of control sequences before setting.
            max_length (int, optional): The max limit of the sdesc.

        Returns:
            sdesc (str): The actually set sdesc.

        Raises:
            SdescError: If the sdesc can not be set or is longer than
            `max_length`.

        """
        # strip emote components from sdesc
        sdesc = _RE_REF.sub(r"\1",
                _RE_REF_LANG.sub(r"\1",
                _RE_SELF_REF.sub(r"",
                _RE_LANGUAGE.sub(r"",
                _RE_OBJ_REF_START.sub(r"", sdesc)))))

        # make an sdesc clean of ANSI codes
        cleaned_sdesc = ansi.strip_ansi(sdesc)
        if len(cleaned_sdesc) > max_length:
            raise SdescError("Too long sdesc")

        # store to attributes
        sdesc_regex = ordered_permutation_regex(cleaned_sdesc)
        self.obj.attributes.add("_sdesc", sdesc)
        self.obj.attributes.add("_sdesc_regex", sdesc_regex)
        # local caching
        self.sdesc = sdesc
        self.sdesc_regex = re.compile(sdesc_regex, _RE_FLAGS)

        return sdesc