Returns the right context for an element, as a list. This method crosses sentence/paragraph boundaries by default, which can be restricted by setting scope
766698
def rightcontext(self, size, placeholder=None, scope=None):
        """"""

        if size == 0: return [] #for efficiency

        context = []
        e = self
        while len(context) < size:
            e = e.next(True,scope)
            if not e: break
            context.append(e)

        if placeholder:
            while len(context) < size:
                context.append(placeholder)

        return context
800463
def get_context(self):
        
        context = super(MailListView, self).get_context()
        mail_list = registered_mails_names()

        context['mail_map'] = mail_list
        return context
1061810
def span_context_from_string(value):
    
    if type(value) is list and len(value) > 0:
        # sometimes headers are presented as arrays of values
        if len(value) > 1:
            raise SpanContextCorruptedException(
                'trace context must be a string or array of 1: "%s"' % value)
        value = value[0]
    if not isinstance(value, six.string_types):
        raise SpanContextCorruptedException(
            'trace context not a string "%s"' % value)
    parts = value.split(':')
    if len(parts) != 4:
        raise SpanContextCorruptedException(
            'malformed trace context "%s"' % value)
    try:
        trace_id = int(parts[0], 16)
        span_id = int(parts[1], 16)
        parent_id = int(parts[2], 16)
        flags = int(parts[3], 16)
        if trace_id < 1 or span_id < 1 or parent_id < 0 or flags < 0:
            raise SpanContextCorruptedException(
                'malformed trace context "%s"' % value)
        if parent_id == 0:
            parent_id = None
        return trace_id, span_id, parent_id, flags
    except ValueError as e:
        raise SpanContextCorruptedException(
            'malformed trace context "%s": %s' % (value, e))
91489
@VisibleForTesting
  static Context parse(String text) {
    Queue<String> parts = Lists.newLinkedList(Arrays.asList(text.split(" ")));
    Context.Builder builder = HTML_PCDATA.toBuilder();
    builder.withState(HtmlContext.valueOf(parts.remove()));
    if (!parts.isEmpty()) {
      try {
        builder.withElType(ElementType.valueOf(parts.element()));
        parts.remove();
      } catch (IllegalArgumentException ex) {
        // OK
      }
    }
    if (!parts.isEmpty()) {
      try {
        builder.withAttrType(AttributeType.valueOf(parts.element()));
        parts.remove();
      } catch (IllegalArgumentException ex) {
        // OK
      }
    }
    if (!parts.isEmpty()) {
      try {
        builder.withDelimType(AttributeEndDelimiter.valueOf(parts.element()));
        parts.remove();
      } catch (IllegalArgumentException ex) {
        // OK
      }
    }
    if (!parts.isEmpty()) {
      try {
        builder.withSlashType(JsFollowingSlash.valueOf(parts.element()));
        parts.remove();
      } catch (IllegalArgumentException ex) {
        // OK
      }
    }
    if (!parts.isEmpty()) {
      try {
        builder.withUriPart(UriPart.valueOf(parts.element()));
        parts.remove();
      } catch (IllegalArgumentException ex) {
        // OK
      }
    }
    if (!parts.isEmpty()) {
      try {
        builder.withUriType(UriType.valueOf(parts.element()));
        parts.remove();
      } catch (IllegalArgumentException ex) {
        // OK
      }
    }
    if (!parts.isEmpty()) {
      String part = parts.element();
      String prefix = "templateNestDepth=";
      if (part.startsWith(prefix)) {
        try {
          builder.withTemplateNestDepth(Integer.parseInt(part.substring(prefix.length())));
          parts.remove();
        } catch (NumberFormatException ex) {
          // OK
        }
      }
    }
    if (!parts.isEmpty()) {
      String part = parts.element();
      String prefix = "jsTemplateLiteralNestDepth=";
      if (part.startsWith(prefix)) {
        try {
          builder.withJsTemplateLiteralNestDepth(Integer.parseInt(part.substring(prefix.length())));
          parts.remove();
        } catch (NumberFormatException ex) {
          // OK
        }
      }
    }
    if (!parts.isEmpty()) {
      throw new IllegalArgumentException(
          "Unable to parse context \"" + text + "\". Unparsed portion: " + parts);
    }
    Context result = builder.build();
    return result;
  }
1312182
def get_contextualize_items_by_step(self, default=None):
        """"""
        if self.items:
            res = {}
            for elem in self.items.values():
                if elem.num in res:
                    res[elem.num].append(elem)
                else:
                    res[elem.num] = [elem]
            return res
        else:
            return default
641215
def context(self):
        
        ret = libxml2mod.xmlXPathParserGetContext(self._o)
        if ret is None:raise xpathError('xmlXPathParserGetContext() failed')
        __tmp = xpathContext(_obj=ret)
        return __tmp
