当前位置: 首页>>代码示例>>Python>>正文


Python traitlets.default方法代码示例

本文整理汇总了Python中traitlets.default方法的典型用法代码示例。如果您正苦于以下问题:Python traitlets.default方法的具体用法?Python traitlets.default怎么用?Python traitlets.default使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在traitlets的用法示例。


在下文中一共展示了traitlets.default方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _default_url

# 需要导入模块: import traitlets [as 别名]
# 或者: from traitlets import default [as 别名]
def _default_url(self):
        cfg = self._docker_config
        auths = cfg.get("auths", {})
        if not auths:
            return DEFAULT_DOCKER_REGISTRY_URL

        # default to first entry in docker config.json auths
        auth_config_url = next(iter(auths.keys()))
        if "://" not in auth_config_url:
            # auth key can be just a hostname,
            # which assumes https
            auth_config_url = "https://" + auth_config_url

        if auth_config_url.rstrip("/") == DEFAULT_DOCKER_AUTH_URL:
            # default docker config key is the v1 registry,
            # but we will talk to the v2 api
            return DEFAULT_DOCKER_REGISTRY_URL

        return auth_config_url 
开发者ID:jupyterhub,项目名称:binderhub,代码行数:21,代码来源:registry.py

示例2: _auth_config_url_default

# 需要导入模块: import traitlets [as 别名]
# 或者: from traitlets import default [as 别名]
def _auth_config_url_default(self):
        url = urlparse(self.url)
        cfg = self._docker_config
        auths = cfg.get("auths", {})
        # check for our url in docker config.json
        # there can be some variation, so try a few things.

        # in ~all cases, the registry url will appear in config.json
        if self.url in auths:
            # this will
            return self.url
        # ...but the config key is allowed to lack https://, so check just hostname
        if url.hostname in auths:
            return url.hostname
        # default docker special-case, where auth and registry urls are different
        if ("." + url.hostname).endswith((".docker.io", ".docker.com")):
            return DEFAULT_DOCKER_AUTH_URL

        # url not found, leave the most likely default
        return self.url 
开发者ID:jupyterhub,项目名称:binderhub,代码行数:22,代码来源:registry.py

示例3: main

# 需要导入模块: import traitlets [as 别名]
# 或者: from traitlets import default [as 别名]
def main():
    """
    Synchronizes a github repository with a local repository.
    """
    logging.basicConfig(
        format='[%(asctime)s] %(levelname)s -- %(message)s',
        level=logging.DEBUG)

    parser = argparse.ArgumentParser(description='Synchronizes a github repository with a local repository.')
    parser.add_argument('git_url', help='Url of the repo to sync')
    parser.add_argument('branch_name', default='master', help='Branch of repo to sync', nargs='?')
    parser.add_argument('repo_dir', default='.', help='Path to clone repo under', nargs='?')
    args = parser.parse_args()

    for line in GitPuller(
        args.git_url,
        args.branch_name,
        args.repo_dir
    ).pull():
        print(line) 
开发者ID:jupyterhub,项目名称:nbgitpuller,代码行数:22,代码来源:pull.py

示例4: start

# 需要导入模块: import traitlets [as 别名]
# 或者: from traitlets import default [as 别名]
def start(self):
        config_file_dir = os.path.dirname(os.path.abspath(self.output))
        if not os.path.isdir(config_file_dir):
            self.exit(
                "%r does not exist. The destination directory must exist "
                "before generating config file." % config_file_dir
            )
        if os.path.exists(self.output) and not self.force:
            self.exit("Config file already exists, use `--force` to overwrite")

        config_text = DaskGateway.instance().generate_config_file()
        if isinstance(config_text, bytes):
            config_text = config_text.decode("utf8")
        print("Writing default config to: %s" % self.output)
        with open(self.output, mode="w") as f:
            f.write(config_text) 
开发者ID:dask,项目名称:dask-gateway,代码行数:18,代码来源:app.py

示例5: options_from_form

# 需要导入模块: import traitlets [as 别名]
# 或者: from traitlets import default [as 别名]
def options_from_form(self, formdata):
        """Parse the submitted form data and turn it into the correct
           structures for self.user_options."""

        default = self.dockerimages[0]

        # formdata looks like {'dockerimage': ['jupyterhub/singleuser']}"""
        dockerimage = formdata.get('dockerimage', [default])[0]

        # Don't allow users to input their own images
        if dockerimage not in self.dockerimages: dockerimage = default

        # container_prefix: The prefix of the user's container name is inherited 
        # from DockerSpawner and it defaults to "jupyter". Since a single user may launch different containers
        # (even though not simultaneously), they should have different
        # prefixes. Otherwise docker will only save one container per user. We
        # borrow the image name for the prefix.
        options = {
            'container_image': dockerimage,
            'container_prefix': '{}-{}'.format(
                super().container_prefix, dockerimage.replace('/', '-')
            )
        }
        return options 
