コード例 #1
0
 def testCommentContinuations(self):
     text = "# comment \\\n continues \\\n multiple lines"
     options = {'multilinehashcomments': True}
     ApacheConfigLexer = make_lexer(**options)
     tokens = ApacheConfigLexer().tokenize(text)
     self.assertEqual(tokens,
                      ['# comment \\\n continues \\\n multiple lines'])
コード例 #2
0
ファイル: test_loader.py プロジェクト: m0namon/apacheconfig
    def testNamedBlocks(self):
        text = """\
<a />
c = 1
</a />

<a b c>
d = 1
</a b c>
"""
        ApacheConfigLexer = make_lexer()
        ApacheConfigParser = make_parser()

        loader = ApacheConfigLoader(ApacheConfigParser(ApacheConfigLexer()))

        config = loader.loads(text)

        self.assertEqual(config,
                         {'a': [{
                             '/': {
                                 'c': '1'
                             }
                         }, {
                             'b c': {
                                 'd': '1'
                             }
                         }]})
コード例 #3
0
    def testOptionAndValueSet(self):
        text = """\
a b
a = b
a    b
a= b
a =b
a   b
a "b"
   a = "b"
   a =        'b'
"""
        ApacheConfigLexer = make_lexer()
        ApacheConfigParser = make_parser()

        parser = ApacheConfigParser(ApacheConfigLexer(), start='contents')

        ast = parser.parse(text)
        self.assertEqual(ast, [
            'contents', ['statement', 'a', 'b'], ['statement', 'a', 'b'],
            ['statement', 'a', 'b'], ['statement', 'a', 'b'],
            ['statement', 'a', 'b'], ['statement', 'a', 'b'],
            ['statement', 'a', 'b'], ['statement', 'a', 'b'],
            ['statement', 'a', 'b']
        ])
コード例 #4
0
    def testLoadWholeConfig(self):
        text = """\

# a
a = b
b = 三

<a block>
  a = b
</a>
a b
<a a block>
c "d d"
</a>
# a
"""
        ApacheConfigLexer = make_lexer()
        ApacheConfigParser = make_parser()

        loader = ApacheConfigLoader(
            ApacheConfigParser(ApacheConfigLexer()))

        config = loader.loads(text)

        self.assertEqual(
            config, {
                'b': '三',
                'a': ['b', {'block': {'a': 'b'}}, 'b',
                      {'a block': {'c': 'd d'}}]
            }
        )
コード例 #5
0
    def testDisabledNamedBlocks(self):
        text = """\
<a />
c = 1
</a />

<a b c>
d = 1
</a b c>
"""
        options = {
            'namedblocks': False
        }

        ApacheConfigLexer = make_lexer(**options)
        ApacheConfigParser = make_parser(**options)

        loader = ApacheConfigLoader(
            ApacheConfigParser(ApacheConfigLexer()), **options)

        config = loader.loads(text)

        self.assertEqual(
            config, {
                'a /': {'c': '1'}, 'a b c': {'d': '1'}
            }
        )
コード例 #6
0
    def testAutoTrue(self):
        text = """\
a 1
a on
a true
b 0
b off
b false
"""
        options = {
            'autotrue': True
        }

        ApacheConfigLexer = make_lexer(**options)
        ApacheConfigParser = make_parser(**options)

        loader = ApacheConfigLoader(
            ApacheConfigParser(ApacheConfigLexer()), **options)

        config = loader.loads(text)

        self.assertEqual(
            config, {
                'a': ['1', '1', '1'], 'b': ['0', '0', '0']
            }
        )
コード例 #7
0
ファイル: test_loader.py プロジェクト: m0namon/apacheconfig
    def testFlagBits(self):
        text = """\
mode = CLEAR | UNSECURE
"""
        options = {
            'flagbits': {
                'mode': {
                    'CLEAR': 1,
                    'STRONG': 1,
                    'UNSECURE': '32bit'
                }
            }
        }

        ApacheConfigLexer = make_lexer(**options)
        ApacheConfigParser = make_parser(**options)

        loader = ApacheConfigLoader(ApacheConfigParser(ApacheConfigLexer()),
                                    **options)

        config = loader.loads(text)

        self.assertEqual(
            config,
            {'mode': {
                'CLEAR': 1,
                'STRONG': None,
                'UNSECURE': '32bit'
            }})