1093975
private Context currentContext()
   {
      LinkedList<Context> stack = threadContexts.get();

      if (stack != null && !stack.isEmpty())
      {
         return stack.getLast();
      }

      return null;
   }
134466
function( elem, context, xml ) {
			while ( (elem = elem[ dir ]) ) {
				if ( checkNonElements || elem.nodeType === 1  ) {
					return matcher( elem, context, xml );
				}
			}
		}
1042273
def context_range(self, context):
        
        if not context.startswith(self.prefix):
            context = self.prefix + '.' + context

        lo = hi = None
        for idx, line_context in enumerate(self.lines, 1):

            # context is hierarchical -- context spans itself
            # and any suffix.
            if line_context.startswith(context):
                lo = lo or idx
                hi = idx

        if lo is None:
            raise ValueError("Context %s does not exist in file %s" %
                             (context, self.filename))

        return lo, hi + 1
392267
def contextDoc(self):
        
        ret = libxml2mod.xmlXPathGetContextDoc(self._o)
        if ret is None:raise xpathError('xmlXPathGetContextDoc() failed')
        __tmp = xmlDoc(_obj=ret)
        return __tmp
823542
def context(self):
	
		
		
		return execution.Context(self.__base_dir, self.__prof_dir,
				self.__prof_name)
737294
def getContext(self, context_name = 'default'):
		
		if context_name == 'default' and 'default' not in self.contexts:
			self('default')

		return self.contexts[context_name]
306483
@Override
	public String[] getContext(Sentence sent, int pos) {
	List<String> cps = new ArrayList<String>();
		
		for (int it = 0; it < cpnames.size(); ++it){			
			String cp = cpnames.get(it);
			Vector<Integer> paras = this.paras.get(it);
			String cpvalue = "";
			if (cp.equals("initial_cap")){
				cpvalue = ic(sent,pos,paras.get(0));
			}
			else if (cp.equals("all_cap")){
				cpvalue = ac(sent, pos, paras.get(0));
			}
			else if (cp.equals("mark")){
				cpvalue = mk(sent, pos, paras.get(0));
			}
			else if (cp.equals("first_obsrv")){
				if (pos + paras.get(0) == 0)
					cpvalue = "fi:" + paras.get(0);
			}
			
			if (!cpvalue.equals("")) cps.add(cpvalue);
		}
		String [] ret = new String[cps.size()];		
		return cps.toArray(ret);
	}
1029342
def sentence(self):
        
        if self._sentence is None:
            sentences = self._element.xpath('sentence/text()')
            if len(sentences) > 0:
                self._sentence = self._coref.document.get_sentence_by_id(int(sentences[0]))
        return self._sentence
647305
def get_context(self, line=1, column=0):
        ''

        line -= 1  # The line is one-based

        # If there is no data in the file, there can be no context.
        datalen = len(self.data)
        if datalen <= line:
            return None

        build = [self.data[line]]

        # Add surrounding lines if they're available. There must always be
        # three elements in the context.
        if line > 0:
            build.insert(0, self.data[line - 1])
        else:
            build.insert(0, None)

        if line < datalen - 1:
            build.append(self.data[line + 1])
        else:
            build.append(None)

        leading_counts = []

        # Count whitespace to determine how much needs to be stripped.
        lstrip_count = INFINITY
        for line in build:
            # Don't count empty/whitespace-only lines.
            if line is None or not line.strip():
                leading_counts.append(lstrip_count)
                continue

            # Isolate the leading whitespace.
            ws_count = len(line) - len(line.lstrip())
            leading_counts.append(ws_count)
            if ws_count < lstrip_count:
                lstrip_count = ws_count

        # If all of the lines were skipped over, it means everything was
        # whitespace.
        if lstrip_count == INFINITY:
            return ('', '', '')

        for lnum in range(3):
            # Skip edge lines.
            if not build[lnum]:
                continue

            line = build[lnum].strip()

            # Empty lines stay empty.
            if not line:
                build[lnum] = ''
                continue

            line = self._format_line(line, column=column, rel_line=lnum)
            line = '%s%s' % (' ' * (leading_counts[lnum] - lstrip_count), line)

            build[lnum] = line

        # Return the final output as a tuple.
        return tuple(build)
1261495
public WebElement findElement(SearchContext context) {
    List<WebElement> allElements = findElements(context);
    if (allElements == null || allElements.isEmpty()) {
      throw new NoSuchElementException("Cannot locate an element using " + toString());
    }
    return allElements.get(0);
  }
720318
function(context) {
        var node = this.createElementDefaultNS("FormatList");
        for (var i=0, len=context.formats.length; i<len; i++) {
            var format = context.formats[i];
            node.appendChild(this.createElementDefaultNS(
                "Format",
                format.value,
                (format.current && format.current == true) ?
                    {current: "1"} : null
            ));
        }

        return node;
    }