Main entry point for discovery.  Attempts to detect whether or not the URI is a raw domain name ('mycompany.com')
 vs. a user's claimed ID ('http://mycompany.com/openid?id=12345') and performs the site or user discovery appropriately
547728
def perform_discovery(uri)
      begin
        parsed_uri = URI::parse(uri)
        if parsed_uri.scheme.nil?
          return discover_site(uri)
        end
        return discover_user(parsed_uri.host, uri)
      rescue
        # If we fail, just return nothing and fallback on default discovery mechanisms
        return nil
      end
    end
918046
def normalizeURL(url):
    """"""
    try:
        normalized = urinorm.urinorm(url)
    except ValueError as why:
        raise DiscoveryFailure('Normalizing identifier: %s' % (why, ), None)
    else:
        return urllib.parse.urldefrag(normalized)[0]
469636
def explore(self):
        
        # Where do we start? Build options in starts which has entries
        # that are a pair comprised of the uri and a list of acceptable
        # capabilities
        starts = []
        if (self.sitemap_name is not None):
            print("Starting from explicit --sitemap %s" % (self.sitemap_name))
            starts.append(XResource(self.sitemap_name))
        elif (len(self.mapper) > 0):
            uri = self.mapper.default_src_uri()
            (scheme, netloc, path, params, query, fragment) = urlparse(uri)
            if (not scheme and not netloc):
                if (os.path.isdir(path)):
                    # have a dir, look for 'likely' file names
                    print(
                        "Looking for capability documents in local directory %s" %
                        (path))
                    for name in ['resourcesync', 'capabilities.xml',
                                 'resourcelist.xml', 'changelist.xml']:
                        file = os.path.join(path, name)
                        if (os.path.isfile(file)):
                            starts.append(XResource(file))
                    if (len(starts) == 0):
                        raise ClientFatalError("No likely capability files found in local directory %s" %
                                               (path))
                else:
                    # local file, might be anything (or not exist)
                    print("Starting from local file %s" % (path))
                    starts.append(XResource(path))
            else:
                # remote, can't tell whether we have a sitemap or a server name or something
                # else, build list of options depending on whether there is a path and whether
                # there is an extension/name
                well_known = urlunparse(
                    [scheme, netloc, '/.well-known/resourcesync', '', '', ''])
                if (not path):
                    # root, just look for .well-known
                    starts.append(
                        XResource(
                            well_known, [
                                'capabilitylist', 'capabilitylistindex']))
                else:
                    starts.append(XResource(uri))
                    starts.append(
                        XResource(
                            well_known, [
                                'capabilitylist', 'capabilitylistindex']))
                print("Looking for discovery information based on mappings")
        else:
            raise ClientFatalError(
                "No source information (server base uri or capability uri) specified, use -h for help")
        #
        # Have list of one or more possible starting point, try them in turn
        try:
            for start in starts:
                # For each starting point we create a fresh history
                history = [start]
                input = None
                while (len(history) > 0):
                    print()
                    xr = history.pop()
                    new_xr = self.explore_uri(xr, len(history) > 0)
                    if (new_xr):
                        # Add current and new to history
                        history.append(xr)
                        history.append(new_xr)
        except ExplorerQuit:
            pass  # expected way to exit
        print("\nresync-explorer done, bye...\n")
1193969
def discovery_uri(host = WORLD_WIDE_AUTHORITY)
      URI(DISCOVERY_TEMPLATE.expand(host: host, endpoint: authorize_endpoint))
    end
452503
def usernameAvailable(self, username, domain):
        
        if len(username) < 2:
            return [False, u"Username too short"]
        for char in u"[ ,:;<>@()!\"'%&\\|\t\b":
            if char in username:
                return [False,
                        u"Username contains invalid character: '%s'" % char]

        # The localpart is acceptable if it can be parsed as the local part
        # of an RFC 2821 address.
        try:
            parseAddress("<%s@example.com>" % (username,))
        except ArgumentError:
            return [False, u"Username fails to parse"]

        # The domain is acceptable if it is one which we actually host.
        if domain not in self.getAvailableDomains():
            return [False, u"Domain not allowed"]

        query = self.store.query(userbase.LoginMethod,
                                 AND(userbase.LoginMethod.localpart == username,
                                     userbase.LoginMethod.domain == domain))
        return [not bool(query.count()), u"Username already taken"]
