Extract dom information from detector file
487831
def _parse_doms(self):
        """"""
        self.print("Reading PMT information...")
        self._det_file.seek(0, 0)
        self._readline()
        pmts = defaultdict(list)
        pmt_index = 0
        while True:
            line = self._readline()

            if line == '':
                self.print("Done.")
                break

            try:
                dom_id, du, floor, n_pmts = split(line, int)
            except ValueError:
                continue

            if du != self._current_du:
                log.debug("Next DU, resetting floor to 1.")
                self._current_du = du
                self.dus.append(du)
                self._current_floor = 1
                if du == 1 and floor == -1:
                    log.warning(
                        "Floor ID is -1 (Jpp conversion bug), "
                        "using our own floor ID!"
                    )
            else:
                self._current_floor += 1

            if floor == -1:
                log.debug("Setting floor ID to our own ID")
                floor = self._current_floor

            self.doms[dom_id] = (du, floor, n_pmts)

            if self.n_pmts_per_dom is None:
                self.n_pmts_per_dom = n_pmts

            if self.n_pmts_per_dom != n_pmts:
                log.warning(
                    "DOMs with different number of PMTs are "
                    "detected, this can cause some unexpected "
                    "behaviour."
                )

            for i in range(n_pmts):
                raw_pmt_info = self._readline()
                pmt_info = raw_pmt_info.split()
                pmt_id, x, y, z, rest = unpack_nfirst(pmt_info, 4)
                dx, dy, dz, t0, rest = unpack_nfirst(rest, 4)
                pmt_id = int(pmt_id)
                omkey = (du, floor, i)
                pmts['pmt_id'].append(int(pmt_id))
                pmts['pos_x'].append(float(x))
                pmts['pos_y'].append(float(y))
                pmts['pos_z'].append(float(z))
                pmts['dir_x'].append(float(dx))
                pmts['dir_y'].append(float(dy))
                pmts['dir_z'].append(float(dz))
                pmts['t0'].append(float(t0))
                pmts['du'].append(int(du))
                pmts['floor'].append(int(floor))
                pmts['channel_id'].append(int(i))
                pmts['dom_id'].append(int(dom_id))
                if self.version == 'v3' and rest:
                    status, rest = unpack_nfirst(rest, 1)
                    pmts['status'].append(int(status))
                if rest:
                    log.warning("Unexpected PMT values: {0}".format(rest))
                self._pmt_index_by_omkey[omkey] = pmt_index
                self._pmt_index_by_pmt_id[pmt_id] = pmt_index
                pmt_index += 1

        self.pmts = Table(pmts, name='PMT')
138798
def _ExtractHuntIdFromPath(entry, event):
  """"""
  match = re.match(r".*hunt/([^/]+).*", entry.http_request_path)
  if match:
    event.urn = "aff4:/hunts/{}".format(match.group(1))
347075
def extract_message_info():
    """"""
    base_path = BASE_PACKAGE.replace('.', '/')
    filename = os.path.join(base_path, 'ProtocolMessage.proto')

    with open(filename, 'r') as file:
        types_found = False

        for line in file:
            stripped = line.lstrip().rstrip()

            # Look for the Type enum
            if stripped == 'enum Type {':
                types_found = True
                continue
            elif types_found and stripped == '}':
                break
            elif not types_found:
                continue

            constant = stripped.split(' ')[0]
            title = constant.title().replace(
                '_', '').replace('Hid', 'HID')  # Hack...
            accessor = title[0].lower() + title[1:]

            if not os.path.exists(os.path.join(base_path, title + '.proto')):
                continue

            yield MessageInfo(
                title + '_pb2', title, accessor, constant)
303930
function getClickDataset(path) {
            var el;
            for (var i = 0; i < path.length; i++) {
                el = path[i];
                if (el.dataset.nctr !== undefined) {
                    return el.dataset;
                }
            }
            return null;
        }
406538
def get_extracted_events(fnames):
    """"""
    event_list = []
    for fn in fnames:
        tp = trips.process_xml_file(fn)
        ed = tp.extracted_events
        for k, v in ed.items():
            event_list += v
    return event_list
