Get EOS formatted rule
197963
def _format_rule(self, protocol, cidr, min_port, max_port, direction):
        """"""
        if cidr is None:
            cidr = 'any'

        if direction == n_const.INGRESS_DIRECTION:
            dst_ip = 'any'
            src_ip = cidr
        elif direction == n_const.EGRESS_DIRECTION:
            dst_ip = cidr
            src_ip = 'any'

        if protocol == n_const.PROTO_NAME_ICMP:
            rule = "permit icmp %s %s" % (src_ip, dst_ip)
            if min_port:
                rule += " %s" % (min_port)
                if max_port:
                    rule += " %s" % (max_port)
        else:
            rule = "permit %s %s %s" % (protocol, src_ip, dst_ip)
            if min_port and max_port:
                rule += " range %s %s" % (min_port, max_port)
            elif min_port and not max_port:
                rule += " eq %s" % min_port
        return rule
1076223
def _to_rule(self, lark_rule):
        """"""
        assert isinstance(lark_rule.origin, NT)
        assert all(isinstance(x, Symbol) for x in lark_rule.expansion)
        return Rule(
            lark_rule.origin, lark_rule.expansion,
            weight=lark_rule.options.priority if lark_rule.options and lark_rule.options.priority else 0,
            alias=lark_rule)
90910
def _make_pull_imethod_resp(objs, eos, context_id):
        
        eos_tup = (u'EndOfSequence', None, eos)
        enum_ctxt_tup = (u'EnumerationContext', None, context_id)

        return [("IRETURNVALUE", {}, objs), enum_ctxt_tup, eos_tup]
1123445
def get_wharton_gsrs_formatted(self, sessionid, date=None):
        
        gsrs = self.get_wharton_gsrs(sessionid, date)
        return self.switch_format(gsrs)
212784
protected String getFormattedDatatypeValue(ICompositeNode node, AbstractRule rule, String text) throws ValueConverterException {
		Object value = valueConverter.toValue(text, rule.getName(), node);
		text = valueConverter.toString(value, rule.getName());
		return text;
	}
49151
def get_any_nt_unit_rule(g):
    """"""
    for rule in g.rules:
        if len(rule.rhs) == 1 and isinstance(rule.rhs[0], NT):
            return rule
    return None
91631
def _get_log_format(self, request):
        """"""
        user = getattr(request, 'user', None)
        if not user:
            return
        if not request.user.is_authenticated:
            return
        method = request.method.upper()
        if not (method in self.target_methods):
            return
        request_url = urlparse.unquote(request.path)
        for rule in self._ignored_urls:
            if rule.search(request_url):
                return
        return self.format
817062
def get_text_with_eol(self):
        """"""
        utext = to_text_string(self.toPlainText())
        lines = utext.splitlines()
        linesep = self.get_line_separator()
        txt = linesep.join(lines)
        if utext.endswith('\n'):
            txt += linesep
        return txt
612791
function getFormattedStopTime (stopTime) {
  return (
    <span>
      {stopTime.realtimeState === 'UPDATED'
        ? <Icon type='rss' style={{ color: '#888', fontSize: '0.8em', marginRight: 2 }} />
        : <Icon type='clock-o' style={{ color: '#888', fontSize: '0.8em', marginRight: 2 }} />
      }
      {formatStopTime(stopTime.realtimeDeparture)}
    </span>
  )
}
1131207
function getOptions(rules, opts) {
	var dir;
	var obj = {
		source: opts.source,
		transform: opts.transform || function (val) {
			return val;
		}
	};

	obj.path = opts.path || [];
	obj.path = Array.isArray(obj.path) ? obj.path : [obj.path];

	if (rules.length && rules[0].position && rules[0].position.source) {
		dir = path.dirname(rules[0].position.source);
	}

	if (dir && obj.path.indexOf(dir) === -1) {
		obj.path.unshift(dir);
	}

	if (!obj.path.length) {
		obj.path.push(process.cwd());
	}

	return obj;
}
71577
public String[] getContext(Object o) {
    /** String preceeding the eos character in the eos token. */
    String prefix;
    /** Space delimited token preceeding token containing eos character. */
    String previous;
    /** String following the eos character in the eos token. */
    String suffix;
    /** Space delimited token following token containsing eos character. */
    String next;
    Object first = ((Pair) o).a;
    /** Character offset of eos character in */
    int position = ((Integer) ((Pair) o).b).intValue();

    if (first instanceof String[]) {
      String[] $_ = (String[]) first;
      previous = $_[0];
      String current = $_[1];
      prefix = current.substring(0, position);
      suffix = current.substring(position + 1);
      if (suffix.startsWith(" "))
        collectFeats.add("sn");
      if (prefix.endsWith(" "))
        collectFeats.add("pn");
      collectFeats.add("eos=" + current.charAt(position));
      next = $_[2];
    }
    else { //compute previous, next, prefix and suffix Strings and space previous, space next features and eos features. 
      StringBuffer sb = (StringBuffer) ((Pair) o).a;
      int lastIndex = sb.length() - 1;
      { // compute space previous and space next features.
        if (position > 0 && sb.charAt(position - 1) == ' ')
          collectFeats.add("sp");
        if (position < lastIndex && sb.charAt(position + 1) == ' ')
          collectFeats.add("sn");
        collectFeats.add("eos=" + sb.charAt(position));
      }
      int prefixStart = previousSpaceIndex(sb, position);

      int c = position;
      { ///assign prefix, stop if you run into a period though otherwise stop at space
        while (--c > prefixStart) {
          for (int eci = 0, ecl = eosCharacters.length; eci < ecl; eci++) {
            if (sb.charAt(c) == eosCharacters[eci]) {
              prefixStart = c;
              c++; // this gets us out of while loop.
              break;
            }
          }
        }
        prefix = sb.substring(prefixStart, position).trim();
      }
      int prevStart = previousSpaceIndex(sb, prefixStart);
      previous = sb.substring(prevStart, prefixStart).trim();

      int suffixEnd = nextSpaceIndex(sb, position, lastIndex);
      {
        c = position;
        while (++c < suffixEnd) {
          for (int eci = 0, ecl = eosCharacters.length; eci < ecl; eci++) {
            if (sb.charAt(c) == eosCharacters[eci]) {
              suffixEnd = c;
              c--; // this gets us out of while loop.
              break;
            }
          }
        }
      }
      int nextEnd = nextSpaceIndex(sb, suffixEnd + 1, lastIndex + 1);
      if (position == lastIndex) {
        suffix = "";
        next = "";
      }
      else {
        suffix = sb.substring(position + 1, suffixEnd).trim();
        next = sb.substring(suffixEnd + 1, nextEnd).trim();
      }
    }

    buf.append("x=");
    buf.append(prefix);
    collectFeats.add(buf.toString());
    buf.setLength(0);
    if (!prefix.equals("")) {
      collectFeats.add(Integer.toString(prefix.length()));
      if (isFirstUpper(prefix)) {
        collectFeats.add("xcap");
      }
      if (inducedAbbreviations.contains(prefix)) {
        collectFeats.add("xabbrev");
      }
    }

    buf.append("v=");
    buf.append(previous);
    collectFeats.add(buf.toString());
    buf.setLength(0);
    if (!previous.equals("")) {
      if (isFirstUpper(previous)) {
        collectFeats.add("vcap");
      }
      if (inducedAbbreviations.contains(previous)) {
        collectFeats.add("vabbrev");
      }
    }

    buf.append("s=");
    buf.append(suffix);
    collectFeats.add(buf.toString());
    buf.setLength(0);
    if (!suffix.equals("")) {
      if (isFirstUpper(suffix)) {
        collectFeats.add("scap");
      }
      if (inducedAbbreviations.contains(suffix)) {
        collectFeats.add("sabbrev");
      }
    }

    buf.append("n=");
    buf.append(next);
    collectFeats.add(buf.toString());
    buf.setLength(0);
    if (!next.equals("")) {
      if (isFirstUpper(next)) {
        collectFeats.add("ncap");
      }
      if (inducedAbbreviations.contains(next)) {
        collectFeats.add("nabbrev");
      }
    }

    String[] context = new String[collectFeats.size()];
    context = (String[]) collectFeats.toArray(context);
    collectFeats.clear();
    return context;
  }