コード例 #8
0
    def testDefaultConfig(self):
        text = """\
a = 1
b = 2
"""
        options = {
            'defaultconfig': {
                'b': '4',
                'c': '3'
            },
            'mergeduplicateoptions': False
        }

        ApacheConfigLexer = make_lexer(**options)
        ApacheConfigParser = make_parser(**options)

        loader = ApacheConfigLoader(
            ApacheConfigParser(ApacheConfigLexer()), **options)

        config = loader.loads(text)

        self.assertEqual(
            config, {
                'a': '1', 'b': ['4', '2'], 'c': '3'
            }
        )
コード例 #9
0
ファイル: test_loader.py プロジェクト: m0namon/apacheconfig
    def testQuotedBlockTag(self):
        text = """\
<"a b">
c = 1
</"a b">

<'d e'>
f = 1
</'d e'>

<g 'h i'>
j = 1
</g 'h i'>
    """
        ApacheConfigLexer = make_lexer()
        ApacheConfigParser = make_parser()

        loader = ApacheConfigLoader(ApacheConfigParser(ApacheConfigLexer()))

        config = loader.loads(text)

        self.assertEqual(config, {
            'a b': {
                'c': '1'
            },
            'd e': {
                'f': '1'
            },
            'g': {
                'h i': {
                    'j': '1'
                }
            }
        })
コード例 #10
0
ファイル: test_loader.py プロジェクト: m0namon/apacheconfig
    def testLineContinuationInNestedBlock(self):
        text = """\
<a>
   b abc \\
        pqr\\

   <aa>
     c value2
   </aa>
</a>
"""
        ApacheConfigLexer = make_lexer()
        ApacheConfigParser = make_parser()

        loader = ApacheConfigLoader(ApacheConfigParser(ApacheConfigLexer()))

        config = loader.loads(text)

        self.assertEqual(config,
                         {'a': {
                             'b': 'abc pqr',
                             'aa': {
                                 'c': 'value2'
                             }
                         }})
コード例 #11
0
    def testNoStripValues(self):
        text = """\
<aA>
  Bb Cc   \

  key value \\# 123 \t  \

</aA>
"""
        options = {'nostripvalues': True}

        ApacheConfigLexer = make_lexer(**options)
        ApacheConfigParser = make_parser(**options)

        parser = ApacheConfigParser(ApacheConfigLexer(), start='contents')

        ast = parser.parse(text)
        self.assertEqual(ast, [
            'contents',
            [
                'block', ('aA', ),
                [
                    'contents', ['statement', 'Bb', 'Cc   '],
                    ['statement', 'key', 'value \\# 123 \t  ']
                ], 'aA'
            ]
        ])
コード例 #12
0
    def testNamedBlocksEmptyBlocksDisabled(self):
        text = """\
<hello/>
</hello/>
<a A/>
</a A/>
<b B />
</b B />
"""

        options = {'disableemptyelementtags': True}
        ApacheConfigLexer = make_lexer(**options)
        ApacheConfigParser = make_parser(**options)

        parser = ApacheConfigParser(ApacheConfigLexer(), start='contents')

        ast = parser.parse(text)
        self.assertEqual(ast, [
            'contents', ['block', ('hello/', ), [], 'hello/'],
            ['block', (
                'a',
                ' ',
                'A/',
            ), [], 'a A/'], ['block', (
                'b',
                ' ',
                'B /',
            ), [], 'b B /']
        ])
コード例 #13
0
    def testUnicodeSupport(self):
        ApacheConfigLexer = make_lexer()
        ApacheConfigParser = make_parser()
        parser = ApacheConfigParser(ApacheConfigLexer(), start='statement')

        ast = parser.parse('a = 三')
        self.assertEqual(ast, ['statement', 'a', '三'])
