Validates self.server_url
6862
def _validate_server_url(self):
        """"""
        try:
            request = requests.head(self.server_url)
            if request.status_code >= 400:
                raise InvenioConnectorServerError(
                    "Unexpected status code '%d' accessing URL: %s"
                    % (request.status_code, self.server_url))
        except (InvalidSchema, MissingSchema) as err:
            raise InvenioConnectorServerError(
                "Bad schema, expecting http:// or https://:\n %s" % (err,))
        except ConnectionError as err:
            raise InvenioConnectorServerError(
                "Couldn't establish connection to '%s':\n %s"
                % (self.server_url, err))
        except InvalidURL as err:
            raise InvenioConnectorServerError(
                "Invalid URL '%s':\n %s"
                % (self.server_url, err))
        except RequestException as err:
            raise InvenioConnectorServerError(
                "Unknown error connecting to '%s':\n %s"
                % (self.server_url, err))
1145007
def validate_repo_url(url):
    
    try:
        if "github.com" in url:
            return re.findall(r"https?://w?w?w?.?github.com/[\w\-]+/[\w.-]+", url)[0]
        elif "bitbucket.org" in url:
            return re.findall(r"https?://bitbucket.org/[\w.-]+/[\w.-]+", url)[0] + "/src/"
        elif "launchpad.net" in url:
            return re.findall(r"https?://launchpad.net/[\w.-]+", url)[0]
        elif "sourceforge.net" in url:
            mo = re.match(r"https?://sourceforge.net/projects/"
                          r"([\w.-]+)/", url, re.I)
            template = "https://sourceforge.net/p/{}/code/HEAD/tree/trunk/src/"
            return template.format(mo.groups()[0])
    except (IndexError, AttributeError):
        pass
    return ""
202543
protected function validateRedirectURL()
    {
        if (!filter_var($this->redirectURL, FILTER_VALIDATE_URL)) {
            // Not a full URL
            if (!preg_match('#^/[a-zA-Z0-9_/.-]*#', $this->redirectURL)) {
                // Not a valid path either
                $this->setNotReady("Invalid redirect URL entered.", null, 404);
                return;
            }
        }
    }
998341
def is_valid_url(url):
    """"""
    pieces = urlparse(url)
    return all([pieces.scheme, pieces.netloc])
5345
def validate(self, value):
        
        if '.' not in value:
            self.error_message = '%s is not a fully qualified domain name.' % \
                                 value
            return False
        try:
            ipaddress = socket.gethostbyname(value)
        except socket.gaierror:
            self.error_message = '%s does not resolve.' % value
            return False
        try:
            socket.gethostbyaddr(ipaddress)
        except socket.herror:
            self.error_message = \
                '%s reverse address (%s) does not resolve.' % \
                (value, ipaddress)
            return False
        self._choice = value
        return True
157805
protected function validateUrlDownload()
    {
        $invalid = array();

        foreach ($this->getSubmitted('sources') as $line => $url) {
            $line++;
            if (filter_var($url, FILTER_VALIDATE_URL) === false) {
                $invalid[] = $line;
            }
        }

        if (!empty($invalid)) {
            $this->setError('sources', $this->text('Error on line @num', array('@num' => implode(',', $invalid))));
        }
    }
631218
def validate(config):
    '''
    
    '''
    if not isinstance(config, list):
        return False, ('Configuration for haproxy beacon must '
                       'be a list.')
    else:
        _config = {}
        list(map(_config.update, config))

        if 'backends' not in _config:
            return False, ('Configuration for haproxy beacon '
                           'requires backends.')
        else:
            if not isinstance(_config['backends'], dict):
                return False, ('Backends for haproxy beacon '
                               'must be a dictionary.')
            else:
                for backend in _config['backends']:
                    log.debug('_config %s', _config['backends'][backend])
                    if 'servers' not in _config['backends'][backend]:
                        return False, ('Backends for haproxy beacon '
                                       'require servers.')
                    else:
                        _servers = _config['backends'][backend]['servers']
                        if not isinstance(_servers, list):
                            return False, ('Servers for haproxy beacon '
                                           'must be a list.')
    return True, 'Valid beacon configuration'
428901
def validate_query(self, using=None, **kwargs):
        
        return self._get_connection(using).indices.validate_query(index=self._name, **kwargs)
