Parse a block of text, splitting it into its url and non-url
    components.
434688
def parse_text_urls(mesg):
    """"""

    rval = []

    loc = 0

    for match in URLRE.finditer(mesg):
        if loc < match.start():
            rval.append(Chunk(mesg[loc:match.start()], None))
        # Turn email addresses into mailto: links
        email = match.group("email")
        if email and "mailto" not in email:
            mailto = "mailto:{}".format(email)
        else:
            mailto = match.group(1)
        rval.append(Chunk(None, mailto))
        loc = match.end()

    if loc < len(mesg):
        rval.append(Chunk(mesg[loc:], None))

    return rval
179674
function split(url) {
  assert.equal(typeof url, 'string', 'url-querystring: url should be a string');

  var res = {};
  var nw = url.split('?');

  res.url = nw[0];
  res.qs = nw.length == 2
    ? qs.parse(nw[1])
    : {};

  return res;
}
1145973
function parse($text) {
		$text=parent::parse($text);
		// Build tree structure
		for ($ptr=0,$w=5,$len=strlen($text),$tree=[],$tmp='';$ptr<$len;)
			if (preg_match('/^(.{0,'.$w.'}?)<(\/?)(?:F3:)?'.
				'('.$this->tags.')\b((?:\s+[\w.:@!-]+'.
				'(?:\h*=\h*(?:"(?:.*?)"|\'(?:.*?)\'))?|'.
				'\h*\{\{.+?\}\})*)\h*(\/?)>/is',
				substr($text,$ptr),$match)) {
				if (strlen($tmp) || $match[1])
					$tree[]=$tmp.$match[1];
				// Element node
				if ($match[2]) {
					// Find matching start tag
					$stack=[];
					for($i=count($tree)-1;$i>=0;$i--) {
						$item=$tree[$i];
						if (is_array($item) &&
							array_key_exists($match[3],$item) &&
							!isset($item[$match[3]][0])) {
							// Start tag found
							$tree[$i][$match[3]]+=array_reverse($stack);
							$tree=array_slice($tree,0,$i+1);
							break;
						}
						else $stack[]=$item;
					}
				}
				else {
					// Start tag
					$node=&$tree[][$match[3]];
					$node=[];
					if ($match[4]) {
						// Process attributes
						preg_match_all(
							'/(?:(\{\{.+?\}\})|([^\s\/"\'=]+))'.
							'\h*(?:=\h*(?:"(.*?)"|\'(.*?)\'))?/s',
							$match[4],$attr,PREG_SET_ORDER);
						foreach ($attr as $kv)
							if (!empty($kv[1]) && !isset($kv[3]) && !isset($kv[4]))
								$node['@attrib'][]=$kv[1];
							else
								$node['@attrib'][$kv[1]?:$kv[2]]=
									(isset($kv[3]) && $kv[3]!==''?
										$kv[3]:
										(isset($kv[4]) && $kv[4]!==''?
											$kv[4]:NULL));
					}
				}
				$tmp='';
				$ptr+=strlen($match[0]);
				$w=5;
			}
			else {
				// Text node
				$tmp.=substr($text,$ptr,$w);
				$ptr+=$w;
				if ($w<50)
					$w++;
			}
		if (strlen($tmp))
			// Append trailing text
			$tree[]=$tmp;
		// Break references
		unset($node);
		return $tree;
	}
