Get back an ET.Element for several possible input formats
492171
def get_element(text_or_tree_or_element):
    
    if isinstance(text_or_tree_or_element, ET.Element):
        return text_or_tree_or_element
    elif isinstance(text_or_tree_or_element, ET.ElementTree):
        return text_or_tree_or_element.getroot()
    elif isinstance(text_or_tree_or_element, (unicode, bytes)):
        return ET.fromstring(text_or_tree_or_element)
    else:
        return ET.parse(text_or_tree_or_element).getroot()
994012
function getNth (elements, target) {
  var length = elements.length
  var count = 0
  for (var index = 0; index < length; index++) {
    var element = elements[index]
    if (!element.hasOwnProperty('deleted')) {
      if (count === target) {
        return index
      }
      count++
    }
  }
  return (index + 1)
}
1146226
def parse_at_root(
            self,
            root,  # type: ET.Element
            state  # type: _ProcessorState
    ):
        # type: (...) -> Any
        """"""
        parsed_dict = {}  # type: Dict

        dict_element = _element_find_from_root(root, self.element_path)
        if dict_element is not None:
            parsed_dict = self.parse_at_element(dict_element, state)
        elif self.required:
            raise MissingValue('Missing required root aggregate "{}"'.format(self.element_path))

        return parsed_dict
1277599
def _element_to_bson(key, value, check_keys, opts):
    """"""
    if not isinstance(key, string_type):
        raise InvalidDocument("documents must have only string keys, "
                              "key was %r" % (key,))
    if check_keys:
        if key.startswith("$"):
            raise InvalidDocument("key %r must not start with '$'" % (key,))
        if "." in key:
            raise InvalidDocument("key %r must not contain '.'" % (key,))

    name = _make_name(key)
    return _name_value_to_bson(name, value, check_keys, opts)
551769
function getData(el, attr, isInt, prefix) {
    if (prefix === undefined) {
      prefix = 'wookmark-';
    }
    var val = el.getAttribute('data-' + prefix + attr);
    if (isInt === true) {
      return parseInt(val, 10);
    }
    return val;
  }
1129809
def _getel(key, value):
    """"""
    if key in ['HorizontalRule', 'Null']:
        return elt(key, 0)()
    elif key in ['Plain', 'Para', 'BlockQuote', 'BulletList',
                 'DefinitionList', 'HorizontalRule', 'Null']:
        return elt(key, 1)(value)
    return elt(key, len(value))(*value)
1141728
function extractAttribs( def ) {
    var key, val, attribs = { standard: {}, special: {}, implicit: [] };
    for ( key in def ) {
        val = def[ key ];
        if ( RX_INTEGER.test( key ) ) {
            attribs.implicit.push( val );
        } else if ( RX_STD_ATT.test( key ) ) {
            attribs.standard[ key ] = val;
        } else {
            attribs.special[ key ] = val;
        }
    }
    return attribs;
}
776358
def element(self, inp=None):
        """"""
        if inp is not None:
            s = str(inp)[:self.length]
            s += ' ' * (self.length - len(s))
            return s
        else:
            return ' ' * self.length
1303090
def _to_DOM(self):
        
        root_node = ET.Element("no2index")
        reference_time_node = ET.SubElement(root_node, "reference_time")
        reference_time_node.text = str(self._reference_time)
        reception_time_node = ET.SubElement(root_node, "reception_time")
        reception_time_node.text = str(self._reception_time)
        interval_node = ET.SubElement(root_node, "interval")
        interval_node.text = str(self._interval)
        no2_samples_node = ET.SubElement(root_node, "no2_samples")
        for smpl in self._no2_samples:
            s = smpl.copy()
            # turn values to 12 decimal digits-formatted strings
            s['label'] = s['label']
            s['value'] = '{:.12e}'.format(s['value'])
            s['precision'] = '{:.12e}'.format(s['precision'])
            xmlutils.create_DOM_node_from_dict(s, "no2_sample",
                                               no2_samples_node)
        root_node.append(self._location._to_DOM())
        return root_node