453352
def is_valid_url(url):
    
    regex = re.compile(
            r'^(?:http|ftp)s?://' # http:// or https://
            r'(?:(?:[A-Z0-9](?:[A-Z0-9-]{0,61}[A-Z0-9])?\.)+(?:[A-Z]{2,6}\.?|[A-Z0-9-]{2,}\.?)|' #domain...
            #r'localhost|' #localhost...
            r'\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})' # ...or ip
            r'(?::\d+)?' # optional port
            r'(?:/?|[/?]\S+)$', re.IGNORECASE)
    return bool(regex.match(url))
738325
def valid_server?(server, port = SSL_PORT)
      # cheating by shelling out to curl, because getting open-uri, or even net/http to use
      # ssl_options like :OP_NO_SSLv2 and :OP_NO_SSLv3 will take time to figure out..
      return true if `/usr/bin/curl -s 'https://#{server}:#{port}/#{TEST_PATH}'`.include? TEST_CONTENT
      return true if `/usr/bin/curl -s 'http://#{server}:#{port}/#{TEST_PATH}'`.include? TEST_CONTENT
      false

      # # try ssl first
      # # NOTE:  doesn't work if we can't disallow SSLv3 or force TLSv1
      # # See cheat above.
      # begin
      #   return true if open("https://#{server}:#{port}/#{TEST_PATH}", ssl_verify_mode: OpenSSL::SSL::VERIFY_NONE).read.include? TEST_CONTENT
      #
      # rescue
      #   # then regular http
      #   begin
      #     return true if open("http://#{server}:#{port}/#{TEST_PATH}").read.include? TEST_CONTENT
      #   rescue
      #     # any errors = no API
      #     return false
      #   end # begin
      # end # begin
      # # if we're here, no API
      # false
    end
649893
def check_url(url):
        '''
        

        '''
        request = urllib2.Request(url)
        try:
            response = urlopen(request)
            return True, response.code
        except urllib2.HTTPError as e:
            return False, e.code
948886
def validate_url(cls, url):
        

        if url is None:
            return None

        url = url.strip()
        while url.endswith('/'):
            url = url[:-1]
        return url
568049
def _is_valid_api_url(self, url):
        """"""
        # Check response is a JSON with ok: 1
        data = {}
        try:
            r = requests.get(url, proxies=self.proxy_servers)
            content = to_text_string(r.content, encoding='utf-8')
            data = json.loads(content)
        except Exception as error:
            logger.error(str(error))

        return data.get('ok', 0) == 1
754933
def _parse_url_and_validate(cls, url):
        
        parsed_url = urlparse(url)
        if parsed_url.scheme and parsed_url.netloc:
            final_url = parsed_url.geturl()
        else:
            raise BadURLException
        return final_url
1052341
def validated_url(url):
    """"""
    try:
        u = urlparse(url)
        u.port  # Trigger 'invalid port' exception
    except Exception:
        raise error.URLError(url)
    else:
        if not u.scheme or not u.netloc:
            raise error.URLError(url)
        return url
100824
def __isValidUrl(self, addr):
        
        regex = re.compile(
            r'^(?:http)s?://'  #: http:// or https://
            r'(?:(?:[A-Z0-9](?:[A-Z0-9-]{0,61}[A-Z0-9])?\.)+(?:[A-Z]{2,6}\.?|[A-Z0-9-]{2,}\.?)|'  #: domain...
            r'localhost|'  #: localhost...
            r'\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})'  #: ...or ip
            r'(?::\d+)?'  #: optional port
            r'(?:/?|[/?]\S+)$', re.IGNORECASE)
        if addr and isinstance(addr, string_types):
            if regex.match(addr):
                return True
        return False
1234084
def validate(self, nonce):
        """"""
        if self.debug: print("Checking nonce " + str(nonce),file=sys.stderr)
        try:
            opaque, ip, expiretime = self.get(nonce) #pylint: disable=unused-variable
            if expiretime < time.time():
                if self.debug: print("Nonce expired",file=sys.stderr)
                self.remove(nonce)
                return False
            elif ip != flask.request.remote_addr:
                if self.debug: print("Nonce IP mismatch",file=sys.stderr)
                self.remove(nonce)
                return False
            else:
                return True
        except KeyError:
            if self.debug: print("Nonce " + nonce + " does not exist",file=sys.stderr)
            return False