示例#1
0
    def test_real(self):
        """Test some real Splunk response examples."""
        testpath = path.dirname(path.abspath(__file__))

        fh = open(path.join(testpath, "data/services.xml"), 'r')
        result = data.load(fh.read())
        self.assertTrue('feed' in result)
        self.assertTrue('author' in result.feed)
        self.assertTrue('entry' in result.feed)
        titles = [item.title for item in result.feed.entry]
        self.assertEqual(titles, [
            'alerts', 'apps', 'authentication', 'authorization', 'data',
            'deployment', 'licenser', 'messages', 'configs', 'saved',
            'scheduled', 'search', 'server', 'streams', 'broker', 'clustering',
            'masterlm'
        ])

        fh = open(path.join(testpath, "data/services.server.info.xml"), 'r')
        result = data.load(fh.read())
        self.assertTrue('feed' in result)
        self.assertTrue('author' in result.feed)
        self.assertTrue('entry' in result.feed)
        self.assertEqual(result.feed.title, 'server-info')
        self.assertEqual(result.feed.author.name, 'Splunk')
        self.assertEqual(result.feed.entry.content.cpu_arch, 'i386')
        self.assertEqual(result.feed.entry.content.os_name, 'Darwin')
        self.assertEqual(result.feed.entry.content.os_version, '10.8.0')
示例#2
0
    def test_real(self):
        """Test some real Splunk response examples."""
        testpath = path.dirname(path.abspath(__file__))

        fh = open(path.join(testpath, "data/services.xml"), 'r')
        result = data.load(fh.read())
        self.assertTrue('feed' in result)
        self.assertTrue('author' in result.feed)
        self.assertTrue('entry' in result.feed)
        titles = [item.title for item in result.feed.entry]
        self.assertEqual(
            titles,
            ['alerts', 'apps', 'authentication', 'authorization', 'data',
             'deployment', 'licenser', 'messages', 'configs', 'saved',
             'scheduled', 'search', 'server', 'streams', 'broker', 'clustering',
             'masterlm'])

        fh = open(path.join(testpath, "data/services.server.info.xml"), 'r')
        result = data.load(fh.read())
        self.assertTrue('feed' in result)
        self.assertTrue('author' in result.feed)
        self.assertTrue('entry' in result.feed)
        self.assertEqual(result.feed.title, 'server-info')
        self.assertEqual(result.feed.author.name, 'Splunk')
        self.assertEqual(result.feed.entry.content.cpu_arch, 'i386')
        self.assertEqual(result.feed.entry.content.os_name, 'Darwin')
        self.assertEqual(result.feed.entry.content.os_version, '10.8.0')
示例#3
0
    def test_dict(self):
        result = data.load("""
            <dict></dict>
        """)
        self.assertEqual(result, {})

        result = data.load("""
            <dict>
              <key name='n1'>v1</key>
              <key name='n2'>v2</key>
            </dict>""")
        self.assertEqual(result, {'n1': "v1", 'n2': "v2"})

        result = data.load("""
            <content>
              <dict>
                <key name='n1'>v1</key>
                <key name='n2'>v2</key>
              </dict>
            </content>""")
        self.assertEqual(result, {'content': {'n1': "v1", 'n2': "v2"}})

        result = data.load("""
            <content>
              <dict>
                <key name='n1'>
                  <dict>
                    <key name='n1n1'>n1v1</key>
                  </dict>
                </key>
                <key name='n2'>
                  <dict>
                    <key name='n2n1'>n2v1</key>
                  </dict>
                </key>
              </dict>
            </content>""")
        self.assertEqual(
            result,
            {'content': {
                'n1': {
                    'n1n1': "n1v1"
                },
                'n2': {
                    'n2n1': "n2v1"
                }
            }})

        result = data.load("""
            <content>
              <dict>
                <key name='n1'>
                  <list>
                    <item>1</item><item>2</item><item>3</item><item>4</item>
                  </list>
                </key>
              </dict>
            </content>""")
        self.assertEqual(result, {'content': {'n1': ['1', '2', '3', '4']}})
