當前位置: 首頁>>代碼示例>>Python>>正文


Python cachecontrol.CacheControl方法代碼示例

本文整理匯總了Python中cachecontrol.CacheControl方法的典型用法代碼示例。如果您正苦於以下問題:Python cachecontrol.CacheControl方法的具體用法?Python cachecontrol.CacheControl怎麽用?Python cachecontrol.CacheControl使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在cachecontrol的用法示例。


在下文中一共展示了cachecontrol.CacheControl方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: __init__

# 需要導入模塊: import cachecontrol [as 別名]
# 或者: from cachecontrol import CacheControl [as 別名]
def __init__(self, url="https://pypi.org/", disable_cache=False, fallback=True):
        super(PyPiRepository, self).__init__(url.rstrip("/") + "/simple/")

        self._base_url = url
        self._disable_cache = disable_cache
        self._fallback = fallback

        release_cache_dir = Path(CACHE_DIR) / "cache" / "repositories" / "pypi"
        self._cache = CacheManager(
            {
                "default": "releases",
                "serializer": "json",
                "stores": {
                    "releases": {"driver": "file", "path": str(release_cache_dir)},
                    "packages": {"driver": "dict"},
                },
            }
        )

        self._cache_control_cache = FileCache(str(release_cache_dir / "_http"))
        self._session = CacheControl(session(), cache=self._cache_control_cache)
        self._inspector = Inspector()

        self._name = "PyPI" 
開發者ID:python-poetry,項目名稱:poetry,代碼行數:26,代碼來源:pypi_repository.py

示例2: __init__

# 需要導入模塊: import cachecontrol [as 別名]
# 或者: from cachecontrol import CacheControl [as 別名]
def __init__(self, access_token=None, host=None, cache=None):
        """Constructs a Service object

        This method should be overridden by subclasses.

        Parameters
        ----------
        access_token : str
            Mapbox access token string.
        host : str, optional
            Mapbox API host (advanced usage only).
        cache : CacheControl cache instance (Dict or FileCache), optional
            Optional caching, not generally needed.

        Returns
        -------
        Service
        """
        self.session = Session(access_token)
        self.host = host or os.environ.get('MAPBOX_HOST', self.default_host)
        if cache:
            self.session = CacheControl(self.session, cache=cache) 
開發者ID:mapbox,項目名稱:mapbox-sdk-py,代碼行數:24,代碼來源:base.py

示例3: open

# 需要導入模塊: import cachecontrol [as 別名]
# 或者: from cachecontrol import CacheControl [as 別名]
def open(self):
        global SESSION
        if SESSION is None:
            SESSION = CacheControl(Session(), cache=FileCache(SESSION_CACHE_PATH))

        try:
            self._response = SESSION.get(self.uri, headers=self.headers)
        except InvalidSchema as e:
            raise DocumentNotFoundException(u'document not found: "{0}"'.format(self.uri), cause=e)
        except ConnectionError as e:
            raise LoaderException(u'request connection error: "{0}"'.format(self.uri), cause=e)
        except Exception as e:
            raise LoaderException(u'request error: "{0}"'.format(self.uri), cause=e)

        status = self._response.status_code
        if status == 404:
            self._response = None
            raise DocumentNotFoundException(u'document not found: "{0}"'.format(self.uri))
        elif status != 200:
            self._response = None
            raise LoaderException(u'request error {0:d}: "{1}"'.format(status, self.uri)) 
開發者ID:apache,項目名稱:incubator-ariatosca,代碼行數:23,代碼來源:request.py

示例4: __init__