コード例 #14
0
ファイル: test_loader.py プロジェクト: m0namon/apacheconfig
    def testDumpWholeConfig(self):
        text = """\

# a
a = b

<a block>
  a = b
</a>
a b
<a a block>
c "d d"
b = 三
</a>
# a
"""

        expect_text = """\
a b
<a>
  <block>
    a b
  </block>
</a>
a b
<a>
  <a block>
    c "d d"
    b 三
  </a block>
</a>
"""

        ApacheConfigLexer = make_lexer()
        ApacheConfigParser = make_parser()

        loader = ApacheConfigLoader(ApacheConfigParser(ApacheConfigLexer()))

        config = loader.loads(text)
        gen_text = loader.dumps(config)

        try:
            self.assertEqual(expect_text, gen_text)
        except AssertionError:
            # Account for non-deterministic ordering of dict items;
            # swap lines `b 三` and `c "d d"`
            lines = expect_text.split('\n')
            lines[9], lines[10] = lines[10], lines[9]
            expect_text = "\n".join(lines)
            self.assertEqual(expect_text, gen_text)

        # Testing dump(filepath, config)
        tmpd = tempfile.mkdtemp()
        filepath = os.path.join(tmpd, "config")
        loader.dump(filepath, config)
        with io.open(filepath, mode='r', encoding='utf-8') as f:
            text = f.read()
        shutil.rmtree(tmpd)
        self.assertEqual(expect_text, text)
コード例 #15
0
    def testNoStripValuesMultiline(self):
        text = """\
  Bb Cc\
 \
 """
        options = {'nostripvalues': True}
        ApacheConfigLexer = make_lexer(**options)
        tokens = ApacheConfigLexer().tokenize(text)
        self.assertEqual(tokens, ['  ', ('Bb', ' ', 'Cc  ')])
コード例 #16
0
ファイル: test_loader.py プロジェクト: m0namon/apacheconfig
    def testLoadEmptyText(self):
        text = ""
        ApacheConfigLexer = make_lexer()
        ApacheConfigParser = make_parser()

        loader = ApacheConfigLoader(ApacheConfigParser(ApacheConfigLexer()))

        config = loader.loads(text)
        self.assertEqual(config, {})
コード例 #17
0
    def testEmptyConfig(self):
        text = " \n "
        ApacheConfigLexer = make_lexer()
        ApacheConfigParser = make_parser()

        parser = ApacheConfigParser(ApacheConfigLexer(), start='config')

        ast = parser.parse(text)
        self.assertEqual(ast, ['config', []])
コード例 #18
0
ファイル: test_loader.py プロジェクト: m0namon/apacheconfig
    def testMergeListsWithSameValues(self):
        options = {}
        ApacheConfigLexer = make_lexer(**options)
        ApacheConfigParser = make_parser(**options)

        loader = ApacheConfigLoader(ApacheConfigParser(ApacheConfigLexer()),
                                    **options)

        self.assertEqual(loader._merge_lists([1], [1]), [1])
コード例 #19
0
ファイル: test_loader.py プロジェクト: m0namon/apacheconfig
    def testMergeEmptyLists(self):
        options = {}
        ApacheConfigLexer = make_lexer(**options)
        ApacheConfigParser = make_parser(**options)

        loader = ApacheConfigLoader(ApacheConfigParser(ApacheConfigLexer()),
                                    **options)

        self.assertEqual(loader._merge_lists([], []), [])
コード例 #20
0
    def testContentsWhitespace(self):
        ApacheConfigLexer = make_lexer()
        ApacheConfigParser = make_parser()

        parser = ApacheConfigParser(ApacheConfigLexer(), start='contents')

        tests = ['a b', 'a b\n', '\n a b', '\n a b  \n', '\n a \\\n b  \n']
        for test in tests:
            ast = parser.parse(test)
            self.assertEqual(ast, ['contents', ['statement', 'a', 'b']])
コード例 #21
0
 def testCommentContinuationsWithOtherComments(self):
     text = ("# comment \\\n continues \\\n multiple lines\n"
             "# comment stuff\n hello there")
     options = {'multilinehashcomments': True}
     ApacheConfigLexer = make_lexer(**options)
     tokens = ApacheConfigLexer().tokenize(text)
     self.assertEqual(tokens, [
         '# comment \\\n continues \\\n multiple lines', '\n',
         '# comment stuff', '\n ', ('hello', ' ', 'there')
     ])
コード例 #22
0
    def testMultilineBlocks(self):
        text = "<long \\\n bloc \\\n name\\\n>\n</long>"
        ApacheConfigLexer = make_lexer()
        ApacheConfigParser = make_parser()

        parser = ApacheConfigParser(ApacheConfigLexer(), start='contents')

        ast = parser.parse(text)
        self.assertEqual(ast, [
            'contents',
            ['block', ('long', ' \\\n ', 'bloc name '), [], 'long']
        ])