示例#4
0
    def test_dict(self):
        result = data.load("""
            <dict></dict>
        """)
        self.assertEqual(result, {})

        result = data.load("""
            <dict>
              <key name='n1'>v1</key>
              <key name='n2'>v2</key>
            </dict>""")
        self.assertEqual(result, {'n1': "v1", 'n2': "v2"})

        result = data.load("""
            <content>
              <dict>
                <key name='n1'>v1</key>
                <key name='n2'>v2</key>
              </dict>
            </content>""")
        self.assertEqual(result, {'content': {'n1': "v1", 'n2': "v2"}})

        result = data.load("""
            <content>
              <dict>
                <key name='n1'>
                  <dict>
                    <key name='n1n1'>n1v1</key>
                  </dict>
                </key>
                <key name='n2'>
                  <dict>
                    <key name='n2n1'>n2v1</key>
                  </dict>
                </key>
              </dict>
            </content>""")
        self.assertEqual(result, 
            {'content': {'n1': {'n1n1': "n1v1"}, 'n2': {'n2n1': "n2v1"}}})

        result = data.load("""
            <content>
              <dict>
                <key name='n1'>
                  <list>
                    <item>1</item><item>2</item><item>3</item><item>4</item>
                  </list>
                </key>
              </dict>
            </content>""")
        self.assertEqual(result, 
            {'content': {'n1': ['1', '2', '3', '4']}})
示例#5
0
    def _read_default_configuration(self):

        command = self.command
        service = command.service
        namespace = service.namespace

        try:
            response = service.get('properties/ldap/default', namespace.owner,
                                   namespace.app, namespace.sharing)
        except HTTPError as error:
            command.error_exit(
                error,
                'The default configuration stanza for ldap.conf is missing.')
            return

        body = response.body.read()
        feed = data.load(body)
        entries = feed['feed'].get('entry', ())

        if isinstance(entries, data.Record):
            entries = entries,

        settings = {
            entry['title']: entry['content'].get('$text', '')
            for entry in entries
        }
        return settings
示例#6
0
    def test_attrs(self):
        result = data.load("<e a1='v1'/>")
        self.assertEqual(result, {'e': {'a1': 'v1'}})

        result = data.load("<e a1='v1' a2='v2'/>")
        self.assertEqual(result, {'e': {'a1': 'v1', 'a2': 'v2'}})

        result = data.load("<e a1='v1'>v2</e>")
        self.assertEqual(result, {'e': {'$text': 'v2', 'a1': 'v1'}})

        result = data.load("<e a1='v1'><b>2</b></e>")
        self.assertEqual(result, {'e': {'a1': 'v1', 'b': '2'}})

        result = data.load("<e a1='v1'>v2<b>bv2</b></e>")
        self.assertEqual(result, {'e': {'a1': 'v1', 'b': 'bv2'}})

        result = data.load("<e a1='v1'><a1>v2</a1></e>")
        self.assertEqual(result, {'e': {'a1': ['v2', 'v1']}})

        result = data.load("<e1 a1='v1'><e2 a1='v1'>v2</e2></e1>")
        self.assertEqual(
            result, {'e1': {
                'a1': 'v1',
                'e2': {
                    '$text': 'v2',
                    'a1': 'v1'
                }
            }})
示例#7
0
    def test_list(self):
        result = data.load("""
            <list>
              <item>1</item><item>2</item><item>3</item><item>4</item>
            </list>""")
        self.assertEqual(result, ['1', '2', '3', '4'])

        result = data.load("""
            <content>
              <list>
                <item>1</item><item>2</item><item>3</item><item>4</item>
              </list>
            </content>""")
        self.assertEqual(result, {'content': ['1', '2', '3', '4']})

        result = data.load("""
            <content>
              <list>
                <item>
                  <list><item>1</item><item>2</item></list>
                </item>
                <item>
                  <list><item>3</item><item>4</item></list>
                </item>
              </list>
            </content>""")
        self.assertEqual(result, {'content': [['1', '2'], ['3', '4']]})

        result = data.load("""
            <content>
              <list>
                <item><dict><key name='n1'>v1</key></dict></item>
                <item><dict><key name='n2'>v2</key></dict></item>
                <item><dict><key name='n3'>v3</key></dict></item>
                <item><dict><key name='n4'>v4</key></dict></item>
              </list>
            </content>""")
        self.assertEqual(result, 
            {'content': [{'n1':"v1"}, {'n2':"v2"}, {'n3':"v3"}, {'n4':"v4"}]})