# 需要導入模塊: import cachecontrol [as 別名]
# 或者: from cachecontrol import CacheControl [as 別名]
def __init__(self, app):
        session = cachecontrol.CacheControl(requests.Session())
        self.request = transport.requests.Request(session=session)
        self.id_token_verifier = _JWTVerifier(
            project_id=app.project_id, short_name='ID token',
            operation='verify_id_token()',
            doc_url='https://firebase.google.com/docs/auth/admin/verify-id-tokens',
            cert_url=ID_TOKEN_CERT_URI,
            issuer=ID_TOKEN_ISSUER_PREFIX,
            invalid_token_error=_auth_utils.InvalidIdTokenError,
            expired_token_error=ExpiredIdTokenError)
        self.cookie_verifier = _JWTVerifier(
            project_id=app.project_id, short_name='session cookie',
            operation='verify_session_cookie()',
            doc_url='https://firebase.google.com/docs/auth/admin/verify-id-tokens',
            cert_url=COOKIE_CERT_URI,
            issuer=COOKIE_ISSUER_PREFIX,
            invalid_token_error=InvalidSessionCookieError,
            expired_token_error=ExpiredSessionCookieError) 
開發者ID:firebase,項目名稱:firebase-admin-python,代碼行數:21,代碼來源:_token_gen.py

示例5: __init__

# 需要導入模塊: import cachecontrol [as 別名]
# 或者: from cachecontrol import CacheControl [as 別名]
def __init__(
        self, name, url, auth=None, disable_cache=False, cert=None, client_cert=None
    ):  # type: (str, str, Optional[Auth], bool, Optional[Path], Optional[Path]) -> None
        if name == "pypi":
            raise ValueError("The name [pypi] is reserved for repositories")

        self._packages = []
        self._name = name
        self._url = url.rstrip("/")
        self._auth = auth
        self._client_cert = client_cert
        self._cert = cert
        self._inspector = Inspector()
        self._cache_dir = Path(CACHE_DIR) / "cache" / "repositories" / name
        self._cache = CacheManager(
            {
                "default": "releases",
                "serializer": "json",
                "stores": {
                    "releases": {"driver": "file", "path": str(self._cache_dir)},
                    "packages": {"driver": "dict"},
                    "matches": {"driver": "dict"},
                },
            }
        )

        self._session = CacheControl(
            requests.session(), cache=FileCache(str(self._cache_dir / "_http"))
        )

        url_parts = urlparse.urlparse(self._url)
        if not url_parts.username and self._auth:
            self._session.auth = self._auth

        if self._cert:
            self._session.verify = str(self._cert)

        if self._client_cert:
            self._session.cert = str(self._client_cert)

        self._disable_cache = disable_cache 
開發者ID:python-poetry,項目名稱:poetry,代碼行數:43,代碼來源:legacy_repository.py

示例6: __init__

# 需要導入模塊: import cachecontrol [as 別名]
# 或者: from cachecontrol import CacheControl [as 別名]
def __init__(self, destination: Path, staging: Path, s3_url: str, dry_run: bool, is_nightly_enabled: bool,
                 cache: Optional[Path]):
        self.destination = destination
        self.staging = staging
        self.s3_url = s3_url
        self.dry_run = dry_run
        self.is_nightly_enabled = is_nightly_enabled
        if cache:
            self.info(f"Using cache {cache}")
            self.fetcher = CacheControl(requests.session(), cache=FileCache(cache))
        else:
            self.info("Making uncached requests")
            self.fetcher = requests 
開發者ID:compiler-explorer,項目名稱:infra,代碼行數:15,代碼來源:installation.py

示例7: _get_session

# 需要導入模塊: import cachecontrol [as 別名]
# 或者: from cachecontrol import CacheControl [as 別名]
def _get_session(self):
        if HTTPSPublicKeyRetriever._class_session is None:
            session = cachecontrol.CacheControl(requests.Session())
            HTTPSPublicKeyRetriever._class_session = session
        return HTTPSPublicKeyRetriever._class_session 
開發者ID:atlassian,項目名稱:asap-authentication-python,代碼行數:7,代碼來源:key.py

示例8: __init__

# 需要導入模塊: import cachecontrol [as 別名]
# 或者: from cachecontrol import CacheControl [as 別名]
def __init__(self, conf):
        self.conf = conf
        self.session = CacheControl(requests.Session())
        self.session.headers.update({
            'User-agent': 'Kibitzr/' + version,
        })
        self.url = conf['url']
        self.valid_http = set(conf.get('valid_http', [200]))
        self.verify_cert = conf.get('verify-cert', conf.get('verify_cert', True)) 
開發者ID:kibitzr,項目名稱:kibitzr,代碼行數:11,代碼來源:simple.py

