Example #1
0
 def test_boolean(self):
     data = (
         "a : True;" \
         "b : False"
     )
     valid = { "a" : True, "b" : False }
     self.assertEqual(ucl.load(data), valid)
Example #2
0
    def hbds_release_branch(self) -> str:
        """Translate the release into a HardenedBSD release git branch name."""
        if self._hbsd_release_branch is not None:
            return self._hbsd_release_branch

        if self.fetched is False:
            raise libioc.errors.ReleaseNotFetched(
                name=self.name,
                logger=self.logger
            )

        root_dataset_mountpoint = self.root_dataset.mountpoint
        source_file = f"{root_dataset_mountpoint}/etc/hbsd-update.conf"

        if not os.path.isfile(source_file):
            raise libioc.errors.ReleaseUpdateBranchLookup(
                release_name=self.name,
                reason=f"{source_file} not found",
                logger=self.logger
            )

        libioc.helpers.require_no_symlink(source_file, logger=self.logger)

        with open(source_file, "r", encoding="utf-8") as f:
            import ucl
            hbsd_update_conf = ucl.load(f.read())
            self._hbsd_release_branch = hbsd_update_conf["branch"]
            return str(self._hbsd_release_branch)
Example #3
0
 def test_boolean(self):
     totest = (
         "a : True;" \
         "b : False"
     )
     correct = {"a": True, "b": False}
     self.assertEqual(ucl.load(totest), correct)
Example #4
0
 def test_every_type(self):
     totest="""{
         "key1": value;
         "key2": value2;
         "key3": "value;"
         "key4": 1.0,
         "key5": -0xdeadbeef
         "key6": 0xdeadbeef.1
         "key7": 0xreadbeef
         "key8": -1e-10,
         "key9": 1
         "key10": true
         "key11": no
         "key12": yes
     }"""
     correct = {
             'key1': 'value',
             'key2': 'value2',
             'key3': 'value;',
             'key4': 1.0,
             'key5': -3735928559,
             'key6': '0xdeadbeef.1',
             'key7': '0xreadbeef',
             'key8': -1e-10,
             'key9': 1,
             'key10': 'true',
             'key11': 'false',
             'key12': 'true',
             }
     self.assertEqual(ucl.load(totest), correct)
Example #5
0
 def test_boolean(self):
     totest = (
         "a : True;" \
         "b : False"
     )
     correct = {"a" : True, "b" : False}
     self.assertEqual(ucl.load(totest), correct)
Example #6
0
    def hbds_release_branch(self) -> str:
        """Translate the release into a HardenedBSD release git branch name."""
        if self._hbsd_release_branch is not None:
            return self._hbsd_release_branch

        if self.fetched is False:
            raise iocage.errors.ReleaseNotFetched(
                name=self.name,
                logger=self.logger
            )

        root_dataset_mountpoint = self.root_dataset.mountpoint
        source_file = f"{root_dataset_mountpoint}/etc/hbsd-update.conf"

        if not os.path.isfile(source_file):
            raise iocage.errors.ReleaseUpdateBranchLookup(
                release_name=self.name,
                reason=f"{source_file} not found",
                logger=self.logger
            )

        with open(source_file, "r") as f:
            import ucl
            hbsd_update_conf = ucl.load(f.read())
            self._hbsd_release_branch = hbsd_update_conf["branch"]
            return str(self._hbsd_release_branch)
Example #7
0
 def test_boolean(self):
     data = (
         "a : True;" \
         "b : False"
     )
     valid = { "a" : True, "b" : False }
     self.assertEqual(ucl.load(data), valid)
Example #8
0
 def test_every_type(self):
     data = ("""{
         "key1": value;
         "key2": value2;
         "key3": "value;"
         "key4": 1.0,
         "key5": -0xdeadbeef
         "key6": 0xdeadbeef.1
         "key7": 0xreadbeef
         "key8": -1e-10,
         "key9": 1
         "key10": true
         "key11": no
         "key12": yes
     }""")
     valid = {
         'key1': 'value',
         'key2': 'value2',
         'key3': 'value;',
         'key4': 1.0,
         'key5': -3735928559,
         'key6': '0xdeadbeef.1',
         'key7': '0xreadbeef',
         'key8': -1e-10,
         'key9': 1,
         'key10': True,
         'key11': False,
         'key12': True,
         }
     self.assertEqual(ucl.load(data), valid)