1188080
function parse(url) {
  ['?', '#'].forEach(function(separator) {
    var index = url.indexOf(separator);
    if (index !== -1) url = url.substring(0, index);
  });
  return url;
}
278643
def _parse(self, text, i):
        """"""

        m = self.start_dict_re.match(text, i)
        if m:
            parsed = m.group(0)
            i += len(parsed)
            return self._parse_dict(text, i)

        m = self.start_list_re.match(text, i)
        if m:
            parsed = m.group(0)
            i += len(parsed)
            return self._parse_list(text, i)

        m = self.value_re.match(text, i)
        if m:
            parsed = m.group(0)
            i += len(parsed)
            if hasattr(self.current_type, "read"):
                reader = self.current_type()
                # Give the escaped value to `read` to be symetrical with
                # `plistValue` which handles the escaping itself.
                value = reader.read(m.group(1))
                return value, i

            value = self._trim_value(m.group(1))

            if self.current_type in (None, dict, OrderedDict):
                self.current_type = self._guess_current_type(parsed, value)

            if self.current_type == bool:
                value = bool(int(value))  # bool(u'0') returns True
                return value, i

            value = self.current_type(value)

            return value, i

        m = self.hex_re.match(text, i)
        if m:
            from glyphsLib.types import BinaryData

            parsed, value = m.group(0), m.group(1)
            decoded = BinaryData.fromHex(value)
            i += len(parsed)
            return decoded, i
        else:
            self._fail("Unexpected content", text, i)
1327052
private function parseBlock($text, &$lines)
    {
        $lines = explode("\n", $text);
        $this->_blocks = array();
        $this->_current = 'normal';
        $this->_pos = -1;
        $state = array(
            'special'   =>  implode("|", array_keys($this->_specialWhiteList)),
            'empty'     =>  0,
            'html'      =>  false
        );
        // analyze by line
        foreach ($lines as $key => $line) {
            $block = $this->getBlock();
            $args = array($block, $key, $line, &$state, $lines);
            if ($this->_current != 'normal') {
                $pass = call_user_func_array($this->_parsers[$this->_current], $args);
                if (!$pass) {
                    continue;
                }
            }
            foreach ($this->_parsers as $name => $parser) {
                if ($name != $this->_current) {
                    $pass = call_user_func_array($parser, $args);
                    if (!$pass) {
                        break;
                    }
                }
            }
        }
        return $this->optimizeBlocks($this->_blocks, $lines);
    }
855004
def tokenize(self, text, context=0, skip_style_tags=False):
        """"""
        split = self.regex.split(text)
        self._text = [segment for segment in split if segment]
        self._head = self._global = self._depth = 0
        self._bad_routes = set()
        self._skip_style_tags = skip_style_tags

        try:
            tokens = self._parse(context)
        except BadRoute:  # pragma: no cover (untestable/exceptional case)
            raise ParserError("Python tokenizer exited with BadRoute")
        if self._stacks:  # pragma: no cover (untestable/exceptional case)
            err = "Python tokenizer exited with non-empty token stack"
            raise ParserError(err)
        return tokens
1179396
def parse(url):
    
    parts = split(url)
    if parts.scheme:
        username, password, host, port = split_netloc(parts.netloc)
        subdomain, domain, tld = split_host(host)
    else:
        username = password = subdomain = domain = tld = port = ''
    return URL(parts.scheme, username, password, subdomain, domain, tld,
               port, parts.path, parts.query, parts.fragment, url)
178349
def parse(self, text):
        
        gen = self.lexer.lex(text)
        next_val_fn = partial(next, *(gen,))
        token = next_val_fn()
        return self.rule_svg_path(next_val_fn, token)
620966
def parse(self, text):
        
        root = ET.fromstring(text)
        for elm in root.findall('{http://www.iana.org/assignments}registry'):
            for record in elm.findall('{http://www.iana.org/assignments}record'):
                for fileElm in record.findall('{http://www.iana.org/assignments}file'):
                    if fileElm.get('type') == 'template':
                        mimeType = fileElm.text.strip()
                        yield mimeType
                        break
998411
def _parse_text(self, page_text):
        """"""

        # 1 sanitize: remove leading blank lines
        # 2 separate "config text" from content, store content
        # 3 convert config text + \n to obtain Meta, this is the config.

        lines = page_text.split('\n')
        i = 0
        while lines[i].strip() == '':
            i += 1
        if i > 0: # i points to the first non-blank line.  Else, i is 0, there are no leading blank lines
            lines = lines[i:]  #remove leading blank lines

        i = 0
        while lines[i].strip() != '':
            i += 1
            # i points to the first blank line
        cfg_lines = '\n'.join(lines[0:i + 1])  #config lines, plus the empty line

        md = markdown.Markdown(extensions=['meta','fenced_code', 'codehilite'],output_format="html5")
        md.convert(cfg_lines)   # need to trigger the conversion to obtain md.Meta

        self._config = md.Meta
        self._content =  '\n'.join(lines[i+1:])
