Discover the hub url and topic url of a given url. Firstly, by inspecting
    the page's headers, secondarily by inspecting the content for link tags.

    timeout determines how long to wait for the url to load. It defaults to 3.
962950
def discover(url, timeout=None):
    
    resp = get_content({'REQUEST_TIMEOUT': timeout}, url)

    parser = LinkParser()
    parser.hub_url = (resp.links.get('hub') or {}).get('url')
    parser.topic_url = (resp.links.get('self') or {}).get('url')
    try:
        parser.updated()
        for chunk in resp.iter_content(chunk_size=None, decode_unicode=True):
            parser.feed(chunk)
        parser.close()
    except Finished:
        return {'hub_url': parser.hub_url, 'topic_url': parser.topic_url}

    raise DiscoveryError("Could not find hub url in topic page")
986807
def _discovery(self):
        
        data = self.cluster_nodes()
        self.cluster_name = data["cluster_name"]
        for _, nodedata in list(data["nodes"].items()):
            server = nodedata['http_address'].replace("]", "").replace("inet[", "http:/")
            if server not in self.servers:
                self.servers.append(server)
        self._init_connection()
        return self.servers
291823
async def probeUrl(self, url, response_headers=None):
    
    self.logger.debug("Probing URL '%s'..." % (url))
    headers = {}
    self.updateHttpHeaders(headers)
    resp_headers = {}
    resp_ok = await self.http.isReachable(url,
                                          headers=headers,
                                          response_headers=resp_headers,
                                          cache=__class__.probe_cache)

    if response_headers is not None:
      response_headers.update(resp_headers)

    return resp_ok
812996
def build_url_parts (self):
        
        # check userinfo@host:port syntax
        self.userinfo, host = urllib.splituser(self.urlparts[1])
        port = urlutil.default_ports.get(self.scheme, 0)
        host, port = urlutil.splitport(host, port=port)
        if port is None:
            raise LinkCheckerError(_("URL host %(host)r has invalid port") %
                    {"host": host})
        self.port = port
        # set host lowercase
        self.host = host.lower()
        if self.scheme in scheme_requires_host:
            if not self.host:
                raise LinkCheckerError(_("URL has empty hostname"))
            self.check_obfuscated_ip()
        if not self.port or self.port == urlutil.default_ports.get(self.scheme):
            host = self.host
        else:
            host = "%s:%d" % (self.host, self.port)
        if self.userinfo:
            self.urlparts[1] = "%s@%s" % (self.userinfo, host)
        else:
            self.urlparts[1] = host
        # safe anchor for later checking
        self.anchor = self.urlparts[4]
        if self.anchor is not None:
            assert isinstance(self.anchor, unicode), repr(self.anchor)
616654
function getUrl (url) {
  var opt = {
    url: url
  , timeout: 10000 // 10 seconds
  }
  ;
  return new Promise(function(resolve, reject){
    request(opt, function(err, res, body){
      if (err) { return reject(err); }
      resolve(body)
    });
  });
}
115331
public void goToURL(String url) {
        String action = "Loading " + url;
        String expected = "Loaded " + url;
        double start = System.currentTimeMillis();
        try {
            driver.get(url);
        } catch (Exception e) {
            log.warn(e);
            reporter.fail(action, expected, "Fail to Load " + url + ". " + e.getMessage());
            return;
        }
        double timeTook = System.currentTimeMillis() - start;
        timeTook = timeTook / 1000;
        reporter.pass(action, expected, "Loaded " + url + " in " + timeTook + SECONDS);
        acceptCertificate();
    }
1052031
def browse
      timeout(5) do
        nodes = []
        DNSSD.browse!(SEARCH) do |node|
          nodes << node
          next if node.flags.more_coming?

          nodes.each do |node|
            resolve(node)
          end

          break
        end
      end
    rescue Timeout::Error => e
      raise NoDevicesFound
    end