1104539
def url2domain(url):
    
    parsed_uri = urlparse.urlparse(url)
    domain = '{uri.netloc}'.format(uri=parsed_uri)
    domain = re.sub("^.+@", "", domain)
    domain = re.sub(":.+$", "", domain)
    return domain
373448
def normalizeURL(url):
    """"""
    try:
        normalized = urinorm.urinorm(url)
    except ValueError, why:
        raise DiscoveryFailure('Normalizing identifier: %s' % (why[0],), None)
    else:
        return urlparse.urldefrag(normalized)[0]
80678
def create_basic_url(self):
        
        if self.username is None:
            if self.namespace is None:
                request_url = "{}/api/0/{}/".format(
                    self.instance, self.repo)
            else:
                request_url = "{}/api/0/{}/{}/".format(
                    self.instance, self.namespace, self.repo)
        else:
            if self.namespace is None:
                request_url = "{}/api/0/fork/{}/{}/".format(
                    self.instance, self.username, self.repo)
            else:
                request_url = "{}/api/0/fork/{}/{}/{}/".format(
                    self.instance, self.username, self.namespace, self.repo)
        return request_url
21096
protected function detectRequestUri()
	{
		// First we need to detect the URI scheme.
		if ($this->isSslConnection())
		{
			$scheme = 'https://';
		}
		else
		{
			$scheme = 'http://';
		}

		/*
		 * There are some differences in the way that Apache and IIS populate server environment variables.  To
		 * properly detect the requested URI we need to adjust our algorithm based on whether or not we are getting
		 * information from Apache or IIS.
		 */

		$phpSelf    = $this->input->server->getString('PHP_SELF', '');
		$requestUri = $this->input->server->getString('REQUEST_URI', '');

		// If PHP_SELF and REQUEST_URI are both populated then we will assume "Apache Mode".
		if (!empty($phpSelf) && !empty($requestUri))
		{
			// The URI is built from the HTTP_HOST and REQUEST_URI environment variables in an Apache environment.
			$uri = $scheme . $this->input->server->getString('HTTP_HOST') . $requestUri;
		}
		else
		{
			// If not in "Apache Mode" we will assume that we are in an IIS environment and proceed.
			// IIS uses the SCRIPT_NAME variable instead of a REQUEST_URI variable... thanks, MS
			$uri       = $scheme . $this->input->server->getString('HTTP_HOST') . $this->input->server->getString('SCRIPT_NAME');
			$queryHost = $this->input->server->getString('QUERY_STRING', '');

			// If the QUERY_STRING variable exists append it to the URI string.
			if (!empty($queryHost))
			{
				$uri .= '?' . $queryHost;
			}
		}

		return trim($uri);
	}
1151437
def _get_domain_id(self, domain):
        
        api = self.api[self.account]['domain_id']
        qdomain = dns.name.from_text(domain).to_unicode(True)
        domains, last_count, page = {}, -1, 0
        while last_count != len(domains):
            last_count = len(domains)
            page += 1
            url = (api['GET'].copy()).get('url', '/').replace('<index>', str(page))
            params = api['GET'].get('params', {}).copy()
            for param in params:
                params[param] = params[param].replace('<index>', str(page))
            response = self._get(url, query_params=params)
            domain_tags = Provider._filter_dom(response.text, api['filter'], True)
            for domain_tag in domain_tags:
                domain_id = Provider._extract_domain_id(dict(domain_tag.attrs)[api['id']['attr']],
                                                        api['id']['regex'])
                domain = (Provider._filter_dom(domain_tag, api['domain'])
                          .renderContents().decode('UTF-8'))
                domains[domain] = domain_id
                if domain == qdomain:
                    LOGGER.info('Hetzner => Get ID %s for domain %s', domain_id, qdomain)
                    return domain_id
        LOGGER.error('Hetzner => ID for domain %s does not exists', qdomain)
        raise AssertionError
