Create a PEG function to match an ordered choice.
978227
def choice(*es):
    
    msg = 'Expected one of: {}'.format(', '.join(map(repr, es)))
    def match_choice(s, grm=None, pos=0):
        errs = []
        for e in es:
            try:
                return e(s, grm, pos)
            except PegreError as ex:
                errs.append((ex.message, ex.position))
        if errs:
            raise PegreChoiceError(errs, pos)
    return match_choice
1248389
def add_choice(self, choice_name):
        """"""

        if not ALLOWED_NAMES.match(choice_name):
            raise ExperimentException(self.name, "Illegal choice name: %s" % choice_name)

        if choice_name in self.choice_names:
            raise ExperimentException(self.name, "Choice already exists: %s" % choice_name)

        self.choice_names.append(choice_name)
        self.redis.hset(EXPERIMENT_REDIS_KEY_TEMPLATE % self.name, "choices", escape.json_encode(self.choice_names))
        self.refresh()
782371
def choice(self, obj):
        
        tree_id = getattr(obj, self.queryset.model._mptt_meta.tree_id_attr, 0)
        left = getattr(obj, self.queryset.model._mptt_meta.left_attr, 0)
        return super(MPTTModelChoiceIterator,
                     self).choice(obj) + ((tree_id, left),)
493612
def p_lpartselect(self, p):
        ''
        p[0] = Partselect(p[1], p[3], p[5], lineno=p.lineno(1))
        p.set_lineno(0, p.lineno(1))
333310
function createPredicateFn(expression, comparator, matchAgainstAnyProp) {
  var predicateFn;

  if (comparator === true) {
    comparator = equals;
  } else if (!isFunction(comparator)) {
    comparator = function(actual, expected) {
      if (isObject(actual) || isObject(expected)) {
        // Prevent an object to be considered equal to a string like `'[object'`
        return false;
      }

      actual = lowercase('' + actual);
      expected = lowercase('' + expected);
      return actual.indexOf(expected) !== -1;
    };
  }

  predicateFn = function(item) {
    return deepCompare(item, expression, comparator, matchAgainstAnyProp);
  };

  return predicateFn;
}
964716
def flags(self, index):
        """"""
        column = index.column()

        if index.isValid():
            if column in [C.COL_START, C.COL_END]:
#                return Qt.ItemFlags(Qt.ItemIsEnabled | Qt.ItemIsSelectable)
                return Qt.ItemFlags(Qt.ItemIsEnabled)
            else:
                return Qt.ItemFlags(Qt.ItemIsEnabled | Qt.ItemIsSelectable)
#                return Qt.ItemFlags(Qt.ItemIsEnabled)
        else:
            return Qt.ItemFlags(Qt.ItemIsEnabled)
7252
function matchesCustom(ctx, opts) {
  if (opts.custom) {
    return opts.custom.call(ctx);
  }
  return false;
}
504803
def order_by(self, order_by: Union[set, str]):
        """"""
        clone = self._clone()
        if isinstance(order_by, str):
            order_by = {order_by}

        clone._order_by = clone._order_by.union(order_by)

        return clone
253093
def nsorted(
    to_sort: Iterable[str],
    key: Optional[Callable[[str], Any]] = None
) -> List[str]:
    """"""
    if key is None:
        key_callback = _natural_keys
    else:
        def key_callback(text: str) -> List[Any]:
            return _natural_keys(key(text))  # type: ignore

    return sorted(to_sort, key=key_callback)
884626
def equal_args(*args, **kwargs):
  """"""
  key = args
  if kwargs:
    key += _kwargs_separator + tuple(sorted(kwargs.items()))
  return key
1286280
def sorted(cls, items, orders):
    ''''''
    return sorted(items, cmp=cls.multipleOrderComparison(orders))
370081
def create_choice(choice_list, help_string=NO_HELP, default=NO_DEFAULT):
        # type: (List[str], str, Union[Any, NO_DEFAULT_TYPE]) -> str
        
        # noinspection PyTypeChecker
        return ParamChoice(
            help_string=help_string,
            default=default,
            choice_list=choice_list,
        )
413545
def choices(cls):
        
        # "natural" order, aka as given when instantiating
        if not hasattr(cls, '__choices_'):
            cls.__choices_ = tuple([c.choice for c in list(cls)])
        return cls.__choices_
795245
def make_k_chose_e(e_vec, k_vec):
    
    return product([sp.factorial(k) / (sp.factorial(e) * sp.factorial(k - e)) for e,k in zip(e_vec, k_vec)])
146720
def flags(self, index):
        """"""
        if not index.isValid():
            return Qt.ItemIsEnabled
        column = index.column()
        if column in [0]:
            return Qt.ItemFlags(Qt.ItemIsEnabled | Qt.ItemIsSelectable |
                                Qt.ItemIsUserCheckable | Qt.ItemIsEditable)
        else:
            return Qt.ItemFlags(Qt.ItemIsEnabled)
591755
def and_next(e):
    
    def match_and_next(s, grm=None, pos=0):
        try:
            e(s, grm, pos)
        except PegreError as ex:
            raise PegreError('Positive lookahead failed', pos)
        else:
            return PegreResult(s, Ignore, (pos, pos))
    return match_and_next
1346812
def _makeMatchSelection(self, block, columnIndex, matched):
        
        selection = QTextEdit.ExtraSelection()

        if matched:
            bgColor = Qt.green
        else:
            bgColor = Qt.red

        selection.format.setBackground(bgColor)
        selection.cursor = QTextCursor(block)
        selection.cursor.setPosition(block.position() + columnIndex)
        selection.cursor.movePosition(QTextCursor.Right, QTextCursor.KeepAnchor)

        return selection