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


Python box.Box方法代码示例

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


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

示例1: from_json

# 需要导入模块: import box [as 别名]
# 或者: from box import Box [as 别名]
def from_json(cls, json_string: str = None, filename: str = None, encoding: str = 'utf-8', errors: str = 'strict',
                  multiline: bool = False, **kwargs):
        """
        Transform a json object string into a BoxList object. If the incoming
        json is a dict, you must use Box.from_json.

        :param json_string: string to pass to `json.loads`
        :param filename: filename to open and pass to `json.load`
        :param encoding: File encoding
        :param errors: How to handle encoding errors
        :param multiline: One object per line
        :param kwargs: parameters to pass to `Box()` or `json.loads`
        :return: BoxList object from json data
        """
        bx_args = {}
        for arg in list(kwargs.keys()):
            if arg in BOX_PARAMETERS:
                bx_args[arg] = kwargs.pop(arg)

        data = _from_json(json_string, filename=filename, encoding=encoding,
                          errors=errors, multiline=multiline, **kwargs)

        if not isinstance(data, list):
            raise BoxError(f'json data not returned as a list, but rather a {type(data).__name__}')
        return cls(data, **bx_args) 
开发者ID:cdgriffith,项目名称:Box,代码行数:27,代码来源:box_list.py

示例2: from_toml

# 需要导入模块: import box [as 别名]
# 或者: from box import Box [as 别名]
def from_toml(cls, toml_string: str = None, filename: str = None, key_name: str = 'toml',
                  encoding: str = 'utf-8', errors: str = 'strict', **kwargs):
        """
        Transforms a toml string or file into a BoxList object

        :param toml_string: string to pass to `toml.load`
        :param filename: filename to open and pass to `toml.load`
        :param key_name: Specify the name of the key to pull the list from
            (cannot directly convert from toml)
        :param encoding: File encoding
        :param errors: How to handle encoding errors
        :param kwargs: parameters to pass to `Box()`
        :return:
        """
        bx_args = {}
        for arg in list(kwargs.keys()):
            if arg in BOX_PARAMETERS:
                bx_args[arg] = kwargs.pop(arg)

        data = _from_toml(toml_string=toml_string, filename=filename, encoding=encoding, errors=errors)
        if key_name not in data:
            raise BoxError(f'{key_name} was not found.')
        return cls(data[key_name], **bx_args) 
开发者ID:cdgriffith,项目名称:Box,代码行数:25,代码来源:box_list.py

示例3: test_box_list

# 需要导入模块: import box [as 别名]
# 或者: from box import Box [as 别名]
def test_box_list(self):
        new_list = BoxList({'item': x} for x in range(0, 10))
        new_list.extend([{'item': 22}])
        assert new_list[-1].item == 22
        new_list.append([{'bad_item': 33}])
        assert new_list[-1][0].bad_item == 33
        assert repr(new_list).startswith("<BoxList:")
        for x in new_list.to_list():
            assert not isinstance(x, (BoxList, Box))
        new_list.insert(0, {'test': 5})
        new_list.insert(1, ['a', 'b'])
        new_list.append('x')
        assert new_list[0].test == 5
        assert isinstance(str(new_list), str)
        assert isinstance(new_list[1], BoxList)
        assert not isinstance(new_list.to_list(), BoxList) 
开发者ID:cdgriffith,项目名称:Box,代码行数:18,代码来源:test_box_list.py

示例4: __init__

# 需要导入模块: import box [as 别名]
# 或者: from box import Box [as 别名]
def __init__(self, title=None, description=None, role_ids=None, options=None, votes=None, timestamp=None):
        super().__init__()

        if role_ids is None:
            role_ids = BoxList()

        if options is None:
            options = BoxList()

        if votes is None:
            votes = Box()

        self.title = title
        self.description = description
        self.role_ids = role_ids
        self.options = options
        self.votes = votes
        self.timestamp = timestamp 
开发者ID:smlbiobot,项目名称:SML-Cogs,代码行数:20,代码来源:votemanager.py

示例5: test_prepare_environment_with_git

# 需要导入模块: import box [as 别名]
# 或者: from box import Box [as 别名]
def test_prepare_environment_with_git(self):
        repo = self.mk_repo()
        conf = ConfigLoader.load(workspace_dir=repo.working_dir)
        with StepRunner(conf) as r:
            step = Box(
                {"name": "a", "env": {"FOO": "BAR"}, "secrets": ["A"]}, default_box=True
            )
            os.environ["A"] = "BC"
            env = r._prepare_environment(step, {"other": "b"})
            expected = {
                "FOO": "BAR",
                "A": "BC",
                "other": "b",
                "GIT_COMMIT": conf.git_commit,
                "GIT_BRANCH": conf.git_branch,
                "GIT_SHA_SHORT": conf.git_sha_short,
                "GIT_REMOTE_ORIGIN_URL": conf.git_remote_origin_url,
            }
            self.assertDictEqual(expected, env)
            os.environ.pop("A") 
开发者ID:getpopper,项目名称:popper,代码行数:22,代码来源:test_runner.py

示例6: test_config_defaults

# 需要导入模块: import box [as 别名]
# 或者: from box import Box [as 别名]
def test_config_defaults(self):
        conf = ConfigLoader.load()
        expected = Box(
            {
                "skip_clone": False,
                "engine_name": "docker",
                "engine_opts": {},
                "resman_name": "host",
                "resman_opts": {},
                "skip_pull": False,
                "dry_run": False,
                "workspace_dir": os.getcwd(),
                "quiet": False,
                "reuse": False,
                "pty": False,
                "allow_undefined_secrets_in_ci": False,
            },
            default_box=True,
        )

        self.assertEqual(expected, TestPopperConfig.extract_dict(expected, conf)) 