573506
function url(path) {
        if (path) {
            if (_.startsWith(path, "/")) {
                if (!_urlPrefix) {
                    // lets discover the base url via the base html element
                    _urlPrefix = $('base').attr('href') || "";
                    if (_.endsWith(_urlPrefix, '/')) {
                        _urlPrefix = _urlPrefix.substring(0, _urlPrefix.length - 1);
                    }
                }
                if (_urlPrefix) {
                    return _urlPrefix + path;
                }
            }
        }
        return path;
    }
525169
def _get_url(url):
        
        if isinstance(url, urlparse.ParseResult):
            return urlparse.urlunparse(url)
        else:
            return url
604737
def click_link_text(self, link_text, timeout=settings.SMALL_TIMEOUT):
        
        # If using phantomjs, might need to extract and open the link directly
        if self.timeout_multiplier and timeout == settings.SMALL_TIMEOUT:
            timeout = self.__get_new_timeout(timeout)
        if self.browser == 'phantomjs':
            if self.is_link_text_visible(link_text):
                element = self.wait_for_link_text_visible(
                    link_text, timeout=timeout)
                element.click()
                return
            self.open(self.__get_href_from_link_text(link_text))
            return
        if not self.is_link_text_present(link_text):
            self.wait_for_link_text_present(link_text, timeout=timeout)
        pre_action_url = self.get_current_url()
        try:
            element = self.wait_for_link_text_visible(
                link_text, timeout=0.2)
            self.__demo_mode_highlight_if_active(link_text, by=By.LINK_TEXT)
            try:
                element.click()
            except (StaleElementReferenceException, ENI_Exception):
                self.wait_for_ready_state_complete()
                time.sleep(0.05)
                element = self.wait_for_link_text_visible(
                    link_text, timeout=timeout)
                element.click()
        except Exception:
            found_css = False
            text_id = self.get_link_attribute(link_text, "id", False)
            if text_id:
                link_css = '[id="%s"]' % link_text
                found_css = True

            if not found_css:
                href = self.__get_href_from_link_text(link_text, False)
                if href:
                    if href.startswith('/') or page_utils.is_valid_url(href):
                        link_css = '[href="%s"]' % href
                        found_css = True

            if not found_css:
                ngclick = self.get_link_attribute(link_text, "ng-click", False)
                if ngclick:
                    link_css = '[ng-click="%s"]' % ngclick
                    found_css = True

            if not found_css:
                onclick = self.get_link_attribute(link_text, "onclick", False)
                if onclick:
                    link_css = '[onclick="%s"]' % onclick
                    found_css = True

            success = False
            if found_css:
                if self.is_element_visible(link_css):
                    self.click(link_css)
                    success = True
                else:
                    # The link text might be hidden under a dropdown menu
                    success = self.__click_dropdown_link_text(
                        link_text, link_css)

            if not success:
                element = self.wait_for_link_text_visible(
                    link_text, timeout=settings.MINI_TIMEOUT)
                element.click()

        if settings.WAIT_FOR_RSC_ON_CLICKS:
            self.wait_for_ready_state_complete()
        if self.demo_mode:
            if self.driver.current_url != pre_action_url:
                self.__demo_mode_pause_if_active()
            else:
                self.__demo_mode_pause_if_active(tiny=True)
631106
def waitForURL(url, max_seconds=None):
    

    startTime = datetime.now()
    while True:
        response = None
        try:
            response = urllib2.urlopen(HEADREQUEST(url))
        except urllib2.URLError:
            pass
        if response is not None and isinstance(response, urllib2.addinfourl):
            if response.getcode() == 200:
                # We're done, yay!
                return
        timeNow = datetime.now()
        timePassed = timeNow - startTime
        if max_seconds and max_seconds < timePassed.seconds:
            return
        print("Waiting on URL %s for %s so far" % (url, timePassed))
        time.sleep(30)