1352827
def full_split(text, regex):
    
    while text:
        m = regex.search(text)
        if not m:
            yield text
            break
        left = text[:m.start()]
        middle = text[m.start():m.end()]
        right = text[m.end():]
        if left:
            yield left
        if middle:
            yield middle
        text = right
338893
def parse(text) -> Optional['Response']:
        """"""

        # Trim the start and end markers, and ensure only lowercase is used
        if text.startswith(MARKER_START) and text.endswith(MARKER_END):
            text = text[1:len(text)-1].lower()

        # No-op; can just ignore these
        if not text:
            return None

        if text.startswith(CMD_DATETIME):
            return DateTimeResponse(text)

        elif text.startswith(CMD_OPMODE):
            return OpModeResponse(text)

        elif text.startswith(CMD_DEVBYIDX_PREFIX):
            if RESPONSE_ERROR == text[2:] or text[2:4] == '00':
                return DeviceNotFoundResponse(text)
            return DeviceInfoResponse(text)

        elif text.startswith(CMD_DEVICE_PREFIX):
            action = next((a for a in [ACTION_ADD, ACTION_DEL, ACTION_SET]
                           if a == text[2:3]), ACTION_NONE)
            args = text[2+len(action):]
            if RESPONSE_ERROR == args:
                return DeviceNotFoundResponse(text)
            elif action == ACTION_ADD:
                if not args:
                    return DeviceAddingResponse(text)
                return DeviceAddedResponse(text)
            elif action == ACTION_SET:
                return DeviceChangedResponse(text)
            elif action == ACTION_DEL:
                return DeviceDeletedResponse(text)
            else:
                return DeviceInfoResponse(text)

        elif text.startswith(CMD_CLEAR_STATUS):
            return ClearedStatusResponse(text)

        elif text.startswith(CMD_ROMVER):
            return ROMVersionResponse(text)

        elif text.startswith(CMD_EXIT_DELAY):
            return ExitDelayResponse(text)

        elif text.startswith(CMD_ENTRY_DELAY):
            return EntryDelayResponse(text)

        elif text.startswith(CMD_SWITCH_PREFIX) and is_ascii_hex(text[1:2]):
            return SwitchResponse(text)

        elif text.startswith(CMD_EVENT_LOG):
            if RESPONSE_ERROR == text[2:]:
                return EventLogNotFoundResponse(text)
            return EventLogResponse(text)

        elif text.startswith(CMD_SENSOR_LOG):
            if RESPONSE_ERROR == text[2:]:
                return SensorLogNotFoundResponse(text)
            return SensorLogResponse(text)

        else:
            raise ValueError("Response not recognised: " + text)
1044368
def _load_text(handle, split=False, encoding="utf-8"):
    """"""
    string = handle.read().decode(encoding)
    return string.splitlines() if split else string
87666
def url_split (url):
    
    scheme, netloc = urllib.splittype(url)
    host, document = urllib.splithost(netloc)
    port = default_ports.get(scheme, 0)
    if host:
        host = host.lower()
        host, port = splitport(host, port=port)
    return scheme, host, port, document
738308
def parse_text(self,text):
        """"""
        try:
            return self.rProgram.ignore(cStyleComment).parseString(text, parseAll=True)
        except SemanticException as err:
            print(err)
            exit(3)
        except ParseException as err:
            print(err)
            exit(3)
137194
def _read_parsed(self, lines):
        
        self.log(u"Parsing fragments from parsed text format")
        pairs = []
        for line in lines:
            pieces = line.split(gc.PARSED_TEXT_SEPARATOR)
            if len(pieces) == 2:
                identifier = pieces[0].strip()
                text = pieces[1].strip()
                if len(identifier) > 0:
                    pairs.append((identifier, [text]))
        self._create_text_fragments(pairs)