开发者ID:ryanlovett,项目名称:imagespawner,代码行数:26,代码来源:imagespawner.py

示例6: user_for_token

# 需要导入模块: import traitlets [as 别名]
# 或者: from traitlets import default [as 别名]
def user_for_token(self, token, use_cache=True):
        """Ask the Hub to identify the user for a given token.
        Args:
            token (str): the token
            use_cache (bool): Specify use_cache=False to skip cached cookie values (default: True)
        Returns:
            user_model (dict): The user model, if a user is identified, None if authentication fails.
            The 'name' field contains the user's name.
        """
        return self._check_hub_authorization(
            url=url_path_join(self.api_url,
                "authorizations/token",
                quote(token, safe='')),
            cache_key='token:%s' % token,
            use_cache=use_cache,
        ) 
开发者ID:HDI-Project,项目名称:FeatureHub,代码行数:18,代码来源:future.py

示例7: _process_execute_error

# 需要导入模块: import traitlets [as 别名]
# 或者: from traitlets import default [as 别名]
def _process_execute_error(self, msg):
        """Handle an execute_error message"""
        self.log.debug("execute_error: %s", msg.get('content', ''))

        content = msg['content']

        traceback = '\n'.join(content['traceback']) + '\n'
        if False:
            # FIXME: For now, tracebacks come as plain text, so we can't
            # use the html renderer yet.  Once we refactor ultratb to
            # produce properly styled tracebacks, this branch should be the
            # default
            traceback = traceback.replace(' ', ' ')
            traceback = traceback.replace('\n', '<br/>')

            ename = content['ename']
            ename_styled = '<span class="error">%s</span>' % ename
            traceback = traceback.replace(ename, ename_styled)

            self._append_html(traceback)
        else:
            # This is the fallback for now, using plain text with ansi
            # escapes
            self._append_plain_text(traceback, before_prompt=not self.from_here(msg)) 
开发者ID:jupyter,项目名称:qtconsole,代码行数:26,代码来源:jupyter_widget.py

示例8: set_default_style

# 需要导入模块: import traitlets [as 别名]
# 或者: from traitlets import default [as 别名]
def set_default_style(self, colors='lightbg'):
        """ Sets the widget style to the class defaults.

        Parameters
        ----------
        colors : str, optional (default lightbg)
            Whether to use the default light background or dark
            background or B&W style.
        """
        colors = colors.lower()
        if colors=='lightbg':
            self.style_sheet = styles.default_light_style_sheet
            self.syntax_style = styles.default_light_syntax_style
        elif colors=='linux':
            self.style_sheet = styles.default_dark_style_sheet
            self.syntax_style = styles.default_dark_syntax_style
        elif colors=='nocolor':
            self.style_sheet = styles.default_bw_style_sheet
            self.syntax_style = styles.default_bw_syntax_style
        else:
            raise KeyError("No such color scheme: %s"%colors)

    #---------------------------------------------------------------------------
    # 'JupyterWidget' protected interface
    #--------------------------------------------------------------------------- 
开发者ID:jupyter,项目名称:qtconsole,代码行数:27,代码来源:jupyter_widget.py

示例9: __init__

# 需要导入模块: import traitlets [as 别名]
# 或者: from traitlets import default [as 别名]
def __init__(self, config=None, **kw):
        """
        Public constructor

        Parameters
        ----------
        config : config
            User configuration instance.
        extra_loaders : list[of Jinja Loaders]
            ordered list of Jinja loader to find templates. Will be tried in order
            before the default FileSystem ones.
        template : str (optional, kw arg)
            Template to use when exporting.
        """
        super(TemplateExporter, self).__init__(config=config, **kw)

        self.observe(self._invalidate_environment_cache,
                     list(self.traits(affects_environment=True)))
        self.observe(self._invalidate_template_cache,
                     list(self.traits(affects_template=True))) 
开发者ID:holzschu,项目名称:Carnets,代码行数:22,代码来源:templateexporter.py

示例10: _get_bucket

# 需要导入模块: import traitlets [as 别名]
# 或者: from traitlets import default [as 别名]
def _get_bucket(self, name, throw=False):
        """
        Get the bucket by it's name. Uses cache by default.
        :param name: bucket name.
        :param throw: If True raises NotFound exception, otherwise, returns
                      None.
        :return: instance of :class:`google.cloud.storage.Bucket` or None.
        """
        if not self.cache_buckets:
            try:
                return self.client.get_bucket(name)
            except NotFound:
                if throw:
                    raise
                return None
        try:
            cache = self._bucket_cache
        except AttributeError:
            self._bucket_cache = cache = {}
        try:
            return cache[name]
        except KeyError:
            try:
                bucket = self.client.get_bucket(name)
            except BrokenPipeError as e:
                if e.errno in (None, errno.EPIPE):
                    return self._get_bucket(name, throw)
                else:
                    raise
            except (BadRequest, NotFound):
                if throw:
                    raise
                return None
            cache[name] = bucket
            return bucket 