158070
function extractLiteralFromInstalled(stats, element) {
    if (element.length === 0) return stats;
    let value = "";
    if (validLiteral(element[0])) {
        value = element[0].value;
        // let array = value.split('$');
        // if (array.length == 0) {
        //     stats.setPackageName(value);
        // } else {
        //     stats.setPackageName(array[0]);
        //     stats.setPackageVersion(array[1]);
        // }
        stats.setPackageName(value);
    }
    if (validLiteral(element[1])) {
        value = element[1].value;
        stats.setFileName(value);
    }
    if (validLiteral(element[2])) {
        value = element[2].value;
        stats.setVersion(value);
    }
    return stats;
}
888295
def to_ele(x):
    ""
    if sys.version < '3':
        return x if etree.iselement(x) else etree.fromstring(x, parser=parser)
    else:
        return x if etree.iselement(x) else etree.fromstring(x.encode('UTF-8'), parser=parser)
588801
def parse_at_element(
            self,
            element,  # type: ET.Element
            state  # type: _ProcessorState
    ):
        # type: (...) -> Any
        """"""
        if self._attribute:
            parsed_value = self._parse_attribute(element, self._attribute, state)
        else:
            parsed_value = self._parser_func(element.text, state)

        return _hooks_apply_after_parse(self._hooks, state, parsed_value)
575842
def get_format(self, c, i):
        """"""

        index = i.index
        field = ''
        value = []

        try:
            if c == '}':
                value.append((_util.FMT_FIELD, ''))
                value.append((_util.FMT_INDEX, -1))
            else:
                # Field
                if c in _LETTERS_UNDERSCORE:
                    # Handle name
                    value.append(c)
                    c = self.format_next(i)
                    while c in _WORD:
                        value.append(c)
                        c = self.format_next(i)
                elif c in _DIGIT:
                    # Handle group number
                    value.append(c)
                    c = self.format_next(i)
                    while c in _DIGIT:
                        value.append(c)
                        c = self.format_next(i)

                # Try and covert to integer index
                field = ''.join(value).strip()
                try:
                    value = [(_util.FMT_FIELD, str(int(field, 10)))]
                except ValueError:
                    value = [(_util.FMT_FIELD, field)]
                    pass

                # Attributes and indexes
                count = 0
                while c in ('[', '.'):
                    if c == '[':
                        findex = []
                        sindex = i.index - 1
                        c = self.format_next(i)
                        try:
                            while c != ']':
                                findex.append(c)
                                c = self.format_next(i)
                        except StopIteration:
                            raise SyntaxError("Unmatched '[' at %d" % (sindex - 1))
                        idx = self.parse_format_index(''.join(findex))
                        if isinstance(idx, int):
                            value.append((_util.FMT_INDEX, idx))
                        else:
                            value.append((_util.FMT_INDEX, idx))
                        c = self.format_next(i)
                    else:
                        if count == 0:
                            value.append((_util.FMT_INDEX, -1))
                        findex = []
                        c = self.format_next(i)
                        while c in _WORD:
                            findex.append(c)
                            c = self.format_next(i)
                        value.append((_util.FMT_ATTR, ''.join(findex)))
                    count += 1

                if count == 0:
                    value.append((_util.FMT_INDEX, -1))

                # Conversion
                if c == '!':
                    c = self.format_next(i)
                    if c not in _FMT_CONV_TYPE:
                        raise SyntaxError("Invalid conversion type at %d!" % (i.index - 1))
                    value.append((_util.FMT_CONV, c))
                    c = self.format_next(i)

                # Format spec
                if c == ':':
                    fill = None
                    width = []
                    align = None
                    convert = None
                    c = self.format_next(i)

                    if c in ('<', '>', '^'):
                        # Get fill and alignment
                        align = c
                        c = self.format_next(i)
                        if c in ('<', '>', '^'):
                            fill = align
                            align = c
                            c = self.format_next(i)
                    elif c in _DIGIT:
                        # Get Width
                        fill = c
                        c = self.format_next(i)
                        if c in ('<', '>', '^'):
                            align = c
                            c = self.format_next(i)
                        else:
                            width.append(fill)
                            fill = None
                    else:
                        fill = c
                        c = self.format_next(i)
                        if fill == 's' and c == '}':
                            convert = fill
                            fill = None
                        if fill is not None:
                            if c not in ('<', '>', '^'):
                                raise SyntaxError('Invalid format spec char at %d!' % (i.index - 1))
                            align = c
                            c = self.format_next(i)

                    while c in _DIGIT:
                        width.append(c)
                        c = self.format_next(i)

                    if not align and len(width) and width[0] == '0':
                        raise ValueError("'=' alignment is not supported!")
                    if align and not fill and len(width) and width[0] == '0':
                        fill = '0'

                    if c == 's':
                        convert = c
                        c = self.format_next(i)

                    if fill and self.is_bytes:
                        fill = fill.encode('latin-1')
                    elif not fill:
                        fill = b' ' if self.is_bytes else ' '

                    value.append((_util.FMT_SPEC, (fill, align, (int(''.join(width)) if width else 0), convert)))

            if c != '}':
                raise SyntaxError("Unmatched '{' at %d" % (index - 1))
        except StopIteration:
            raise SyntaxError("Unmatched '{' at %d!" % (index - 1))

        return field, value
