Пример #1
0
    def test_bind_collection(self):
        class TestBoundData(BoundData):
            pass

        class TestChildData(BoundData):
            def template(self):
                return Node('', children=[PropertyNode('value', None)])

        TestBoundData.bind_collection('items',
                                      item_class=TestChildData,
                                      selector=lambda x: x.name != 'test')
        TestChildData.bind_property('value', 'value')
        n = Node('name',
                 children=[
                     Node('1', children=[PropertyNode('value', 1)]),
                     Node('2', children=[PropertyNode('value', 2)]),
                     Node('test', children=[PropertyNode('value', 3)]),
                     Node('3', children=[PropertyNode('value', 3)]),
                 ])

        d = TestBoundData(n)
        self.assertEqual(d.items[0].value, 1)
        self.assertEqual(len(d.items), 3)
        c = TestChildData()
        c.value = 4
        d.items.append(c)
        self.assertEqual(len(d.items), 4)
        self.assertEqual(d.items[-1].value, 4)
Пример #2
0
 def create_destination():
     return OptionData(
         Node(
             'option',
             Node('argument', PropertyNode('value', 'ACCEPT')),
             PropertyNode('negative', False),
             PropertyNode('name', 'j'),
         ))
Пример #3
0
 def template(self):
     return Node('line',
                 children=[
                     Node('token',
                          children=[PropertyNode('value', 'nameserver')]),
                     Node('token',
                          children=[PropertyNode('value', '8.8.8.8')]),
                 ])
Пример #4
0
 def template(self):
     return Node('line',
                 children=[
                     Node('token',
                          children=[PropertyNode('value', '127.0.0.1')]),
                     Node('token', children=[PropertyNode('value',
                                                          'eth0')]),
                 ])
Пример #5
0
 def create(template_id):
     t = OptionData.templates[template_id]
     return OptionData(
         Node(
             'option',
             *([Node('argument', PropertyNode('value', x))
                for x in t[1]] + [PropertyNode('negative', False)] +
               [PropertyNode('name', t[0])])))
Пример #6
0
 def template(self, name, *args):
     children = [PropertyNode('1', name)]
     index = 2
     for arg in args:
         children += [PropertyNode(str(index), arg)]
         index += 1
     return Node('line', PropertyNode('name', 'acl'),
                 Node('arguments', *children))
Пример #7
0
 def template(self):
     return Node(
         'append',
         Node(
             'option',
             Node('argument', PropertyNode('value', 'ACCEPT')),
             PropertyNode('negative', False),
             PropertyNode('name', 'j'),
         ))
Пример #8
0
    def test_bind_property(self):
        class TestBoundData (BoundData):
            pass
        TestBoundData.bind_property('prop', 'dataprop', getter=lambda x: 'd' + x, setter=lambda x: x[1:])

        n = Node('name', children=[
                PropertyNode('prop', 'value')
            ])

        d = TestBoundData(n)

        self.assertEqual(d.dataprop, 'dvalue')
        d.dataprop = 'dnew'
        self.assertEqual(d.dataprop, 'dnew')
        self.assertEqual(n.get('prop').value, 'new')
Пример #9
0
 def template(self):
     return Node(
         'zone',
         PropertyNode('type', 'master'),
         PropertyNode('file', 'db.example.com'),
         parameter='"example.com"',
     )
Пример #10
0
 def template(self):
     return Node(
         'unnamed',
         PropertyNode('configs', {}),
         PropertyNode('password', ''),
         PropertyNode('permissions', []),
     )
Пример #11
0
    def test_bind_property(self):
        class TestBoundData(BoundData):
            pass

        TestBoundData.bind_property('prop',
                                    'dataprop',
                                    getter=lambda x: 'd' + x,
                                    setter=lambda x: x[1:])

        n = Node('name', children=[PropertyNode('prop', 'value')])

        d = TestBoundData(n)

        self.assertEqual(d.dataprop, 'dvalue')
        d.dataprop = 'dnew'
        self.assertEqual(d.dataprop, 'dnew')
        self.assertEqual(n.get('prop').value, 'new')
Пример #12
0
 def template(self, **kwargs):
     return Node('normal_task',
                 children=[
                     PropertyNode('minute', '0'),
                     PropertyNode('hour', '0'),
                     PropertyNode('day_of_month', '1'),
                     PropertyNode('month', '1'),
                     PropertyNode('day_of_week', '1'),
                     PropertyNode('command', 'false')
                 ])
Пример #13
0
 def template(self):
     return Node('line', children=[
         Node('token', children=[PropertyNode('value', 'none')]),
         Node('token', children=[PropertyNode('value', 'none')]),
         Node('token', children=[PropertyNode('value', 'auto')]),
         Node('token', children=[PropertyNode('value', 'none')]),
         Node('token', children=[PropertyNode('value', '0')]),
         Node('token', children=[PropertyNode('value', '0')]),
     ])
Пример #14
0
class CrontabParserTest(BaseParserTest):
    parser = CrontabParser()

    source = '\n'.join([
        '#comment line',
        '* * * * * date',
        '@reboot ls -al',
        '1 * 0 1 2 date -s',
        'NAME = TEST',
    ])
    parsed = RootNode(None,
                      children=[
                          Node('normal_task',
                               comment='comment line',
                               children=[
                                   PropertyNode('minute', '*'),
                                   PropertyNode('hour', '*'),
                                   PropertyNode('day_of_month', '*'),
                                   PropertyNode('month', '*'),
                                   PropertyNode('day_of_week', '*'),
                                   PropertyNode('command', 'date'),
                               ]),
                          Node('special_task',
                               children=[
                                   PropertyNode('special', '@reboot'),
                                   PropertyNode('command', 'ls -al'),
                               ]),
                          Node('normal_task',
                               children=[
                                   PropertyNode('minute', '1'),
                                   PropertyNode('hour', '*'),
                                   PropertyNode('day_of_month', '0'),
                                   PropertyNode('month', '1'),
                                   PropertyNode('day_of_week', '2'),
                                   PropertyNode('command', 'date -s'),
                               ]),
                          Node('env_setting',
                               children=[
                                   PropertyNode('name', 'NAME'),
                                   PropertyNode('value', 'TEST'),
                               ]),
                      ])