773454
def find_pingback_urls(self, urls):
        
        pingback_urls = {}

        for url in urls:
            try:
                page = urlopen(url)
                headers = page.info()

                server_url = headers.get('X-Pingback')

                if not server_url:
                    content_type = headers.get('Content-Type', '').split(
                        ';')[0].strip().lower()
                    if content_type in ['text/html', 'application/xhtml+xml']:
                        server_url = self.find_pingback_href(
                            page.read(5 * 1024))

                if server_url:
                    server_url_splitted = urlsplit(server_url)
                    if not server_url_splitted.netloc:
                        url_splitted = urlsplit(url)
                        server_url = '%s://%s%s' % (url_splitted.scheme,
                                                    url_splitted.netloc,
                                                    server_url)
                    pingback_urls[url] = server_url
            except IOError:
                pass
        return pingback_urls
376209
function(url, callback) {
    var link = document.createElement('link');
    link.type = 'text/css';
    link.rel = 'stylesheet';
    if (useOnload)
      link.onload = function() {
        link.onload = function() {};
        // for style dimensions queries, a short delay can still be necessary
        setTimeout(callback, 7);
      }
    else
      var loadInterval = setInterval(function() {
        for (var i = 0; i < document.styleSheets.length; i++) {
          var sheet = document.styleSheets[i];
          if (sheet.href == link.href) {
            clearInterval(loadInterval);
            return callback();
          }
        }
      }, 10);
    link.href = url;
    head.appendChild(link);
  }
759824
def get_topic(self):
        
        pk = self.kwargs.get(self.topic_pk_url_kwarg, None)
        if not pk:
            return
        if not hasattr(self, '_topic'):
            self._topic = get_object_or_404(Topic, pk=pk)
        return self._topic
809790
def parse_url(url):
    
    if url.startswith(('http', 'https', '//')):
        if url.startswith('//'):
            return urlparse.urlparse(url, scheme='http')
        else:
            return urlparse.urlparse(url)
    else:
        return urlparse.urlparse(urlparse.urljoin('http://', url))
583533
def _get_connection_from_url(self, url, timeout, **kwargs):
        """"""

        url = self._decode_url(url, "")

        if url.scheme == 'http' or url.scheme == 'https':
            return HttpConnection(url.geturl(), timeout=timeout, **kwargs)
        else:
            if sys.version_info[0] > 2:
                raise ValueError("Thrift transport is not available "
                                 "for Python 3")

            try:
                from thrift_connection import ThriftConnection
            except ImportError:
                raise ImportError("The 'thrift' python package "
                                    "does not seem to be installed.")
            return ThriftConnection(url.hostname, url.port,
                                    timeout=timeout, **kwargs)
237192
def _initURL(self,
                 org_url,
                 referer_url):
        
        if org_url is not None and org_url != '':
            if not org_url.startswith('http://') and not org_url.startswith('https://'):
                org_url = 'https://' + org_url
            self._org_url = org_url

            if self._org_url.lower().find('/sharing/rest') > -1:
                self._url = self._org_url
            else:
                self._url = self._org_url + "/sharing/rest"

            if self._url.startswith('http://'):
                self._surl = self._url.replace('http://', 'https://')
            else:
                self._surl = self._url

            parsed_url = urlparse(self._org_url)
            self._parsed_org_url = urlunparse((parsed_url[0],parsed_url[1],"","","",""))

        if referer_url is None:
            parsed_org = urlparse(self._org_url)
            self._referer_url = parsed_org.netloc

            url = '{}/portals/self'.format( self._url)

        parameters = {
            'f': 'json'
        }
        portal_info = self._post(url=url,
                                 param_dict=parameters,
                                 securityHandler=self,
                                 proxy_port=self._proxy_port,
                                 proxy_url=self._proxy_url)
        if 'user' in portal_info:
            if 'username' in portal_info['user']:
                self._username = portal_info['user']['username']