Beispiel #1
0
    def __init__(self, **kwargs):
        """        
        :param \*\*kwargs: passed safely to CompoundRule_
       
        """
        _spec = _first_not_none(kwargs.get("spec"), self.spec)
        _extras = _first_not_none(kwargs.get("extras"), getattr(self, "extras", None))

        kwargs["spec"], kwargs["extras"] = self._alter_rule(_spec, _extras)
        _RegistryRule.__init__(self, **kwargs)
Beispiel #2
0
    def __init__(self, **kwargs):
        """        
        :param \*\*kwargs: passed safely to CompoundRule_
       
        """
        _spec = _first_not_none(kwargs.get("spec"), self.spec)
        _extras = _first_not_none(kwargs.get("extras"), getattr(self, "extras", None))

        kwargs["spec"], kwargs["extras"] = self._alter_rule(_spec, _extras)
        _RegistryRule.__init__(self, **kwargs)
Beispiel #3
0
 def _determine_partials(rule, intros=None):
     partials = []
     intros = _first_not_none(intros, Registry._get_intros(rule))
     for intro in intros:
         position = intro.rfind(" ")
         while position != -1: # -1 means down to final word, not a partial
             partials.append(intro[0:position])
             position = intro.rfind(" ", 0, position)
     return partials
Beispiel #4
0
 def _determine_partials(rule, intros=None):
     partials = []
     intros = _first_not_none(intros, Registry._get_intros(rule))
     for intro in intros:
         position = intro.rfind(" ")
         while position != -1:  # -1 means down to final word, not a partial
             partials.append(intro[0:position])
             position = intro.rfind(" ", 0, position)
     return partials
Beispiel #5
0
 def __init__(self, name, registry=None, **kwargs):
     """
     :param name: Passed to dragonfly Grammar_
     :param Registry registry: The Registry object that serves as the
         active `registration` list. It may be shared across
         RegistryGrammar instances. If None, a local Registry object is
         created.
     :param \*\*kwargs: Passed safely to dragonfly Grammar_
     """
     self.registry = _first_not_none(registry, Registry())
     _safe_kwargs(Grammar.__init__, self, name, **kwargs)
Beispiel #6
0
 def __init__(self, name, registry=None, **kwargs):
     """
     :param name: Passed to dragonfly Grammar_
     :param Registry registry: The Registry object that serves as the
         active `registration` list. It may be shared across
         RegistryGrammar instances. If None, a local Registry object is
         created.
     :param \*\*kwargs: Passed safely to dragonfly Grammar_
     """
     self.registry = _first_not_none(registry, Registry())
     _safe_kwargs(Grammar.__init__, self, name, **kwargs)
Beispiel #7
0
 def __init__(self, intros=None, intros_spec=None, **kwargs):
     """
     For information regarding ``intros`` and ``intros_spec``, refer to the
     `intros documentation <intros>`.
     
     :param intros: If None, the command `intros <intros>`
         will be automatically determined from the spec, otherwise any string
         provided, by itself or in a list, will be registered as an intro of
         the command. If supplied, overrides any provided ``intros_spec``.
     :type intros: string, string list, or None
     :param string intros_spec: If supplied, will be parsed to obtained the
         intros for the command, similar in manner to how spec is parsed.
     :param \*\*kwargs: passed safely to CompoundRule_
     
     """
     self._intros = _first_not_none(intros, getattr(self, "intros", None))
     if isinstance(self._intros, six.string_types):
             self._intros = [self._intros]
     self._intros_spec = _first_not_none(intros_spec, getattr(self, "intros_spec", None))
     
     # avoid duplicate processing to speed load time
     if not isinstance(self, FluidRule):
         _RegistryRule.__init__(self, **kwargs)
Beispiel #8
0
 def __init__(self, intros=None, intros_spec=None, **kwargs):
     """
     For information regarding ``intros`` and ``intros_spec``, refer to the
     `intros documentation <intros>`.
     
     :param intros: If None, the command `intros <intros>`
         will be automatically determined from the spec, otherwise any string
         provided, by itself or in a list, will be registered as an intro of
         the command. If supplied, overrides any provided ``intros_spec``.
     :type intros: string, string list, or None
     :param string intros_spec: If supplied, will be parsed to obtained the
         intros for the command, similar in manner to how spec is parsed.
     :param \*\*kwargs: passed safely to CompoundRule_
     
     """
     self._intros = _first_not_none(intros, getattr(self, "intros", None))
     if isinstance(self._intros, six.string_types):
             self._intros = [self._intros]
     self._intros_spec = _first_not_none(intros_spec, getattr(self, "intros_spec", None))
     
     # avoid duplicate processing to speed load time
     if not isinstance(self, FluidRule):
         _RegistryRule.__init__(self, **kwargs)
Beispiel #9
0
 def _determine_intros(rule):
     """
     Expected to be able to accept any spec as long as it is well-formed:
     - balanced parentheses and brackets
     - contains no { or } characters
     - outside of <extra> references, contains no < or > characters
     
     This could be further enhanced to extract string parts from Option elements
     e.g.    spec = "select <direction> word"
             extras = (Choice("direction", {"left":"left", "right":"right"}), )
             ### intros --> ["select right word", "select left word"]
     """
     if rule._intros:
         return rule._intros
     else:
         intros_spec = _first_not_none(getattr(rule, "_intros_spec", None), getattr(rule, "_spec", None))
         if not intros_spec:
             return None
         return Registry._parse_spec(intros_spec)
Beispiel #10
0
 def _determine_intros(rule):
     """
     Expected to be able to accept any spec as long as it is well-formed:
     - balanced parentheses and brackets
     - contains no { or } characters
     - outside of <extra> references, contains no < or > characters
     
     This could be further enhanced to extract string parts from Option elements
     e.g.    spec = "select <direction> word"
             extras = (Choice("direction", {"left":"left", "right":"right"}), )
             ### intros --> ["select right word", "select left word"]
     """
     if rule._intros:
         return rule._intros
     else:
         intros_spec = _first_not_none(getattr(rule, "_intros_spec", None),
                                       getattr(rule, "_spec", None))
         if not intros_spec:
             return None
         return Registry._parse_spec(intros_spec)