开发者ID:src-d,项目名称:jgscm,代码行数:37,代码来源:__init__.py

示例11: _google_api_url

# 需要导入模块: import traitlets [as 别名]
# 或者: from traitlets import default [as 别名]
def _google_api_url(self):
        """get default google apis url from env"""
        google_api_url = os.getenv('GOOGLE_API_URL')

        # default to googleapis.com
        if not google_api_url:
            google_api_url = 'https://www.googleapis.com'

        return google_api_url 
开发者ID:jupyterhub,项目名称:oauthenticator,代码行数:11,代码来源:google.py

示例12: _github_url_default

# 需要导入模块: import traitlets [as 别名]
# 或者: from traitlets import default [as 别名]
def _github_url_default(self):
        github_url = os.environ.get("GITHUB_URL")
        if not github_url:
            # fallback on older GITHUB_HOST config,
            # treated the same as GITHUB_URL
            host = os.environ.get("GITHUB_HOST")
            if host:
                if os.environ.get("GITHUB_HTTP"):
                    protocol = "http"
                    warnings.warn(
                        'Use of GITHUB_HOST with GITHUB_HTTP might be deprecated in the future. '
                        'Use GITHUB_URL=http://{} to set host and protocol together.'.format(
                            host
                        ),
                        PendingDeprecationWarning,
                    )
                else:
                    protocol = "https"
                github_url = "{}://{}".format(protocol, host)

        if github_url:
            if '://' not in github_url:
                # ensure protocol is included, assume https if missing
                github_url = 'https://' + github_url

            return github_url
        else:
            # nothing specified, this is the true default
            github_url = "https://github.com"

        # ensure no trailing slash
        return github_url.rstrip("/") 
开发者ID:jupyterhub,项目名称:oauthenticator,代码行数:34,代码来源:github.py

示例13: get_next_url

# 需要导入模块: import traitlets [as 别名]
# 或者: from traitlets import default [as 别名]
def get_next_url(self, user=None):
        """Get the redirect target from the state field"""
        state = self.get_state_url()
        if state:
            next_url = _deserialize_state(state).get('next_url')
            if next_url:
                return next_url
        # JupyterHub 0.8 adds default .get_next_url for a fallback
        if hasattr(BaseHandler, 'get_next_url'):
            return super().get_next_url(user)
        return url_path_join(self.hub.server.base_url, 'home') 
开发者ID:jupyterhub,项目名称:oauthenticator,代码行数:13,代码来源:oauth2.py

示例14: _default_gitlab_url

# 需要导入模块: import traitlets [as 别名]
# 或者: from traitlets import default [as 别名]
def _default_gitlab_url(self):
        """get default gitlab url from env"""
        gitlab_url = os.getenv('GITLAB_URL')
        gitlab_host = os.getenv('GITLAB_HOST')

        if not gitlab_url and gitlab_host:
            warnings.warn(
                'Use of GITLAB_HOST might be deprecated in the future. '
                'Rename GITLAB_HOST environment variable to GITLAB_URL.',
                PendingDeprecationWarning,
            )
            if gitlab_host.startswith(('https:', 'http:')):
                gitlab_url = gitlab_host
            else:
                # Hides common mistake of users which set the GITLAB_HOST
                # without a protocol specification.
                gitlab_url = 'https://{0}'.format(gitlab_host)
                warnings.warn(
                    'The https:// prefix has been added to GITLAB_HOST.'
                    'Set GITLAB_URL="{0}" instead.'.format(gitlab_host)
                )

        # default to gitlab.com
        if not gitlab_url:
            gitlab_url = 'https://gitlab.com'

        return gitlab_url 
开发者ID:jupyterhub,项目名称:oauthenticator,代码行数:29,代码来源:gitlab.py

示例15: _default_scene

# 需要导入模块: import traitlets [as 别名]
# 或者: from traitlets import default [as 别名]
def _default_scene(self):
        # could be removed when https://github.com/jovyan/pythreejs/issues/176 is solved
        # the default for pythreejs is white, which leads the volume rendering pass to make everything white
        return pythreejs.Scene(background=None) 
开发者ID:maartenbreddels,项目名称:ipyvolume,代码行数:6,代码来源:widgets.py


注:本文中的traitlets.default方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。