Return a (target, url_agrs) tuple or raise HTTPError(400/404/405).
961979
def match(self, environ):
        '''  '''
        path, targets, urlargs = environ['PATH_INFO'] or '/', None, {}
        if path in self.static:
            targets = self.static[path]
        else:
            for combined, rules in self.dynamic:
                match = combined.match(path)
                if not match: continue
                getargs, targets = rules[match.lastindex - 1]
                urlargs = getargs(path) if getargs else {}
                break

        if not targets:
            raise HTTPError(404, "Not found: " + repr(environ['PATH_INFO']))
        method = environ['REQUEST_METHOD'].upper()
        if method in targets:
            return targets[method], urlargs
        if method == 'HEAD' and 'GET' in targets:
            return targets['GET'], urlargs
        if 'ANY' in targets:
            return targets['ANY'], urlargs
        allowed = [verb for verb in targets if verb != 'ANY']
        if 'GET' in allowed and 'HEAD' not in allowed:
            allowed.append('HEAD')
        raise HTTPError(405, "Method not allowed.",
                        header=[('Allow',",".join(allowed))])
539335
def get_ga_query_dict(self):
        
        query_dict = super(GARequestErrorReportingMixin, self).get_ga_query_dict()
        request = self.get_ga_request()
        if not request:
            return query_dict
        user_ip = request.META.get('HTTP_X_FORWARDED_FOR', request.META.get('REMOTE_ADDR', ''))
        user_ip = user_ip.split(',')[0].strip()
        user_agent = request.META.get('HTTP_USER_AGENT')
        user_language = request.META.get('HTTP_ACCEPT_LANGUAGE')
        if user_ip:
            query_dict['uip'] = user_ip
        if user_agent:
            query_dict['ua'] = user_agent
        if user_language:
            query_dict['ul'] = user_language
        return query_dict
6590
def get_safe_redirect_target(arg='next'):
    """"""
    for target in request.args.get(arg), request.referrer:
        if not target:
            continue
        if is_local_url(target):
            return target
    return None
995246
def get(self, path, *args, **kwargs):
        ''''''
        target = self._host.relative(path).utf8
        if not isinstance(target, basestring):
            # on older versions of the `url` library, .utf8 is a method, not a property
            target = target()
        params = kwargs.get('params', {})
        params.update(self._params)
        kwargs['params'] = params
        logger.debug('GET %s with %s, %s', target, args, kwargs)
        return requests.get(target, *args, **kwargs)
605133
def get(self, url, params=None, callback=None, retry=0, **kwargs):
        """"""
        kwargs.setdefault("allow_redirects", True)
        return self.request(
            "get", url=url, params=params, callback=callback, retry=retry, **kwargs
        )
340715
def get(self, url):
        
        r = requests.get(self._format_url(url), headers=self.headers, timeout=TIMEOUT)
        self._check_response(r, 200)

        return r.json()
141698
def _get(self, url, params={}):
        """"""
        r = requests.get(self._api_prefix + url,
            params=params,
            headers=self.headers,
            auth=self.auth,
        )
        return self._action(r)
171343
def is_url_for(cls, _action, _endpoint=None, _app=None, _external=None, **paramattrs):
        
        def decorator(f):
            if 'url_for_endpoints' not in cls.__dict__:
                cls.url_for_endpoints = {None: {}}  # Stick it into the class with the first endpoint
            cls.url_for_endpoints.setdefault(_app, {})

            for keyword in paramattrs:
                if isinstance(paramattrs[keyword], six.string_types) and '.' in paramattrs[keyword]:
                    paramattrs[keyword] = tuple(paramattrs[keyword].split('.'))
            cls.url_for_endpoints[_app][_action] = _endpoint or f.__name__, paramattrs, _external
            return f
        return decorator
69011
def get(self, uri, disable_proxy=False, stream=False):
        """"""
        response = requests.get(
            uri,
            headers=self.headers,
            allow_redirects=True,
            cookies={},
            stream=stream,
            proxies=self.proxy if not disable_proxy else False
        )

        if response.status_code in _PERMITTED_STATUS_CODES:
            self.response_headers = response.headers
            return response.content if not stream else response.iter_content()
        else:
            raise requests.exceptions.HTTPError(
                "HTTP response did not have a permitted status code."
            )
990315
def rest_get(url, timeout):
    ''''''
    try:
        response = requests.get(url, timeout=timeout)
        return response
    except Exception as e:
        print('Get exception {0} when sending http get to url {1}'.format(str(e), url))
        return None
827982
def get(self, url, headers=None, kwargs=None):
        
        return self._request(
            method='get',
            url=url,
            headers=headers,
            kwargs=kwargs
        )
811532
def url_for(self, *args, **kwargs):
        """"""
        return yarl.URL(self.url(parts=kwargs))
964853
def url_for(self, *args: str, **kwargs: str) -> URL:
        """"""
        return self._resource.url_for(*args, **kwargs)
35944
def find_proxy(url, host=None):
  
  if host is None:
    m = _URL_REGEX.match(url)
    if not m:
      raise URLError(url)
    if len(m.groups()) is 1:
      host = m.groups()[0]
    else:
      raise URLError(url)
  return _pacparser.find_proxy(url, host)
691156
def _build_url(self, endpoint):
        
        try:
            path = self.endpoints[endpoint]
        except KeyError:
            msg = 'Unknown endpoint `{0}`'
            raise ValueError(msg.format(endpoint))
        absolute_url = urljoin(self.target, path)
        return absolute_url
29851
def fetch(url, timeout=5, userAgent=None, only_mime_types=None):
    
    headers = {}
    if userAgent:
        headers['User-agent'] = str(userAgent)
    else:
        headers['User-agent'] = ua.random

    #request = Request(url=url, headers=headers)
    #response = urlopen(request, timeout=timeout)
    response = requests.get(url, headers=headers, timeout=timeout)

    # Return nothing of the content isn't one of the target mime-types.
    if only_mime_types:
        assert isinstance(only_mime_types, (tuple, list))
        # Check for mimetype by looking at pattern in the URL.
        # Not super accurate, but very fast.
        ct, mt_encoding = mimetypes.guess_type(url)
        # Then check for mimetype by actually requesting the resource and
        # looking at the response.
        # More accurate, but slower since we actually have to send a request.
        if not ct:
            response_info = response.info()
            ct = (response_info.getheader('Content-Type') or '').split(';')[0]
        #TODO:if still undefined, use magic.Magic(mime=True).from_file(url)?
        if ct not in only_mime_types:
            return
    try:
        #return response.read()
        return response.text
    except httplib.IncompleteRead as e:
        # This should rarely happen, and is often the fault of the server
        # sending a malformed response.
        #TODO:just abandon all content and return '' instead?
        return e.partial
1272004
def _urllib_send(opener, req, **kwargs):
    """"""
    if req.content and not any(h.lower() == 'content-type'
                               for h in req.headers):
        req = req.with_headers({'Content-Type': 'application/octet-stream'})
    url = req.url + '?' + urlencode(req.params)
    raw_req = urllib_request.Request(url, req.content, headers=req.headers)
    set_urllib_method(raw_req, req.method)
    try:
        res = opener.open(raw_req, **kwargs)
    except urllib_http_error_cls as http_err:
        res = http_err
    return Response(res.getcode(), content=res.read(), headers=res.headers)