105746
def _generate_docstring_return_section(self, return_vals, header,
                                           return_element_name,
                                           return_element_type,
                                           placeholder, indent):
        """"""
        # If all return values are None, return none
        non_none_vals = [return_val for return_val in return_vals
                         if return_val and return_val != 'None']
        if not non_none_vals:
            return header + indent + 'None.'

        # Get only values with matching brackets that can be cleaned up
        non_none_vals = [return_val.strip(' ()\t\n').rstrip(',')
                         for return_val in non_none_vals]
        non_none_vals = [re.sub('([\"\'])(?:(?=(\\\\?))\\2.)*?\\1',
                                '"string"', return_val)
                         for return_val in non_none_vals]
        unambiguous_vals = []
        for return_val in non_none_vals:
            try:
                cleaned_val = self.find_top_level_bracket_locations(return_val)
            except IndexError:
                continue
            unambiguous_vals.append(cleaned_val)
        if not unambiguous_vals:
            return header + placeholder

        # If remaining are a mix of tuples and not, return single placeholder
        single_vals, tuple_vals = [], []
        for return_val in unambiguous_vals:
            (tuple_vals.append(return_val) if ',' in return_val
             else single_vals.append(return_val))
        if single_vals and tuple_vals:
            return header + placeholder

        # If return values are tuples of different length, return a placeholder
        if tuple_vals:
            num_elements = [return_val.count(',') + 1
                            for return_val in tuple_vals]
            if num_elements.count(num_elements[0]) != len(num_elements):
                return header + placeholder
            num_elements = num_elements[0]
        else:
            num_elements = 1

        # If all have the same len but some ambiguous return that placeholders
        if len(unambiguous_vals) != len(non_none_vals):
            return header + '\n'.join(
                [placeholder for __ in range(num_elements)])

        # Handle tuple (or single) values position by position
        return_vals_grouped = zip(*[
            [return_element.strip() for return_element in
             return_val.split(',')]
            for return_val in unambiguous_vals])
        return_elements_out = []
        for return_vals_group in return_vals_grouped:
            return_elements_out.append(
                self.parse_return_elements(return_vals_group,
                                           return_element_name,
                                           return_element_type,
                                           placeholder))

        return header + '\n'.join(return_elements_out)
312594
def get_attrib(self, et_node, prefixed_attrib):
        """"""
        prefix, attrib = prefixed_attrib.split(':')
        return et_node.get('{{{0}}}{1}'.format(self.namespaces[prefix],
                                               attrib))
1296027
def parse_at_element(
            self,
            element,  # type: ET.Element
            state  # type: _ProcessorState
    ):
        # type: (...) -> Any
        """"""
        item_iter = element.findall(self._item_processor.element_path)
        return self._parse(item_iter, state)
189231
function (input) {
    if (!canConvert(input)) {
      throw new TypeError(
        input + ' is not a string, or an element/document/fragment node.'
      )
    }

    if (input === '') return ''

    var output = process.call(this, new RootNode(input));
    return postProcess.call(this, output)
  }