Example #9
0
 def test_every_type(self):
     data = ("""{
         "key1": value;
         "key2": value2;
         "key3": "value;"
         "key4": 1.0,
         "key5": -0xdeadbeef
         "key6": 0xdeadbeef.1
         "key7": 0xreadbeef
         "key8": -1e-10,
         "key9": 1
         "key10": true
         "key11": no
         "key12": yes
     }""")
     valid = {
         'key1': 'value',
         'key2': 'value2',
         'key3': 'value;',
         'key4': 1.0,
         'key5': -3735928559,
         'key6': '0xdeadbeef.1',
         'key7': '0xreadbeef',
         'key8': -1e-10,
         'key9': 1,
         'key10': True,
         'key11': False,
         'key12': True,
         }
     self.assertEqual(ucl.load(data), valid)
Example #10
0
    def test_example(self):
        # load in sample UCL
        u = ucl.load(_ucl_inp)

        # Output and read back the JSON
        uj = json.loads(json.dumps(u))

        self.assertEqual(uj, _json_res)
Example #11
0
    def read_data(self):
        with open(JailConfigLegacy.__get_config_path(self), "r") as conf:
            data = ucl.load(conf.read())

            try:
                if data["type"] == "basejail":
                    data["basejail"] = "on"
                    data["clonejail"] = "off"
                    data["basejail_type"] = "zfs"
                    data["type"] = "jail"
            except:
                pass

            return data
Example #12
0
 def test_1_in(self):
     valid = {
         'key1': [
             'value',
             'value2',
             'value;',
             1.0,
             -0xdeadbeef,
             '0xdeadbeef.1',
             '0xreadbeef',
             -1e-10,
             1,
             True,
             False,
             True,
         ]
     }
     with open("../tests/basic/1.in", "r") as in1:
         self.assertEqual(ucl.load(in1.read()), valid)
Example #13
0
    def hbds_release_branch(self):

        if self._hbsd_release_branch is not None:
            return self._hbsd_release_branch

        if self.fetched is False:
            raise libiocage.lib.errors.ReleaseNotFetched(name=self.name,
                                                         logger=self.logger)

        source_file = f"{self.root_dataset.mountpoint}/etc/hbsd-update.conf"

        if not os.path.isfile(source_file):
            raise libiocage.lib.errors.ReleaseUpdateBranchLookup(
                release_name=self.name,
                reason=f"{source_file} not found",
                logger=self.logger)

        with open(source_file, "r") as f:
            hbsd_update_conf = ucl.load(f.read())
            self._hbsd_release_branch = hbsd_update_conf["branch"]
            return self._hbsd_release_branch
Example #14
0
 def test_float(self):
     data  = "a : 1.1"
     valid = {"a" : 1.1}
     self.assertEqual(ucl.load(data), valid)
Example #15
0
 def test_str(self):
     data  = "a : b"
     valid = { "a" : "b" }
     self.assertEqual(ucl.load(data), valid)
Example #16
0
 def test_braced_int(self):
     data  = "{a : 1}"
     valid = { "a" : 1 }
     self.assertEqual(ucl.load(data), valid)
Example #17
0
 def test_none(self):
     self.assertEqual(ucl.load(None), None)
Example #18
0
 def test_no_args(self):
     with self.assertRaises(TypeError):
         ucl.load()
Example #19
0
 def test_1_in(self):
     with open("../tests/basic/1.in", "r") as in1:
         self.assertEqual(ucl.load(in1.read()), {'key1': 'value'})
Example #20
0
 def test_comment_ignored(self):
     self.assertEqual(ucl.load("{/*1*/}"), {})
Example #21
0
 def test_none(self):
     r = ucl.load(None)
     self.assertEqual(r, None)