示例9: handle_pre

# 需要導入模塊: import cachecontrol [as 別名]
# 或者: from cachecontrol import CacheControl [as 別名]
def handle_pre(self, context_pre):
    import requests
    from cachecontrol import CacheControl
    from cachecontrol.caches.file_cache import FileCache

    from isitfit.utils import logger
    
    logger.debug("Downloading ec2 catalog (cached to local file)")

    # based on URL = 'http://www.ec2instances.info/instances.json'
    # URL = 's3://...csv'
    # Edit 2019-09-10 use CDN link instead of direct gitlab link
    if self.allow_ec2_different_family:
      URL = 'https://cdn.jsdelivr.net/gh/autofitcloud/www.ec2instances.info-ec2op@0.3/www.ec2instances.info/t3c_smaller_familyNone.json'
    else:
      # URL = 'https://gitlab.com/autofitcloud/www.ec2instances.info-ec2op/raw/master/www.ec2instances.info/t3b_smaller_familyL2.json'
      URL = 'https://cdn.jsdelivr.net/gh/autofitcloud/www.ec2instances.info-ec2op@0.2/www.ec2instances.info/t3b_smaller_familyL2.json'

    # Update 2019-12-03: move into /tmp/isitfit/
    # fc_dir = '/tmp/isitfit_ec2info.cache'
    from isitfit.dotMan import DotMan
    import os
    fc_dir = os.path.join(DotMan().tempdir(), 'ec2info.cache')

    # cached https://cachecontrol.readthedocs.io/en/latest/
    sess = requests.session()
    cached_sess = CacheControl(sess, cache=FileCache(fc_dir))
    r = cached_sess.request('get', URL)

    # read catalog, copy from ec2op-cli/ec2op/optimizer/cwDailyMaxMaxCpu
    import json
    j = json.dumps(r.json(), indent=4, sort_keys=True)
    from pandas import read_json
    df = read_json(j, orient='split')
    
    # Edit 2019-09-13 no need to subsample the columns at this stage
    # df = df[['API Name', 'Linux On Demand cost']]

    df = df.rename(columns={'Linux On Demand cost': 'cost_hourly'})
    # df = df.set_index('API Name') # need to use merge, not index
    context_pre['df_cat'] = df

    return context_pre 
開發者ID:autofitcloud,項目名稱:isitfit,代碼行數:45,代碼來源:catalog_ec2.py

示例10: github_api_ctor

# 需要導入模塊: import cachecontrol [as 別名]
# 或者: from cachecontrol import CacheControl [as 別名]
def github_api_ctor(
    github_url: str,
    verify_ssl: bool=True,
    session_adapter: SessionAdapter=SessionAdapter.RETRY,
):
    '''returns the appropriate github3.GitHub constructor for the given github URL

    In case github_url does not refer to github.com, the c'tor for GithubEnterprise is
    returned with the url argument preset, thus disburdening users to differentiate
    between github.com and non-github.com cases.
    '''
    parsed = urllib.parse.urlparse(github_url)
    if parsed.scheme:
        hostname = parsed.hostname
    else:
        raise ValueError('failed to parse url: ' + str(github_url))

    session = github3.session.GitHubSession()
    session_adapter = SessionAdapter(session_adapter)
    if session_adapter is SessionAdapter.NONE:
        pass
    elif session_adapter is SessionAdapter.RETRY:
        session = http_requests.mount_default_adapter(session)
    elif session_adapter is SessionAdapter.CACHE:
        session = cachecontrol.CacheControl(
            session,
            cache_etags=True,
        )
    else:
        raise NotImplementedError

    if log_github_access:
        session.hooks['response'] = log_stack_trace_information_hook

    if hostname.lower() == 'github.com':
        return functools.partial(
            github3.github.GitHub,
            session=session,
        )
    else:
        return functools.partial(
            github3.github.GitHubEnterprise,
            url=github_url,
            verify=verify_ssl,
            session=session,
        ) 
開發者ID:gardener,項目名稱:cc-utils,代碼行數:48,代碼來源:github.py


注:本文中的cachecontrol.CacheControl方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。