コード例 #1
0
ファイル: loader.py プロジェクト: gitter-badger/dragonfly-1
 def build(self, call_info):
     name = call_info.name
     min = call_info.arguments.pop().value
     max = call_info.arguments.pop().value
     if call_info.arguments:
         raise SyntaxError("Invalid arguments for integer extra: %r" %
                           (call_info.arguments, ))
     print "just build", dragonfly.Integer(name=name, min=min, max=max)
     return dragonfly.Integer(name=name, min=min, max=max)
コード例 #2
0
 def build(self, call_info):
     name = call_info.name
     arguments = call_info.arguments
     # Check argument input here.
     min = arguments.pop().value
     max = arguments.pop().value
     if arguments:
         raise SyntaxError("Invalid arguments for integer extra: %r" %
                           (arguments, ))
     return dragonfly.Integer(name=name, min=min, max=max)
コード例 #3
0
ファイル: _dfly_client.py プロジェクト: sboosali/mandimus
    def cleanupProtoRule(self, r, allPrototypes):
        # have to uniquify in this round about way because lists
        # aren't hashable and we need them for ListRef.
        if type(r["extras"]) == dict:
            r["extras"] = r["extras"].values()

        newExtras = []
        for e in r["extras"]:
            if isinstance(e, protocol.Integer):
                newExtras.append(dfly.Integer(e.name, e.min, e.max))
            elif isinstance(e, protocol.Dictation):
                newExtras.append(dfly.Dictation(e.name))
            elif isinstance(e, protocol.Repetition):
                if e.rule_ref not in self.concreteRules:
                    self.cleanupProtoRule(allPrototypes[e.rule_ref],
                                          allPrototypes)

                # Dragonfly wants RuleRef to take a RuleRef rather than an actual
                # Rule, so we just make one rather than forcing the server to
                # handle this, see protocol.py comments.
                concrete = self.concreteRules[e.rule_ref]
                log.info("concrete type: [%s]" % type(concrete))
                newExtras.append(
                    dfly.Repetition(dfly.RuleRef(rule=concrete), e.min, e.max,
                                    e.name))
            elif isinstance(e, protocol.RuleRef):
                if e.rule_ref not in self.concreteRules:
                    self.cleanupProtoRule(allPrototypes[e.rule_ref],
                                          allPrototypes)

                newExtras.append(
                    dfly.RuleRef(self.concreteRules[e.rule_ref], e.name))
            elif isinstance(e, protocol.ListRef):
                self.concreteWordLists[e.name] = List(e.name + "ConcreteList")
                # self.concreteWordLists[e.name].set(e.words)
                newExtras.append(
                    dfly.ListRef(e.ref_name, self.concreteWordLists[e.name]))
            else:
                raise Exception("Unknown extra type: [%s]" % e)

        r["extras"] = newExtras

        self.concreteStartTime = time.time()
        self.buildConcreteRule(r)
        self.concreteEndTime = time.time()
        self.concreteTime += (self.concreteEndTime - self.concreteStartTime)

        r["built"] = True
        return True