示例#8
0
    def test_list(self):
        result = data.load("""<list></list>""")
        self.assertEqual(result, [])

        result = data.load("""
            <list>
              <item>1</item><item>2</item><item>3</item><item>4</item>
            </list>""")
        self.assertEqual(result, ['1', '2', '3', '4'])

        result = data.load("""
            <content>
              <list>
                <item>1</item><item>2</item><item>3</item><item>4</item>
              </list>
            </content>""")
        self.assertEqual(result, {'content': ['1', '2', '3', '4']})

        result = data.load("""
            <content>
              <list>
                <item>
                  <list><item>1</item><item>2</item></list>
                </item>
                <item>
                  <list><item>3</item><item>4</item></list>
                </item>
              </list>
            </content>""")
        self.assertEqual(result, {'content': [['1', '2'], ['3', '4']]})

        result = data.load("""
            <content>
              <list>
                <item><dict><key name='n1'>v1</key></dict></item>
                <item><dict><key name='n2'>v2</key></dict></item>
                <item><dict><key name='n3'>v3</key></dict></item>
                <item><dict><key name='n4'>v4</key></dict></item>
              </list>
            </content>""")
        self.assertEqual(result, 
            {'content': [{'n1':"v1"}, {'n2':"v2"}, {'n3':"v3"}, {'n4':"v4"}]})

        result = data.load("""
        <ns1:dict xmlns:ns1="http://dev.splunk.com/ns/rest">
            <ns1:key name="build">101089</ns1:key>
            <ns1:key name="cpu_arch">i386</ns1:key>
            <ns1:key name="isFree">0</ns1:key>
        </ns1:dict>
        """)
        self.assertEqual(result,
        {'build': '101089', 'cpu_arch': 'i386', 'isFree': '0'})
示例#9
0
    def test_list(self):
        result = data.load("""<list></list>""")
        self.assertEqual(result, [])

        result = data.load("""
            <list>
              <item>1</item><item>2</item><item>3</item><item>4</item>
            </list>""")
        self.assertEqual(result, ['1', '2', '3', '4'])

        result = data.load("""
            <content>
              <list>
                <item>1</item><item>2</item><item>3</item><item>4</item>
              </list>
            </content>""")
        self.assertEqual(result, {'content': ['1', '2', '3', '4']})

        result = data.load("""
            <content>
              <list>
                <item>
                  <list><item>1</item><item>2</item></list>
                </item>
                <item>
                  <list><item>3</item><item>4</item></list>
                </item>
              </list>
            </content>""")
        self.assertEqual(result, {'content': [['1', '2'], ['3', '4']]})

        result = data.load("""
            <content>
              <list>
                <item><dict><key name='n1'>v1</key></dict></item>
                <item><dict><key name='n2'>v2</key></dict></item>
                <item><dict><key name='n3'>v3</key></dict></item>
                <item><dict><key name='n4'>v4</key></dict></item>
              </list>
            </content>""")
        self.assertEqual(result, 
            {'content': [{'n1':"v1"}, {'n2':"v2"}, {'n3':"v3"}, {'n4':"v4"}]})

        result = data.load("""
        <ns1:dict xmlns:ns1="http://dev.splunk.com/ns/rest">
            <ns1:key name="build">101089</ns1:key>
            <ns1:key name="cpu_arch">i386</ns1:key>
            <ns1:key name="isFree">0</ns1:key>
        </ns1:dict>
        """)
        self.assertEqual(result,
        {'build': '101089', 'cpu_arch': 'i386', 'isFree': '0'})
示例#10
0
    def test_attrs(self):
        result = data.load("<e a1='v1'/>")
        self.assertEqual(result, {'e': {'a1': 'v1'}})

        result = data.load("<e a1='v1' a2='v2'/>")
        self.assertEqual(result, {'e': {'a1': 'v1', 'a2': 'v2'}})

        result = data.load("<e a1='v1'>v2</e>")
        self.assertEqual(result, {'e': {'$text': 'v2', 'a1': 'v1'}})

        result = data.load("<e a1='v1'><b>2</b></e>")
        self.assertEqual(result, {'e': {'a1': 'v1', 'b': '2'}})

        result = data.load("<e a1='v1'>v2<b>bv2</b></e>")
        self.assertEqual(result, {'e': {'a1': 'v1', 'b': 'bv2'}})

        result = data.load("<e a1='v1'><a1>v2</a1></e>")
        self.assertEqual(result, {'e': {'a1': ['v2', 'v1']}})

        result = data.load("<e1 a1='v1'><e2 a1='v1'>v2</e2></e1>")
        self.assertEqual(result,
            {'e1': {'a1': 'v1', 'e2': {'$text': 'v2', 'a1': 'v1'}}})
示例#11
0
def _load_atom(response, match=None):
    return data.load(response.body.read(), match)
示例#12
0
def load(response):
    return data.load(response.body.read())
