Example #1
0
def sanitizeInstance(o):
    """If possible, sanitize the given instance so it is source-persistent.
    """
    if reflect.isinst(o,thing.Thing):
        return SourceThing(o)
    if reflect.isinst(o,observable.Hash):
        return SourceHash(o)
    else: return o # flag a warning here; you're screwed
Example #2
0
def sanitizeInstance(o):
    """If possible, sanitize the given instance so it is source-persistent.
    """
    if reflect.isinst(o, thing.Thing):
        return SourceThing(o)
    if reflect.isinst(o, observable.Hash):
        return SourceHash(o)
    else:
        return o  # flag a warning here; you're screwed
Example #3
0
def sanitizeMethod(o):
    """If this is a method of a Thing, sanitize it.
    Otherwise, write out the method.
    """
    if reflect.isinst(o.im_self, thing.Thing):
        return SourceMethod(o)
    else:
        return o  # screwed here too...
Example #4
0
def sanitizeMethod(o):
    """If this is a method of a Thing, sanitize it.
    Otherwise, write out the method.
    """
    if reflect.isinst(o.im_self,thing.Thing):
        return SourceMethod(o)
    else:
        return o # screwed here too...
Example #5
0
def remove_dots(value):
    if value is None:
        return None
    if not isinst(value, str):
        value = unicode(value)

    value = re.sub(r'\.', '', value)
    return value
Example #6
0
def remove_dots(value):
    if value is None:
        return None
    if not isinst(value, str):
        value = unicode(value)
        
    value = re.sub(r'\.', '', value)
    return value
Example #7
0
 def ambient_go(self, sentence):
     addtl = ""
     if self.exits:
         exit = random.choice(self.exits)
         room = self.findExit(exit)
         if not reflect.isinst(room, DarkRoom):
             addtl = " and head into the light!"
         sentence.subject.location = room
         sentence.subject.hears("You stumble around blindly...", addtl)
     else:
         sentence.subject.hears("You bash into a wall.")
Example #8
0
File: room.py Project: lhl/songclub
 def ambient_go(self, sentence):
     addtl = ""
     if self.exits:
         exit = random.choice(self.exits)
         room = self.findExit(exit)
         if not reflect.isinst(room, DarkRoom):
             addtl = " and head into the light!"
         sentence.subject.location = room
         sentence.subject.hears("You stumble around blindly...", addtl)
     else:
         sentence.subject.hears("You bash into a wall.")
Example #9
0
    def checkKeyMatch(self, key):
        """ Check to see if the given key matches this object's lock.

        Raise a error.Failure if it does not.  Override this method to
        implement different key-matching mechanisms; by default, I will check
        that one of the key's lockTypes is in my list of lockTypes.
        """
        if not reflect.isinst(key, Key):
            error.Failure("That's not a key.")
        for type in key.lockTypes:
            if type in self.lockTypes:
                return
        error.Failure(key, " doesn't seem to fit.")
Example #10
0
File: lock.py Project: lhl/songclub
    def checkKeyMatch(self, key):
        """ Check to see if the given key matches this object's lock.

        Raise a error.Failure if it does not.  Override this method to
        implement different key-matching mechanisms; by default, I will check
        that one of the key's lockTypes is in my list of lockTypes.
        """
        if not reflect.isinst(key, Key):
            error.Failure("That's not a key.")
        for type in key.lockTypes:
            if type in self.lockTypes:
                return
        error.Failure(key, " doesn't seem to fit.")
Example #11
0
    def ability_mutate(self, sentence):
        """mutate object to new_type

This will mutate an object into a different type of object. """
        mutator = sentence.directObject()
        try:
            newtype = sentence.indirectString("to")
            newtype = self.code_space[newtype]
        except:
            error.Failure("You don't know of any such type.")
        newtype = reflect.getcurrent(newtype)
        x = issubclass(newtype, reflect.getcurrent(thing.Thing))
        assert x, "You shouldn't mutate Things to types which are not Things."
        if not reflect.isinst(mutator, newtype):
            mutator.__class__ = newtype
Example #12
0
 def reportResults(self, testClass, method, resultType, results=None):
     jresults = results
     if type(jresults) == types.TupleType:
         typ, val, tb = jresults
         jresults = failure.Failure(val, typ, tb)
     # make sure Failures don't reference objects that can't be created
     # by the recipient
     if reflect.isinst(jresults, failure.Failure):
         jresults.type = str(jresults.type)
         jresults.value = str(jresults.value)
     testClassName, methodName = self.cleanResults(testClass, method)
     self.jellyMethodCall("reportResults",
                          testClassName, methodName,
                          resultType,
                          jresults)
     reporter.Reporter.reportResults(self, testClass, method, resultType,
                                     results)
Example #13
0
    def ability_rebuild(self, sentence):
        """rebuild (name|.python.name)

This will rebuild either a Thing (reloading its toplevel module (the one that
its class is in) and changing its class as appropriate.), an object in your
namespace, or a qualified python module name (prefixed with a dot).  """

        ds = sentence.directString()

        if ds[0] == ".":
            module = string.replace(ds[1:], " ", "")
            rebuild.rebuild(reflect.namedModule(module))
        else:
            try:
                object = self.code_space[ds]
            except:
                object = sentence.directObject()

            if reflect.isinst(object, thing.Thing):
                rebuild.rebuild(reflect.namedModule(object.__class__.__module__))
            else:
                rebuild.rebuild(object)
Example #14
0
        #     the preposition that the object being searched was found after in
        #     the sentence.
        #
        # (3) the player will be searched for methods of the form
        #     ability_verbname.

        # (1) locations
        locations = list(player.locations)
        locations.reverse()
        for loc in locations:
            self._ambientResolve(loc)
        # (2) explicitly specified objects
        obVals = self.objects.items()
        obVals.sort()  # sort by preposition name
        for prep, ob in obVals:
            if reflect.isinst(ob, thing.Thing):
                self._resolve(ob, prep)
        # (3) attempt to get an ability from the player
        self._abilityResolve(player)
        if self.candidates:
            return

        # If there are no candidates after scanning all of the usual suspects
        # for applicable verbs, perform an exhaustive search for other objects
        # which contain an auto-verb listed for this verb.  This means a
        # hashtable of the form
        #
        #   {verb: preposition,
        #    ...}
        #
        # Where verb is the name of the verb which should be automatically used
Example #15
0
 #     the preposition that the object being searched was found after in
 #     the sentence.
 # 
 # (3) the player will be searched for methods of the form
 #     ability_verbname.
 
 # (1) locations
 locations = list(player.locations)
 locations.reverse()
 for loc in locations:
     self._ambientResolve(loc)
 # (2) explicitly specified objects
 obVals = self.objects.items()
 obVals.sort() # sort by preposition name
 for prep, ob in obVals:
     if reflect.isinst(ob, thing.Thing):
         self._resolve(ob, prep)
 # (3) attempt to get an ability from the player
 self._abilityResolve(player)
 if self.candidates:
     return
 
 # If there are no candidates after scanning all of the usual suspects
 # for applicable verbs, perform an exhaustive search for other objects
 # which contain an auto-verb listed for this verb.  This means a
 # hashtable of the form
 #
 #   {verb: preposition,
 #    ...}
 # 
 # Where verb is the name of the verb which should be automatically used