Opens a BBC radio tracklisting page based on trailing part of url.
    Returns a lxml ElementTree derived from that page.

    trailing_part_of_url: a string, like the pid or e.g. pid/segments.inc
359740
def open_listing_page(trailing_part_of_url):
    
    base_url = 'http://www.bbc.co.uk/programmes/'
    print("Opening web page: " + base_url + trailing_part_of_url)

    try:
        html = requests.get(base_url + trailing_part_of_url).text
    except (IOError, NameError):
        print("Error opening web page.")
        print("Check network connection and/or programme id.")
        sys.exit(1)

    try:
        return lxml.html.fromstring(html)
    except lxml.etree.ParserError:
        print("Error trying to parse web page.")
        print("Maybe there's no programme listing?")
        sys.exit(1)
362517
def urljoin(*parts):
    
    # first strip extra forward slashes (except http:// and the likes) and
    # create list
    part_list = []
    for part in parts:
        p = str(part)
        if p.endswith('//'):
            p = p[0:-1]
        else:
            p = p.strip('/')
        part_list.append(p)
    # join everything together
    url = '/'.join(part_list)
    return url
1279313
def _scrape_song_lyrics_from_url(self, url):
        
        page = requests.get(url)
        if page.status_code == 404:
            return None

        # Scrape the song lyrics from the HTML
        html = BeautifulSoup(page.text, "html.parser")
        div = html.find("div", class_="lyrics")
        if not div:
            return None # Sometimes the lyrics section isn't found

        # Scrape lyrics if proper section was found on page
        lyrics = div.get_text()
        if self.remove_section_headers:  # Remove [Verse], [Bridge], etc.
            lyrics = re.sub('(\[.*?\])*', '', lyrics)
            lyrics = re.sub('\n{2}', '\n', lyrics)  # Gaps between verses
        return lyrics.strip("\n")
850634
def parse_html(html: str, parser: FragmentParser = None) -> Node:
    
    parser = parser or FragmentParser()
    parser.feed(html)
    return parser.root
41396
function convertUrlSegmentToRegex(segment) {

    // if it has this format "{stuff}" - then it's regex-y
    var beginIdx = segment.indexOf('{');
    var endIdx = segment.indexOf('}');

    if (beginIdx < 0) {
        return segment;
    }

    // if capturing regex and trim trailing "}"
    // this could be a named regex {id:[0-9]+} or just name {companySlug}
    var pieces = segment.split(':');
    if (pieces.length === 2) {
        if ( pieces[1] === (urlPathPatternSymbol + '}') ) {
            // special case where we want to capture the whole remaining path, even slashes, like /search/a/b/c/
            return urlPathPattern;
        }
        else {
            return '(' + pieces[1].substring(0, pieces[1].length - 1) + ')';
        }
    }
    else if (pieces.length === 1) {
        return segment.substring(0, beginIdx) + '[^\\/]+' + segment.substring(endIdx + 1);
    }
    else {
        throw new Error('Weird URL segment- don\'t know how to parse! ' + segment);
    }
}
571125
def full_url(self):
        
        if self.link == '':
            return None
        else:
            return Note._expand_url(self.link, self.subreddit)
1005416
def split(self, url):
        
        parts = url.split('://', 1)
        if len(parts) == 2:
            return parts
        else:
            return (None, url)
382149
def get_ext(url):
    

    parsed = urllib.parse.urlparse(url)
    root, ext = os.path.splitext(parsed.path)
    return ext.lstrip('.')
200366
def xpathNewParserContext(self, str):
        
        ret = libxml2mod.xmlXPathNewParserContext(str, self._o)
        if ret is None:raise xpathError('xmlXPathNewParserContext() failed')
        __tmp = xpathParserContext(_obj=ret)
        return __tmp
988076
def extract_segment_types(urml_document_element, namespace):
    
    segment_types = \
        {namespace+':'+seg.attrib['id']: seg.tag
         for seg in urml_document_element.iter('nucleus', 'satellite')}

    for seg in urml_document_element.iter('segment'):
        seg_id = namespace+':'+seg.attrib['id']
        if seg_id not in segment_types:
            segment_types[seg_id] = 'isolated'
    return segment_types