607972
def resolve_url(url, directory=None, permissions=None):
    

    u = urlparse(url)

    # create the name of the destination file
    if directory is None:
        directory = os.getcwd()
    filename = os.path.join(directory,os.path.basename(u.path))

    if u.scheme == '' or u.scheme == 'file':
        # for regular files, make a direct copy
        if os.path.isfile(u.path):
            if os.path.isfile(filename):
                # check to see if src and dest are the same file
                src_inode = os.stat(u.path)[stat.ST_INO]
                dst_inode = os.stat(filename)[stat.ST_INO]
                if src_inode != dst_inode:
                    shutil.copy(u.path, filename)
            else:
                shutil.copy(u.path, filename)
        else:
            errmsg  = "Cannot open file %s from URL %s" % (u.path, url)
            raise ValueError(errmsg)

    elif u.scheme == 'http' or u.scheme == 'https':
        s = requests.Session()
        s.mount(str(u.scheme)+'://',
            requests.adapters.HTTPAdapter(max_retries=5))

        # look for an ecp cookie file and load the cookies
        cookie_dict = {}
        ecp_file = '/tmp/ecpcookie.u%d' % os.getuid()
        if os.path.isfile(ecp_file):
            cj = cookielib.MozillaCookieJar()
            cj.load(ecp_file, ignore_discard=True, ignore_expires=True)
        else:
            cj = []

        for c in cj:
            if c.domain == u.netloc:
                # load cookies for this server
                cookie_dict[c.name] = c.value
            elif u.netloc == "code.pycbc.phy.syr.edu" and \
              c.domain == "git.ligo.org":
                # handle the redirect for code.pycbc to git.ligo.org
                cookie_dict[c.name] = c.value

        r = s.get(url, cookies=cookie_dict, allow_redirects=True)
        if r.status_code != 200:
            errmsg = "Unable to download %s\nError code = %d" % (url,
                r.status_code)
            raise ValueError(errmsg)

        # if we are downloading from git.ligo.org, check that we
        # did not get redirected to the sign-in page
        if u.netloc == 'git.ligo.org' or u.netloc == 'code.pycbc.phy.syr.edu':
            # Check if we have downloaded a binary file.
            if istext(r.content):
                soup = BeautifulSoup(r.content, 'html.parser')
                desc = soup.findAll(attrs={"property":"og:url"})
                if len(desc) and \
                  desc[0]['content'] == 'https://git.ligo.org/users/sign_in':
                    raise ValueError(ecp_cookie_error.format(url))

        output_fp = open(filename, 'w')
        output_fp.write(r.content)
        output_fp.close()

    else:
        # TODO: We could support other schemes such as gsiftp by
        # calling out to globus-url-copy
        errmsg  = "Unknown URL scheme: %s\n" % (u.scheme)
        errmsg += "Currently supported are: file, http, and https."
        raise ValueError(errmsg)

    if not os.path.isfile(filename):
        errmsg = "Error trying to create file %s from %s" % (filename,url)
        raise ValueError(errmsg)

    if permissions:
        if os.access(filename, os.W_OK):
            os.chmod(filename, permissions)
        else:
            # check that the file has at least the permissions requested
            s = os.stat(filename)[stat.ST_MODE]
            if (s & permissions) != permissions:
                errmsg = "Could not change permissions on %s (read-only)" % url
                raise ValueError(errmsg)

    return filename
832947
def url_is_from_any_domain(url, domains):
    """"""
    host = parse_url(url).netloc.lower()

    if host:
        return any(((host == d.lower()) or (host.endswith('.%s' % d.lower())) for d in domains))
    else:
        return False