805920
def find_rule(self, rule):
        """"""
        defrule = lib.EnvFindDefrule(self._env, rule.encode())
        if defrule == ffi.NULL:
            raise LookupError("Rule '%s' not found" % defrule)

        return Rule(self._env, defrule)
994109
def from_raw(self, rule_ids, outputs, raw_rules):
        
        self._rule_pool = [([], [])] + raw_rules
        self._rule_list = []
        for i, idx in enumerate(rule_ids):
            rule = Rule([Clause(f, c) for f, c in zip(*self._rule_pool[idx])], outputs[i])
            self._rule_list.append(rule)
            # self._rule_list.append(rule_str2rule(_rule_name, outputs[i]))
        self._rule_ids = rule_ids
        self._rule_outputs = outputs
695073
def _get_rules_from_aws(self):
        
        list_of_rules = list()

        if self.profile:
            boto3.setup_default_session(profile_name=self.profile)

        if self.region:
            ec2 = boto3.client('ec2', region_name=self.region)
        else:
            ec2 = boto3.client('ec2')

        security_groups = ec2.describe_security_groups(Filters=self.filters)

        for group in security_groups['SecurityGroups']:
            group_dict = dict()
            group_dict['id'] = group['GroupId']
            group_dict['name'] = group['GroupName']
            group_dict['description'] = group.get('Description', None)

            if (group.get('IpPermissions', None) or
                    group.get('IpPermissionsEgress', None)):
                group_dict['rules'] = list()

            for rule in group.get('IpPermissions', None):
                rule_dict = self._build_rule(rule)
                rule_dict['direction'] = "INGRESS"

                group_dict['rules'].append(rule_dict)

            for rule in group.get('IpPermissionsEgress', None):
                rule_dict = self._build_rule(rule)
                rule_dict['direction'] = "EGRESS"

                group_dict['rules'].append(rule_dict)

            list_of_rules.append(group_dict)

        return list_of_rules
279536
public String getRule() {
    if (Clause_Type.featOkTst && ((Clause_Type)jcasType).casFeat_rule == null)
      jcasType.jcas.throwFeatMissing("rule", "com.digitalpebble.rasp.Clause");
    return jcasType.ll_cas.ll_getStringValue(addr, ((Clause_Type)jcasType).casFeatCode_rule);}
926202
function getFormatter(oType) {
		var oFormatOptions;

		if (!oType.oFormat) {
			oFormatOptions = jQuery.extend({strictParsing : true}, oType.oFormatOptions);
			oFormatOptions.UTC = true;
			oType.oFormat = DateFormat.getTimeInstance(oFormatOptions);
		}
		return oType.oFormat;
	}
850478
function convertBreakpointToMedia(rule) {
		rule.params = `(min-width: ${breakpoints[rule.name]}px)`;
		rule.name = 'media';
		rule.raws.afterName = ' ';
		rule.raws.between = ' ';

		return rule;
	}