87650
def element_for_url(cls, url):
        """"""
        response = cls.http_request(url)
        if response.status != 200:
            cls.raise_http_error(response)

        assert response.getheader('Content-Type').startswith('application/xml')

        response_xml = response.read()
        logging.getLogger('recurly.http.response').debug(response_xml)
        response_doc = ElementTree.fromstring(response_xml)

        return response, response_doc
267370
def slug(self):
        
        if self.is_root_node():
            return ""
        if self.slugable and self.parent.parent:
            if not self.page.regex or (self.page.regex and not self.page.show_regex) or self.is_leaf_node():
                return u"{0}/{1}".format(self.parent.slug, self.page.slug)
            elif self.page.regex and self.value_regex and self.page.show_regex:
                return u'{0}/{1}/{2}'.format(self.parent.slug, self.page.slug, self.value_regex)
            elif not self.hide_in_url:
                return u'{0}/{1}'.format(self.parent.slug, self.name)
        elif self.slugable:
            if not self.page.regex or (self.page.regex and not self.page.show_regex) or self.is_leaf_node():
                return u"{0}".format(self.page.slug)
            elif self.page.regex and self.value_regex and self.page.show_regex:
                return u'{0}/{1}'.format(self.page.slug, self.value_regex)
            elif not self.hide_in_url:
                return u'{0}'.format(self.name)
        return ""
578087
def parse_description_xml(location):
    
    class _URLBase(str):
        """ Convenient access to hostname (ip) portion of the URL """
        @property
        def hostname(self):
            return urlsplit(self).hostname

    # """TODO: review error handling on xml"""
    # may want to suppress ParseError in the event that it was caused
    # by a none bridge device although this seems unlikely
    try:
        xml_str = from_url(location)
    except urllib.request.HTTPError as error:
        logger.info("No description for %s: %s", location, error)
        return None, error
    except urllib.request.URLError as error:
        logger.info("No HTTP server for %s: %s", location, error)
        return None, error
    else:
        root = ET.fromstring(xml_str)
        rootname = {'root': root.tag[root.tag.find('{')+1:root.tag.find('}')]}
        baseip = root.find('root:URLBase', rootname).text
        device = root.find('root:device', rootname)
        serial = device.find('root:serialNumber', rootname).text
        # anicon = device.find('root:iconList', rootname).find('root:icon', rootname)
        # imgurl = anicon.find('root:url', rootname).text

        # Alternatively, could look directly in the modelDescription field
        if all(x in xml_str.lower() for x in ['philips', 'hue']):
            return serial, _URLBase(baseip)
        else:
            return None, None
1191787
private static String url(final Track track) {
		return track.getLinks().isEmpty()
			? null
			: track.getLinks().get(0).getHref().toString();
	}
608058
def iter_links_object_element(cls, element):
        '''
        '''
        base_link = element.attrib.get('codebase', None)

        if base_link:
            # lxml returns codebase as inline
            link_type = element.attrib.get(base_link)
            yield LinkInfo(
                element=element, tag=element.tag, attrib='codebase',
                link=base_link,
                inline=True, linked=False,
                base_link=None,
                value_type='plain',
                link_type=link_type
            )

        for attribute in ('code', 'src', 'classid', 'data'):
            if attribute in element.attrib:
                link_type = identify_link_type(element.attrib.get(attribute))
                yield LinkInfo(
                    element=element, tag=element.tag, attrib=attribute,
                    link=element.attrib.get(attribute),
                    inline=True, linked=False,
                    base_link=base_link,
                    value_type='plain',
                    link_type=link_type
                )

        if 'archive' in element.attrib:
            for match in re.finditer(r'[^ ]+', element.attrib.get('archive')):
                value = match.group(0)
                link_type = identify_link_type(value)
                yield LinkInfo(
                    element=element, tag=element.tag, attrib='archive',
                    link=value,
                    inline=True, linked=False,
                    base_link=base_link,
                    value_type='list',
                    link_type=link_type
                )
1333787
def xpath(self, xpath_str):
        
        return super(BaseOxmlElement, self).xpath(
            xpath_str, namespaces=_nsmap
        )
421912
def url(self):
        
        el_FLocat = self._el.find(TAG_METS_FLOCAT)
        if el_FLocat is not None:
            return el_FLocat.get("{%s}href" % NS["xlink"])
        return ''