Example #22
0
 def test_multi_args(self):
     with self.assertRaises(TypeError):
         ucl.load(0,0)
Example #23
0
 def test_nested_int(self):
     data  = "a : { b : 1 }"
     valid = { "a" : { "b" : 1 } }
     self.assertEqual(ucl.load(data), valid)
Example #24
0
 def test_str(self):
     data  = "a : b"
     valid = { "a" : "b" }
     self.assertEqual(ucl.load(data), valid)
Example #25
0
 def test_multi_args(self):
     self.assertRaises(TypeError, lambda: ucl.load(0,0))
Example #26
0
 def test_no_args(self):
     self.assertRaises(TypeError, lambda: ucl.load())
Example #27
0
 def test_empty_ucl(self):
     self.assertEqual(ucl.load("{}"), {})
Example #28
0
 def test_single_square_forward(self):
     self.assertEqual(ucl.load("["), [])
Example #29
0
 def test_int(self):
     r = ucl.load("a : 1")
     self.assertEqual(ucl.load("a : 1"), { "a" : 1 } )
Example #30
0
 def test_float(self):
     data  = "a : 1.1"
     valid = {"a" : 1.1}
     self.assertEqual(ucl.load(data), valid)
Example #31
0
 def test_braced_int(self):
     self.assertEqual(ucl.load("{a : 1}"), { "a" : 1 } )
Example #32
0
 def test_braced_int(self):
     data  = "{a : 1}"
     valid = { "a" : 1 }
     self.assertEqual(ucl.load(data), valid)
Example #33
0
 def test_nested_int(self):
     self.assertEqual(ucl.load("a : { b : 1 }"), { "a" : { "b" : 1 } })
Example #34
0
 def test_null(self):
     data  = "a: null"
     valid = { "a" : None }
     self.assertEqual(ucl.load(data), valid)
Example #35
0
 def test_str(self):
     self.assertEqual(ucl.load("a : b"), {"a" : "b"})
Example #36
0
 def test_null(self):
     data  = "a: null"
     valid = { "a" : None }
     self.assertEqual(ucl.load(data), valid)
Example #37
0
 def test_multi_args(self):
     with self.assertRaises(TypeError):
         ucl.load(0,0)
Example #38
0
 def test_nested_int(self):
     data  = "a : { b : 1 }"
     valid = { "a" : { "b" : 1 } }
     self.assertEqual(ucl.load(data), valid)
Example #39
0
 def test_single_brace(self):
     self.assertEqual(ucl.load("{"), {})
Example #40
0
 def test_no_args(self):
     with self.assertRaises(TypeError):
         ucl.load()
Example #41
0
 def test_single_back_brace(self):
     ucl.load("}")
Example #42
0
 def test_none(self):
     self.assertEqual(ucl.load(None), None)
Example #43
0
 def test_single_square_forward(self):
     self.assertEqual(ucl.load("["), [])
Example #44
0
 def test_single_back_brace(self):
     self.assertEqual(ucl.load("}"), {})
Example #45
0
 def test_invalid_ucl(self):
     with self.assertRaisesRegex(ValueError, "unfinished key$"):
         ucl.load('{ "var"')
Example #46
0
 def test_invalid_ucl(self):
     with self.assertRaisesRegex(ValueError, "unfinished key$"):
         ucl.load('{ "var"')
Example #47
0
 def test_comment_ignored(self):
     self.assertEqual(ucl.load("{/*1*/}"), {})
Example #48
0
 def test_float(self):
     self.assertEqual(ucl.load("a : 1.1"), {"a" : 1.1})
Example #49
0
 def test_empty_ucl(self):
     self.assertEqual(ucl.load("{}"), {})
Example #50
0
 def test_empty_ucl(self):
     r = ucl.load("{}")
     self.assertEqual(r, {})
Example #51
0
 def _read(self) -> dict:
     import ucl
     data = dict(ucl.load(open(self.path).read()))
     if self.logger is not None:
         self.logger.spam(f"{self._file} was read from {self.path}")
     return data