258121
function realDomain(id) {
  return id.lastIndexOf("@") === 0 ? id.substr(1).toLowerCase() :
    id.toLowerCase().
      replace(/@/g, "-at-").
      replace(/\./g, "-dot-").
      replace(UUID_PATTERN, "$1");
}
1106624
def checkURL(cls, trust_root, url):
        """"""
        tr = cls.parse(trust_root)
        return tr is not None and tr.validateURL(url)
731341
def show_company(domain):
    '''
    
    '''
    data = __utils__['http.query'](
        '{0}/companies/domain/{1}'.format(_base_url(), domain),
        status=True,
        decode=True,
        decode_type='json',
        header_dict={
            'tppl-api-key': _api_key(),
        },
    )
    status = data['status']
    if six.text_type(status).startswith('4') or six.text_type(status).startswith('5'):
        raise CommandExecutionError(
            'There was an API error: {0}'.format(data['error'])
        )
    return data.get('dict', {})
1010172
def handleCheckIDRequest(request, openid_request):
    
    # If the request was an IDP-driven identifier selection request
    # (i.e., the IDP URL was entered at the RP), then return the
    # default identity URL for this server. In a full-featured
    # provider, there could be interaction with the user to determine
    # what URL should be sent.
    if not openid_request.idSelect():

        id_url = getViewURL(request, idPage)

        # Confirm that this server can actually vouch for that
        # identifier
        if id_url != openid_request.identity:
            # Return an error response
            error_response = ProtocolError(
                openid_request.message,
                "This server cannot verify the URL %r" %
                (openid_request.identity,))

            return displayResponse(request, error_response)

    if openid_request.immediate:
        # Always respond with 'cancel' to immediate mode requests
        # because we don't track information about a logged-in user.
        # If we did, then the answer would depend on whether that user
        # had trusted the request's trust root and whether the user is
        # even logged in.
        openid_response = openid_request.answer(False)
        return displayResponse(request, openid_response)
    else:
        # Store the incoming request object in the session so we can
        # get to it later.
        setRequest(request, openid_request)
        return showDecidePage(request, openid_request)
931756
def find(url, args = {})
      raise ArgumentError.new("url can't be nil!") if url.nil?
      
      harmonized_url = harmonize_url(url)

      raise ArgumentError.new("url's protocol must be 'http(s)' or 'feed' (#{url})") if harmonized_url.nil?

      feeds = []

      # Open the URL to check the content-type or crawl for feed links
      open(harmonized_url) do |file|

        if feed_content_type?(file)
          # Add the url to feeds if it shows a feed content type
          feeds << harmonized_url
        
        else
          # Else, parse the page to search for links
          doc = Nokogiri::HTML(file.read)

          # Check <link> elements
          doc.css('link').each do |link|
            discovery = complete_extracted_url(link[:href], harmonized_url) if link[:rel] =~ %r{(alternate|service.feed)}i && Feedisco.feed_content_types.include?(link[:type].downcase.strip)
            feeds << discovery unless discovery.nil? or feeds.include? discovery
          end

          # Check <a> elements
          doc.css('a').each do |a|
            if looks_like_feed? a[:href] and
               (a[:href] =~ %r{\A/} or a[:href] =~ %r{#{URI.parse(harmonized_url).host}/})

              discovery = complete_extracted_url(a[:href], harmonized_url)
              feeds << discovery unless discovery.nil? or feeds.include?(discovery)
            end
          end

          # Check <a> elements again, less restrictively, so we add all discovered feeds even the ones
          # on external domains, but the will come after in the feeds array.
          doc.css('a').each do |a|
            discovery = complete_extracted_url(a[:href], harmonized_url) if looks_like_feed? a[:href]
            feeds << discovery unless discovery.nil? or feeds.include?(discovery)
          end
        end
      end

      feeds
    end