311814
function extractTodoTitle (content, conf) {
  var result = null;

  var labels = {};
  _.each(conf, function (value, key) {
    if (value && key.match(/^label\./)) {
      var trigger = key.substring(6);
      if (conf["label-whitespace"]) {
        trigger += " ";
      }
      labels[trigger] = value;
    }
  });

  if (_.isString(content)) {
    _.find(Object.keys(labels), function (trigger) {
      var index;
      if (conf["case-sensitive"]) {
        index = content.indexOf(trigger);
      } else {
        index = content.toUpperCase().indexOf(trigger.toUpperCase());
      }

      if (index !== -1) {
        var title = content.substring(index + trigger.length).trim();
        var issue = null;
        if (title && !isCode(title)) {
          var match = title.match(/^\s+#(\d+)\s+/);
          if (match) {
            issue = match[1];
            title = title.substring(match[0].length);
          }
          result = {
            "title":  title,
            "label":  labels[trigger],
            "issue":  Number(issue)
          };
        }
        return true; // break
      }
    });
  }

  return result;
}
120267
def detect(self, obj):
        """"""
        links = obj.get(LINKS_KEY, {})

        for detector in [LATEST, DRAFT_3]:
            if detector.draft.curies_rel in links:
                return detector.detect(obj)

        return LATEST.detect(obj)
1278836
function extractInline($) {
  var scripts = [];
  $('script:not([src])').each(function() {
    var el  = $(this);
    var src = el.text();
    var closestPolymerElement = el.closest('polymer-element');
    if(closestPolymerElement.length) {
      src = fixPolymerInvocation(src, $(closestPolymerElement).attr('name'))
    }
    scripts.push(src);
    el.remove();
  })
  return scripts;
}
914102
async function getWidgetsFromXml(target) {
  const $ = await parseFile(target)
  const widgets = []
  let widget

  $('node').each((i, elem) => {
    const node = $(elem)
    widget = new Widget()
    widget.text = node.attr('text')
    widget.resourceId = node.attr('resource-id')
    widget.className = node.attr('class')
    widget.packageName = node.attr('package')
    widget.contentDesc = node.attr('content-desc')
    widget.checkable = node.attr('checkable')
    widget.checked = node.attr('checked')
    widget.clickable = node.attr('clickable')
    widget.enabled = node.attr('enabled')
    widget.focusable = node.attr('focusable')
    widget.focused = node.attr('focused')
    widget.scrollable = node.attr('scrollable')
    widget.longClickable = node.attr('long-clickable')
    widget.password = node.attr('password')
    widget.selected = node.attr('selected')
    widget.bounds = node.attr('bounds')
    widgets.push(widget)
  })

  return widgets
}
157485
def _to_DOM(self):
        
        root_node = ET.Element("observation")
        reception_time_node = ET.SubElement(root_node, "reception_time")
        reception_time_node.text = str(self._reception_time)
        root_node.append(self._location._to_DOM())
        root_node.append(self._weather._to_DOM())
        return root_node
539205
private static String getDescriptionWithoutHtml(DetectorFactory factory) {
        String detailHTML = factory.getDetailHTML();
        // cut beginning and the end of the html document
        detailHTML = trimHtml(detailHTML, "<BODY>", "</BODY>");
        // replace any amount of white space with newline between through one
        // space
        detailHTML = detailHTML.replaceAll("\\s*[\\n]+\\s*", " ");
        // remove all valid html tags
        detailHTML = detailHTML.replaceAll("<[a-zA-Z]+>", "");
        detailHTML = detailHTML.replaceAll("</[a-zA-Z]+>", "");
        // convert some of the entities which are used in current FB
        // messages.xml
        detailHTML = detailHTML.replaceAll("&nbsp;", "");
        detailHTML = detailHTML.replaceAll("&lt;", "<");
        detailHTML = detailHTML.replaceAll("&gt;", ">");
        detailHTML = detailHTML.replaceAll("&amp;", "&");
        return detailHTML.trim();
    }
304952
def getElementText(self, node, preserve_ws=None):
        """"""
        result = []
        for child in node.childNodes:
            nodetype = child.nodeType
            if nodetype == child.TEXT_NODE or \
               nodetype == child.CDATA_SECTION_NODE:
                result.append(child.nodeValue)
        value = join(result, '')
        if preserve_ws is None:
            value = strip(value)
        return value
1292925
def detect_all(byte_str):
    
    if not isinstance(byte_str, bytearray):
        if not isinstance(byte_str, bytes):
            raise TypeError('Expected object of type bytes or bytearray, got: '
                            '{0}'.format(type(byte_str)))
        else:
            byte_str = bytearray(byte_str)

    detector = UniversalDetector()
    detector.feed(byte_str)
    detector.close()

    if detector._input_state == InputState.HIGH_BYTE:
        results = []
        for prober in detector._charset_probers:
            if prober.get_confidence() > detector.MINIMUM_THRESHOLD:
                charset_name = prober.charset_name
                lower_charset_name = prober.charset_name.lower()
                # Use Windows encoding name instead of ISO-8859 if we saw any
                # extra Windows-specific bytes
                if lower_charset_name.startswith('iso-8859'):
                    if detector._has_win_bytes:
                        charset_name = detector.ISO_WIN_MAP.get(lower_charset_name,
                                                            charset_name)
                results.append({
                    'encoding': charset_name,
                    'confidence': prober.get_confidence()
                })
        if len(results) > 0:
            return sorted(results, key=lambda result: -result['confidence'])

    return [detector.result]
873326
def detect(agent, fill_none=False):
    
    result = dict(platform=dict(name=None, version=None))
    _suggested_detectors = []

    for info_type in detectorshub:
        detectors = _suggested_detectors or detectorshub[info_type]
        for detector in detectors:
            try:
                detector.detect(agent, result)
            except Exception as _err:
                pass

    if fill_none:
        for outer_key in ('os', 'browser'):
            outer_value = result.setdefault(outer_key, dict())
            for inner_key in ('name', 'version'):
                outer_value.setdefault(inner_key, None)

    return result
798104
function getDOMPath(node, dontGoUpTheDom /* = false */ ) {
		var path = [],
			entry = '';

		if (node === window) {
			return 'window';
		}

		while (node instanceof Node) {
			// div
			entry = node.nodeName.toLowerCase();

			// shorten the path a bit
			if (['body', 'head', 'html'].indexOf(entry) > -1) {
				path.push(entry);
				break;
			}

			if (node instanceof DocumentFragment) {
				entry = 'DocumentFragment';
			}

			// div#foo
			if (node.id && node.id !== '') {
				entry += '#' + node.id;
			}
			// div#foo.bar.test
			else if (typeof node.className === 'string' && node.className !== '') {
				entry += '.' + node.className.trim().replace(/\s+/g, '.');
			}
			// div[0] <- index of child node
			else if (node.parentNode instanceof Node) {
				entry += '[' + Math.max(0, Array.prototype.indexOf.call(node.parentNode.children || node.parentNode.childNodes, node)) + ']';
			}

			path.push(entry);

			if (dontGoUpTheDom === true) {
				break;
			}

			// go up the DOM
			node = node && node.parentNode;
		}

		return (path.length > 0) ? path.reverse().join(' > ') : false;
	}
746596
def scan(s):
    
    line = 1
    linepos = 1
    pos = 0
    toks = []
    while pos < len(s):
        matched = False
        for (tokname, r) in patterns:
            m = r.match(s, pos)
            if m is not None:
                # found a matching token
                v = m.group(0)
                prec = _preceding_token(toks)
                if tokname == 'STAR' and prec is not None and _is_special(prec):
                    # XPath 1.0 spec, 3.7 special rule 1a
                    # interpret '*' as a wildcard
                    tok = XPathTok('wildcard', v, line, linepos)
                elif (tokname == 'name' and
                      prec is not None and not _is_special(prec) and
                      v in operators):
                    # XPath 1.0 spec, 3.7 special rule 1b
                    # interpret the name as an operator
                    tok = XPathTok(operators[v], v, line, linepos)
                elif tokname == 'name':
                    # check if next token is '('
                    if re_open_para.match(s, pos + len(v)):
                        # XPath 1.0 spec, 3.7 special rule 2
                        if v in node_types:
                            # XPath 1.0 spec, 3.7 special rule 2a
                            tok = XPathTok('node_type', v, line, linepos)
                        else:
                            # XPath 1.0 spec, 3.7 special rule 2b
                            tok = XPathTok('function_name', v, line, linepos)
                    # check if next token is '::'
                    elif re_axis.match(s, pos + len(v)):
                        # XPath 1.0 spec, 3.7 special rule 3
                        if v in axes:
                            tok = XPathTok('axis', v, line, linepos)
                        else:
                            e = "unknown axis %s" % v
                            raise XPathError(e, line, linepos)
                    else:
                        tok = XPathTok('name', v, line, linepos)
                else:
                    tok = XPathTok(tokname, v, line, linepos)
                if tokname == '_whitespace':
                    n = v.count('\n')
                    if n > 0:
                        line = line + n
                        linepos = len(v) - v.rfind('\n')
                    else:
                        linepos += len(v)
                else:
                    linepos += len(v)
                pos += len(v)
                toks.append(tok)
                matched = True
                break
        if matched == False:
            # no patterns matched
            raise XPathError('syntax error', line, linepos)
    return toks
943803
def _extract_sel_info(sel):
    """"""
    from cssselect2.parser import (CombinedSelector, CompoundSelector,
                                   PseudoClassSelector,
                                   FunctionalPseudoClassSelector)
    steps = []
    extras = []
    if isinstance(sel, CombinedSelector):
        lstep, lextras = _extract_sel_info(sel.left)
        rstep, rextras = _extract_sel_info(sel.right)
        steps = lstep + rstep
        extras = lextras + rextras
    elif isinstance(sel, CompoundSelector):
        for ssel in sel.simple_selectors:
            s, e = _extract_sel_info(ssel)
            steps.extend(s)
            extras.extend(e)
    elif isinstance(sel, FunctionalPseudoClassSelector):
        if sel.name == 'pass':
            steps.append(serialize(sel.arguments).strip('"\''))
    elif isinstance(sel, PseudoClassSelector):
        if sel.name == 'deferred':
            extras.append('deferred')
    return (steps, extras)