开发者ID:getpopper,项目名称:popper,代码行数:23,代码来源:test_config.py

示例7: validate_regex

# 需要导入模块: import box [as 别名]
# 或者: from box import Box [as 别名]
def validate_regex(response, expression, header=None):
    """Make sure the response matches a regex expression

    Args:
        response (Response): requests.Response object
        expression (str): Regex expression to use
        header (str): Match against a particular header instead of the body

    Returns:
        dict: dictionary of regex: boxed name capture groups
    """
    if header:
        content = response.headers[header]
    else:
        content = response.text

    match = re.search(expression, content) or False
    assert match

    return {"regex": Box(match.groupdict())} 
开发者ID:taverntesting,项目名称:tavern,代码行数:22,代码来源:helpers.py

示例8: from_data

# 需要导入模块: import box [as 别名]
# 或者: from box import Box [as 别名]
def from_data(self, data, cached, ts, response):
        self.cached = cached
        self.last_updated = ts
        self.raw_data = data
        self.response = response
        if isinstance(data, list):
            self._boxed_data = BoxList(
                data, camel_killer_box=not self.client.camel_case
            )
        else:
            self._boxed_data = Box(
                data, camel_killer_box=not self.client.camel_case
            )
        return self 
开发者ID:cgrok,项目名称:clashroyale,代码行数:16,代码来源:models.py

示例9: test_k8s_nodes_ready

# 需要导入模块: import box [as 别名]
# 或者: from box import Box [as 别名]
def test_k8s_nodes_ready(self):
        with patch('eksrollup.lib.k8s.get_k8s_nodes') as get_k8s_nodes_mock:
            box = Box(self.k8s_response_mock, ordered_box=True)
            get_k8s_nodes_mock.return_value = box['items']
            self.assertTrue(k8s_nodes_ready(2, 1), True) 
开发者ID:hellofresh,项目名称:eks-rolling-update,代码行数:7,代码来源:test_k8s.py

示例10: test_k8s_nodes_ready_fail

# 需要导入模块: import box [as 别名]
# 或者: from box import Box [as 别名]
def test_k8s_nodes_ready_fail(self):
        with patch('eksrollup.lib.k8s.get_k8s_nodes') as get_k8s_nodes_mock:
            box = Box(self.k8s_response_mock_unhealthy, ordered_box=True)
            get_k8s_nodes_mock.return_value = box['items']
            self.assertFalse(k8s_nodes_ready(2, 1), False) 
开发者ID:hellofresh,项目名称:eks-rolling-update,代码行数:7,代码来源:test_k8s.py

示例11: __init__

# 需要导入模块: import box [as 别名]
# 或者: from box import Box [as 别名]
def __init__(self, iterable: Iterable = None, box_class: box.Box = box.Box, **box_options):
        self.box_class = box_class
        self.box_options = box_options
        self.box_org_ref = self.box_org_ref = id(iterable) if iterable else 0
        if iterable:
            for x in iterable:
                self.append(x)
        if box_options.get('frozen_box'):
            def frozen(*args, **kwargs):
                raise BoxError('BoxList is frozen')

            for method in ['append', 'extend', 'insert', 'pop', 'remove', 'reverse', 'sort']:
                self.__setattr__(method, frozen) 
开发者ID:cdgriffith,项目名称:Box,代码行数:15,代码来源:box_list.py

示例12: to_list

# 需要导入模块: import box [as 别名]
# 或者: from box import Box [as 别名]
def to_list(self):
        new_list = []
        for x in self:
            if x is self:
                new_list.append(new_list)
            elif isinstance(x, box.Box):
                new_list.append(x.to_dict())
            elif isinstance(x, BoxList):
                new_list.append(x.to_list())
            else:
                new_list.append(x)
        return new_list 
开发者ID:cdgriffith,项目名称:Box,代码行数:14,代码来源:box_list.py

示例13: test_config_default

# 需要导入模块: import box [as 别名]
# 或者: from box import Box [as 别名]
def test_config_default(self):
        bx4 = Box(default_box=True, default_box_attr=ConfigBox)
        assert isinstance(bx4.bbbbb, ConfigBox) 
开发者ID:cdgriffith,项目名称:Box,代码行数:5,代码来源:test_config_box.py

示例14: test_property_box

# 需要导入模块: import box [as 别名]
# 或者: from box import Box [as 别名]
def test_property_box(self):
        td = test_dict.copy()
        td['inner'] = {'CamelCase': 'Item'}

        pbox = SBox(td, camel_killer_box=True)
        assert isinstance(pbox.inner, SBox)
        assert pbox.inner.camel_case == 'Item'
        assert json.loads(pbox.json)['inner']['camel_case'] == 'Item'
        test_item = yaml.load(pbox.yaml, Loader=yaml.SafeLoader)
        assert test_item['inner']['camel_case'] == 'Item'
        assert repr(pbox['inner']).startswith('<ShorthandBox')
        assert not isinstance(pbox.dict, Box)
        assert pbox.dict['inner']['camel_case'] == 'Item'
        assert pbox.toml.startswith('key1 = "value1"') 
开发者ID:cdgriffith,项目名称:Box,代码行数:16,代码来源:test_sbox.py

示例15: __init__

# 需要导入模块: import box [as 别名]
# 或者: from box import Box [as 别名]
def __init__(self, config_path=None):
        with open(config_path) as f:
            self.config = Box(yaml.load(f)) 
开发者ID:RoyaleAPI,项目名称:cr-api-data,代码行数:5,代码来源:quests.py


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