コード例 #23
0
ファイル: test_loader.py プロジェクト: m0namon/apacheconfig
    def testEscape(self):
        text = """\
a = \\$b
"""
        ApacheConfigLexer = make_lexer()
        ApacheConfigParser = make_parser()

        loader = ApacheConfigLoader(ApacheConfigParser(ApacheConfigLexer()))

        config = loader.loads(text)

        self.assertEqual(config, {'a': '$b'})
コード例 #24
0
    def testEmptyElementTagsDisabled(self):
        options = {'disableemptyelementtags': True}
        text = """\
<block/>
<block />
<block hello/>
"""
        ApacheConfigLexer = make_lexer(**options)
        tokens = ApacheConfigLexer().tokenize(text)
        self.assertEqual(tokens, [('block/', ), '\n',
                                  ('block', ' ', '/'), '\n',
                                  ('block', ' ', 'hello/'), '\n'])
コード例 #25
0
ファイル: test_loader.py プロジェクト: m0namon/apacheconfig
    def testKeyOnlyOption(self):
        text = """\
key2
key value
"""
        ApacheConfigLexer = make_lexer()
        ApacheConfigParser = make_parser()

        loader = ApacheConfigLoader(ApacheConfigParser(ApacheConfigLexer()))

        config = loader.loads(text)
        self.assertEqual(config, {'key2': None, 'key': 'value'})
コード例 #26
0
ファイル: test_loader.py プロジェクト: m0namon/apacheconfig
    def testLineContinuation(self):
        text = """\
a = \\
b
"""
        ApacheConfigLexer = make_lexer()
        ApacheConfigParser = make_parser()

        loader = ApacheConfigLoader(ApacheConfigParser(ApacheConfigLexer()))

        config = loader.loads(text)

        self.assertEqual(config, {'a': 'b'})
コード例 #27
0
    def testDumpWholeConfig(self):
        text = """\

# a
a = b

<a block>
  a = b
</a>
a b
<a a block>
c "d d"
b = 三
</a>
# a
"""

        expect_text = """\
a b
<a>
  <block>
    a b
  </block>
</a>
a b
<a>
  <a block>
    c "d d"
    b 三
  </a block>
</a>
"""

        ApacheConfigLexer = make_lexer()
        ApacheConfigParser = make_parser()

        loader = ApacheConfigLoader(
            ApacheConfigParser(ApacheConfigLexer()))

        config = loader.loads(text)
        gen_text = loader.dumps(config)
        self.assertEqual(expect_text, gen_text)

        # Testing dump(filepath, config)
        tmpd = tempfile.mkdtemp()
        filepath = os.path.join(tmpd, "config")
        loader.dump(filepath, config)
        with io.open(filepath, mode='r', encoding='utf-8') as f:
            text = f.read()
        shutil.rmtree(tmpd)
        self.assertEqual(expect_text, text)
コード例 #28
0
    def testIncludes(self):
        text = """\
include first.conf
<<include second.conf>>
"""
        ApacheConfigLexer = make_lexer()
        ApacheConfigParser = make_parser()

        parser = ApacheConfigParser(ApacheConfigLexer(), start='contents')

        ast = parser.parse(text)
        self.assertEqual(ast, [
            'contents', ['include', 'first.conf'], ['include', 'second.conf']
        ])
コード例 #29
0
ファイル: test_loader.py プロジェクト: m0namon/apacheconfig
    def testForceArray(self):
        text = """\
b = [1]
"""
        options = {'forcearray': True}
        ApacheConfigLexer = make_lexer(**options)
        ApacheConfigParser = make_parser(**options)

        loader = ApacheConfigLoader(ApacheConfigParser(ApacheConfigLexer()),
                                    **options)

        config = loader.loads(text)

        self.assertEqual(config, {'b': ['1']})
コード例 #30
0
ファイル: test_loader.py プロジェクト: m0namon/apacheconfig
    def testInterpolateVarsIgnoreUndefined(self):
        text = """\
b = '${a}'
"""
        options = {'interpolatevars': True, 'strictvars': False}

        ApacheConfigLexer = make_lexer(**options)
        ApacheConfigParser = make_parser(**options)

        loader = ApacheConfigLoader(ApacheConfigParser(ApacheConfigLexer()),
                                    **options)

        config = loader.loads(text)

        self.assertEqual(config, {'b': '${a}'})