Пример #15
0
 def template(self):
     return Node('custom')
Пример #16
0
 def template(self, **kwargs):
     return Node('special_task',
                 children=[
                     PropertyNode('special', '@reboot'),
                     PropertyNode('command', 'false')
                 ])
Пример #17
0
 def template(self):
     return Node(
         'CUSTOM',
         PropertyNode('default', '-'),
     )
Пример #18
0
 def template(self):
     return Node('program:new',
         PropertyNode('command', 'false'),
     )
Пример #19
0
 def template(self, **kwargs):
     return Node('env_setting',
                 children=[
                     PropertyNode('name', 'ENV_NAME'),
                     PropertyNode('value', 'ENV_VALUE')
                 ])
Пример #20
0
    def parse(self, content):
        root = RootNode()
        lines = [l.strip() for l in content.splitlines() if l]
        comment = None
        for line in lines:
            if line.startswith('#'):
                comment = '\n'.join([comment, line]) if comment else line[1:]
                continue
            elif line.startswith('@'):
                special, command = line.split(' ', 1)
                node = Node('special_task', comment=comment)
                node.append(PropertyNode('special', special))
                node.append(PropertyNode('command', command))

            else:
                split_line = line.split(' ', 5)
                if len(split_line) <= 3 and '=' in line:
                    name, value = [n.strip() for n in line.split('=')]
                    if not name:
                        continue
                    node = Node('env_setting', comment=comment)
                    node.append(PropertyNode('name', name))
                    node.append(PropertyNode('value', value))
                elif len(split_line) == 6:
                    node = Node('normal_task', comment=comment)
                    node.append(PropertyNode('minute', split_line[0]))
                    node.append(PropertyNode('hour', split_line[1]))
                    node.append(PropertyNode('day_of_month', split_line[2]))
                    node.append(PropertyNode('month', split_line[3]))
                    node.append(PropertyNode('day_of_week', split_line[4]))
                    node.append(PropertyNode('command', split_line[5]))
                else:
                    continue
            root.append(node)
            comment = None
        root.comment = comment
        return root
Пример #21
0
 def template(self):
     return Node(
         'program:new',
         PropertyNode('command', '127.0.0.1'),
     )
Пример #22
0
 def template(self):
     return Node(
         'line',
         PropertyNode('name', 'http_access'),
         Node('arguments', PropertyNode('1', ''))
     )
Пример #23
0
 def template(self):
     return Node(
         'line',
         PropertyNode('name', 'https_port'),
         Node('arguments', PropertyNode('1', '3128'))
     )
Пример #24
0
 def remove_include(self, node):
     return Node('include', children=[PropertyNode('files', node.files)])
Пример #25
0
 def template(self):
     return Node('localhost', PropertyNode('options', ''))
Пример #26
0
 def template(self):
     return Node('/', Node('clients'))
Пример #27
0
 def template(self):
     return Node(
         'line',
         Node('token', PropertyNode('value', 'mibs')),
         Node('token', PropertyNode('value', 'IF-MIB')),
     )
Пример #28
0
 def template(self):
     return Node(
         'line', *[
             Node('token', children=[PropertyNode('value', '')])
             for x in GroupData.fields
         ])
Пример #29
0
 def template(self):
     return Node(
         'line',
         Node('token', PropertyNode('value', 'rwcommunity')),
         Node('token', PropertyNode('value', 'public 192.168.0.0/24')),
     )
Пример #30
0
 def template(self):
     return Node(
         'line',
         Node('token', PropertyNode('value', 'informsink')),
         Node('token', PropertyNode('value', 'localhost public')),
     )
Пример #31
0
 def template(self):
     return Node(
         'share',
         *[PropertyNode(x, y) for x, y in zip(ShareData.fields, ShareData.defaults)]
     )
Пример #32
0
    def parse(self, content):
        root = RootNode()
        lines = [l.strip() for l in content.splitlines() if l]
        comment = None
        for line in lines:
            if line.startswith('#'):
                comment = '\n'.join([comment, line]) if comment else line[1:]
                continue
            elif line.startswith('@'):
                special, command = line.split(' ', 1)
                node = Node('special_task', comment=comment)
                node.append(PropertyNode('special', special))
                node.append(PropertyNode('command', command))

            else:
                split_line = line.split(' ', 5)
                if len(split_line) <= 3 and '=' in line:
                    name, value = [n.strip() for n in line.split('=')]
                    if not name:
                        continue
                    node = Node('env_setting', comment=comment)
                    node.append(PropertyNode('name', name))
                    node.append(PropertyNode('value', value))
                elif len(split_line) == 6:
                    node = Node('normal_task', comment=comment)
                    node.append(PropertyNode('minute', split_line[0]))
                    node.append(PropertyNode('hour', split_line[1]))
                    node.append(PropertyNode('day_of_month', split_line[2]))
                    node.append(PropertyNode('month', split_line[3]))
                    node.append(PropertyNode('day_of_week', split_line[4]))
                    node.append(PropertyNode('command', split_line[5]))
                else:
                    continue
            root.append(node)
            comment = None
        root.comment = comment
        return root