示例#13
0
    def test_elems(self):
        result = data.load("")
        self.assertTrue(result is None)

        result = data.load("<a></a>")
        self.assertEqual(result, {'a': None})

        result = data.load("<a>1</a>")
        self.assertEqual(result, {'a': "1"})

        result = data.load("<a><b></b></a>")
        self.assertEqual(result, {'a': {'b': None}})

        result = data.load("<a><b>1</b></a>")
        self.assertEqual(result, {'a': {'b': '1'}})

        result = data.load("<a><b></b><b></b></a>")
        self.assertEqual(result, {'a': {'b': [None, None]}})

        result = data.load("<a><b>1</b><b>2</b></a>")
        self.assertEqual(result, {'a': {'b': ['1', '2']}})

        result = data.load("<a><b></b><c></c></a>")
        self.assertEqual(result, {'a': {'b': None, 'c': None}})

        result = data.load("<a><b>1</b><c>2</c></a>")
        self.assertEqual(result, {'a': {'b': '1', 'c': '2'}})

        result = data.load("<a><b><c>1</c></b></a>")
        self.assertEqual(result, {'a': {'b': {'c': '1'}}})

        result = data.load("<a><b><c>1</c></b><b>2</b></a>")
        self.assertEqual(result, {'a': {'b': [{'c': '1'}, '2']}})
示例#14
0
def _load_atom(response, match=None):
    return data.load(response.body.read(), match)
示例#15
0
    def test_elems(self):
        result = data.load("")
        self.assertTrue(result is None)

        result = data.load("<a></a>")
        self.assertEqual(result, {'a': None})

        result = data.load("<a>1</a>")
        self.assertEqual(result, {'a': "1"})

        result = data.load("<a><b></b></a>")
        self.assertEqual(result, {'a': {'b': None}})

        result = data.load("<a><b>1</b></a>")
        self.assertEqual(result, {'a': {'b': '1'}})

        result = data.load("<a><b></b><b></b></a>")
        self.assertEqual(result, {'a': {'b': [None, None]}})

        result = data.load("<a><b>1</b><b>2</b></a>")
        self.assertEqual(result, {'a': {'b': ['1', '2']}})

        result = data.load("<a><b></b><c></c></a>")
        self.assertEqual(result, {'a': {'b': None, 'c': None}})

        result = data.load("<a><b>1</b><c>2</c></a>")
        self.assertEqual(result, {'a': {'b': '1', 'c': '2'}})

        result = data.load("<a><b><c>1</c></b></a>")
        self.assertEqual(result, {'a': {'b': {'c': '1'}}})

        result = data.load("<a><b><c>1</c></b><b>2</b></a>")
        self.assertEqual(result, {'a': {'b': [{'c': '1'}, '2']}})

        result = data.load('<e><a1>alpha</a1><a1>beta</a1></e>')
        self.assertEqual(result, {'e': {'a1': ['alpha', 'beta']}})

        result = data.load("<e a1='v1'><a1>v2</a1></e>")
        self.assertEqual(result, {'e': {'a1': ['v2', 'v1']}})
示例#16
0
    def test_elems(self):
        result = data.load("")
        self.assertTrue(result is None)

        result = data.load("<a></a>")
        self.assertEqual(result, {'a': None})

        result = data.load("<a>1</a>")
        self.assertEqual(result, {'a': "1"})

        result = data.load("<a><b></b></a>")
        self.assertEqual(result, {'a': {'b': None}})

        result = data.load("<a><b>1</b></a>")
        self.assertEqual(result, {'a': {'b': '1'}})

        result = data.load("<a><b></b><b></b></a>")
        self.assertEqual(result, {'a': {'b': [None, None]}})

        result = data.load("<a><b>1</b><b>2</b></a>")
        self.assertEqual(result, {'a': {'b': ['1', '2']}})

        result = data.load("<a><b></b><c></c></a>")
        self.assertEqual(result, {'a': {'b': None, 'c': None}})

        result = data.load("<a><b>1</b><c>2</c></a>")
        self.assertEqual(result, {'a': {'b': '1', 'c': '2'}})

        result = data.load("<a><b><c>1</c></b></a>")
        self.assertEqual(result, {'a': {'b': {'c': '1'}}})

        result = data.load("<a><b><c>1</c></b><b>2</b></a>")
        self.assertEqual(result, {'a': {'b': [{'c': '1'}, '2']}})

        result = data.load('<e><a1>alpha</a1><a1>beta</a1></e>')
        self.assertEqual(result, {'e': {'a1': ['alpha', 'beta']}})

        result = data.load("<e a1='v1'><a1>v2</a1></e>")
        self.assertEqual(result, {'e': {'a1': ['v2', 'v1']}})
示例#17
0
def load(response):
    return data.load(response.body.read())