def test_sphinx_eql_type_06(self):
        src = r'''
        .. eql:type:: std::int64

            An integer.

        .. eql:type:: std::array

            Array.

        Testing :eql:type:`XXX <array<int64>>` ref.
        Testing :eql:type:`array\<int64\>` ref.
        Testing :eql:type:`array\<int64\> <array<int64>>` ref.
        Testing :eql:type:`array\<array\<int64\>\>` ref.
        '''

        out = self.build(src, format='xml')
        x = requests_xml.XML(xml=out)

        self.assertEqual(
            x.xpath('''
                //paragraph /
                reference[@eql-type="type"] /
                literal / text()
            '''),
            ['XXX', 'array<int64>', 'array<int64>', 'array<array<int64>>'])
    def test_sphinx_eql_constr_01(self):
        src = '''
        .. eql:type:: std::int64

            An integer.

        .. eql:type:: any

            any.

        .. eql:constraint:: std::max_len_value(v: any)

            blah

        Testing :eql:constraint:`XXX <max_len_value>` ref.
        Testing :eql:constraint:`max_len_value` ref.
        '''

        out = self.build(src, format='xml')
        x = requests_xml.XML(xml=out)

        constr = x.xpath('//desc[@desctype="constraint"]')
        self.assertEqual(len(constr), 1)
        constr = constr[0]

        self.assertEqual(constr.attrs['summary'], 'blah')

        self.assertEqual(
            x.xpath('''
                //paragraph /
                reference[@eql-type="constraint" and
                    @refid="constraint::std::max_len_value"] /
                literal / text()
            '''),
            ['XXX', 'max_len_value'])
    def test_sphinx_eql_op_02(self):
        src = '''
        .. eql:type:: any

            123

        .. eql:operator:: IS: A IS B

            :optype A: any
            :optype B: type
            :resulttype: any

            Is

        :eql:op:`XXX <IS>`
        '''

        out = self.build(src, format='xml')
        x = requests_xml.XML(xml=out)

        self.assertEqual(
            x.xpath('''
                //field[@eql-opname="B"] /
                field_body / * / literal_strong / text()
            '''),
            ['B'])
    def test_sphinx_eql_kw_01(self):
        src = '''
        .. eql:keyword:: SET OF

            blah

        some text

        :eql:kw:`XXX <SET OF>`
        '''

        out = self.build(src, format='xml')
        x = requests_xml.XML(xml=out)

        self.assertEqual(
            len(x.xpath('''
                //desc[@desctype="keyword"] /

                desc_signature[@eql-name="SET OF"] /
                *[
                    (self::desc_annotation and text()="keyword") or
                    (self::desc_name and text()="SET OF")
                ]
            ''')),
            2)

        self.assertEqual(
            x.xpath('''
                //paragraph /
                reference[@eql-type="keyword" and @refid="keyword::SET-OF"] /
                literal / text()
            '''),
            ['XXX'])
def get_resourcemanager_webapp():
    yarn_site_xml = "/etc/hadoop/conf/yarn-site.xml"
    with open(yarn_site_xml) as f:
        doc = re.sub(r'<?.*(encoding=\"UTF-8\"|encoding=\'UTF-8\').*?>',
                     '',
                     f.read(),
                     flags=re.I)
        j = json.loads(requests_xml.XML(xml=doc).json())
        return [
            p['value']['$'] for p in j['configuration']['property']
            if 'yarn.resourcemanager.webapp.address' in p['name']['$']
        ]
示例#6
0
    def test_sphinx_eql_inline_role_01(self):
        src = '''
        a test of :eql:synopsis:`WITH <aaaa>`.
        '''

        out = self.build(src, format='xml')
        x = requests_xml.XML(xml=out)

        self.assertEqual(
            x.xpath('''
                //literal[@eql-lang="edgeql-synopsis"] / text()
            '''), ['WITH <aaaa>'])
    def test_sphinx_eql_func_01(self):
        src = '''
        Testing DESC !! :eql:func-desc:`test` !! >> ref.

        .. eql:type:: std::int64

            An integer.

        .. eql:type:: any

            any.

        .. eql:function:: std::test(v: any) -> any

            :index: xxx YyY

            A super function.

        Testing :eql:func:`XXX <test>` ref.
        Testing :eql:func:`test` ref.
        '''

        out = self.build(src, format='xml')
        x = requests_xml.XML(xml=out)

        func = x.xpath('//desc[@desctype="function"]')
        self.assertEqual(len(func), 1)
        func = func[0]

        self.assertEqual(func.attrs['summary'], 'A super function.')
        self.assertIn('!! A super function. !!', out)

        self.assertEqual(
            x.xpath('//desc_returns / text()'),
            ['any'])

        self.assertEqual(
            x.xpath('''
                //paragraph /
                reference[@eql-type="function" and
                    @refid="function::std::test"] /
                literal / text()
            '''),
            ['XXX', 'test()'])

        self.assertEqual(
            x.xpath('''
                //field[@eql-name="index"] / field_body / paragraph / text()
            '''),
            ['xxx YyY'])
    def test_sphinx_eql_op_01(self):
        src = '''
        Testing ?? :eql:op-desc:`PLUS` ??.

        .. eql:type:: int64

            int64

        .. eql:type:: str

            123

        .. eql:operator:: PLUS: A + B

            :optype A: int64 or str
            :optype B: int64 or str
            :resulttype: int64 or str

            Arithmetic addition.

        some text

        :eql:op:`XXX <PLUS>`
        '''

        out = self.build(src, format='xml')
        x = requests_xml.XML(xml=out)

        self.assertIn('Testing ?? Arithmetic addition. ??.', out)

        self.assertEqual(
            len(x.xpath('''
                //desc_signature[@eql-name="PLUS" and @eql-signature="A + B"] /
                *[
                    (self::desc_annotation and text()="operator") or
                    (self::desc_name and text()="A + B")
                ]
            ''')),
            2)

        self.assertEqual(len(x.xpath('//field[@eql-name="operand"]')), 2)
        self.assertEqual(len(x.xpath('//field[@eql-name="resulttype"]')), 1)

        self.assertEqual(
            x.xpath('''
                //paragraph /
                reference[@eql-type="operator" and @refid="operator::PLUS"] /
                literal / text()
            '''),
            ['XXX'])
示例#9
0
    def test_eql_constr_1(self):
        src = '''
        .. eql:type:: std::int64

            An integer.

        .. eql:type:: any

            any.

        .. eql:constraint:: std::maxlength(any)

            :param $0: param
            :paramtype $0: any

            blah

        Testing :eql:constraint:`XXX <maxlength>` ref.
        Testing :eql:constraint:`maxlength` ref.
        '''

        out = self.build(src, format='xml')
        x = requests_xml.XML(xml=out)

        constr = x.xpath('//desc[@desctype="constraint"]')
        self.assertEqual(len(constr), 1)
        constr = constr[0]
        param, = constr.xpath('//field')

        self.assertEqual(constr.attrs['summary'], 'blah')

        self.assertEqual(param.attrs, {
            'eql-name': 'parameter',
            'eql-paramname': '$0',
            'eql-paramtype': 'any'
        })

        self.assertEqual(
            param.xpath('''
                //reference[@eql-type="type" and @refid="type::std::any"] /
                    literal_emphasis/text()
            '''), ['any'])

        self.assertEqual(
            x.xpath('''
                //paragraph /
                reference[@eql-type="constraint" and
                    @refid="constraint::std::maxlength"] /
                literal / text()
            '''), ['XXX', 'maxlength'])
    def test_sphinx_eql_stmt_10(self):
        src = '''
        =========
        Functions
        =========

        :edb-alt-title: Functions and Operators

        This section describes the DDL commands ...


        CREATE FUNCTION
        ===============

        :eql-statement:

        Define a new function.


        DROP FUNCTION
        =============

        :eql-statement:
        :eql-haswith:

        Remove a function.
        '''

        out = self.build(src, format='xml')
        x = requests_xml.XML(xml=out)

        self.assertEqual(
            x.xpath('''
                //section/title[text()="Functions"]/@edb-alt-title
            '''),
            ['Functions and Operators'])

        self.assertEqual(
            x.xpath('''
                //section[@eql-statement="true"]/title/text()
            '''),
            ['CREATE FUNCTION', 'DROP FUNCTION'])

        self.assertEqual(
            x.xpath('''
                //section[@eql-statement="true" and @eql-haswith="true"]
                    /title/text()
            '''),
            ['DROP FUNCTION'])
示例#11
0
    def test_sphinx_eql_func_08(self):
        src = '''
        .. eql:function:: std::test(NAMED ONLY v: in64=42) -> OPTIONAL int64

            blah
        '''

        out = self.build(src, format='xml')
        x = requests_xml.XML(xml=out)

        self.assertEqual(x.xpath('//desc_returns / text()'),
                         ['OPTIONAL int64'])

        self.assertEqual(
            x.xpath('//desc_signature/@eql-signature'),
            ['std::test(NAMED ONLY v: in64 = 42) -> OPTIONAL int64'])
示例#12
0
    def test_sphinx_eql_type_01(self):
        src = '''
        .. eql:type:: int64

            descr
        '''

        out = self.build(src, format='xml')
        x = requests_xml.XML(xml=out)

        self.assertEqual(
            x.xpath('''
                //desc_signature
                    [@eql-fullname="std::int64"] /
                    desc_name / text()
            '''), ['int64'])
示例#13
0
    def test_sphinx_eql_func_07(self):
        src = '''
        .. eql:function:: std::test(a: OPTIONAL str, b: SET OF str, \\
                            c: str) -> SET OF str

            blah

        '''

        out = self.build(src, format='xml')
        x = requests_xml.XML(xml=out)

        self.assertEqual(x.xpath('//desc_returns / text()'), ['SET OF str'])

        self.assertEqual(x.xpath('//desc_signature/@eql-signature'), [
            'std::test(a: OPTIONAL str, b: SET OF str, c: str) -> SET OF str'
        ])
示例#14
0
    def test_sphinx_eql_constr_02(self):
        src = '''
        .. eql:constraint:: std::len_value on (len(<std::str>__subject__))

            blah
        '''

        out = self.build(src, format='xml')
        x = requests_xml.XML(xml=out)

        sig = x.xpath('//desc[@desctype="constraint"]/desc_signature')[0]

        self.assertEqual(sig.attrs['eql-signature'],
                         'std::len_value on (len(<std::str>__subject__))')

        self.assertEqual(sig.attrs['eql-subjexpr'],
                         'len(<std::str>__subject__)')
    def test_sphinx_eql_func_09(self):
        src = '''
        .. eql:function:: sys::sleep(duration: duration) -> bool
                          sys::sleep(duration: float64) -> bool

            :index: sleep delay

            blah
        '''

        out = self.build(src, format='xml')
        x = requests_xml.XML(xml=out)

        self.assertEqual(
            x.xpath('//desc_signature/@eql-signature'),
            ['sys::sleep(duration: duration) ->  bool',
             'sys::sleep(duration: float64) ->  bool'])
示例#16
0
    def test_eql_migration_1(self):
        src = '''
        .. eql:migration:: foobar

            type User:
                property name -> str
        '''

        out = self.build(src, format='xml')
        x = requests_xml.XML(xml=out)

        self.assertEqual(
            x.xpath('''
                //container[@eql-migration="true"] / literal_block / text()
            '''), [
                'CREATE MIGRATION foobar TO eschema $$\n\n',
                'type User:\n    property name -> str',
                '\n$$;\nCOMMIT MIGRATION foobar;'
            ])
示例#17
0
    def test_sphinx_eql_type_08(self):
        src = '''
        .. eql:type:: SET OF

            An integer.

        Testing :eql:type:`SET OF`.
        Testing :eql:type:`XXX <SET OF>`.
        '''

        out = self.build(src, format='xml')
        x = requests_xml.XML(xml=out)

        self.assertEqual(
            x.xpath('''
                //paragraph /
                reference[@eql-type="type"] /
                literal / text()
            '''), ['SET OF', 'XXX'])
示例#18
0
    def test_sphinx_eql_struct_01(self):
        src = '''
        .. eql:struct:: edb.testbase.protocol.AuthenticationSASLFinal

        .. eql:struct:: edb.testbase.protocol.Cardinality
        '''

        out = self.build(src, format='xml')
        x = requests_xml.XML(xml=out)

        self.assertEqual(
            x.xpath('''
                literal_block/@language
            '''), ['c', 'c'])

        val = x.xpath('''
            literal_block/text()
        ''')
        self.assertIn('struct AuthenticationSASLFinal {', val[0])
        self.assertIn('enum Cardinality {', val[1])
示例#19
0
    def test_sphinx_eql_constr_02(self):
        src = '''
        .. eql:constraint:: std::len_value on (len(<std::str>__subject__))

            blah
        '''

        out = self.build(src, format='xml')
        x = requests_xml.XML(xml=out)

        constr = x.xpath('//desc[@desctype="constraint"]')
        self.assertEqual(len(constr), 1)
        constr = constr[0]
        sig = constr.xpath('//desc_signature')[0]

        self.assertEqual(sig.xpath('@eql-signature'),
                         ['std::len_value ON (len(<std::str>__subject__))'])

        self.assertEqual(sig.xpath('@eql-subjexpr'),
                         ['len(<std::str>__subject__)'])
示例#20
0
    def test_eql_func_7(self):
        src = '''
        .. eql:function:: std::test(OPTIONAL str, SET OF str, str) \\
                            -> SET OF str

            blah

        '''

        out = self.build(src, format='xml')
        x = requests_xml.XML(xml=out)

        self.assertEqual(x.xpath('//desc_parameter / text()'),
                         ['OPTIONAL str', 'SET OF str', 'str'])

        self.assertEqual(x.xpath('//desc_returns / text()'), ['SET OF str'])

        self.assertEqual(
            x.xpath('//desc_signature/@eql-signature'),
            ['std::test(OPTIONAL str, SET OF str, str) -> SET OF str'])
示例#21
0
    def test_sphinx_eql_blockquote_02(self):
        # Test that although regular block-qoutes are blocked
        # (as their syntax is very confusing and fragile), we can
        # still use explicit block-quotes via the `.. pull-quote::`
        # directive.

        src = '''
        blah

        .. pull-quote::

            spam

        blah2
        '''

        out = self.build(src, format='xml')
        x = requests_xml.XML(xml=out)

        self.assertEqual(
            x.xpath('''
                block_quote/*/text()
            '''), ['spam'])
    def test_sphinx_eql_type_07(self):
        src = '''
        .. eql:type:: int64

            An integer.

        Testing :eql:type:`OPTIONAL  int64` ref.
        Testing :eql:type:`OPTIONAL int64` ref.
        Testing :eql:type:`SET  OF  int64` ref.
        Testing :eql:type:`SET OF int64` ref.
        '''

        out = self.build(src, format='xml')
        x = requests_xml.XML(xml=out)

        self.assertEqual(
            x.xpath('''
                //paragraph /
                reference[@eql-type="type"] /
                literal / text()
            '''),
            ['OPTIONAL  int64', 'OPTIONAL int64',
             'SET  OF  int64', 'SET OF int64'])
示例#23
0
 def parse(self):
     if self.output:
         self.output = ''
     mod_time = os.stat(self.xmlfile)[stat.ST_MTIME]
     if time.time() - mod_time > self.stale_time:
         return self.output
     with open(self.xmlfile) as f:
         doc = re.sub(r'<?.*(encoding=\"UTF-8\"|encoding=\'UTF-8\').*?>',
                      '',
                      f.read(),
                      flags=re.I)
         j = json.loads(requests_xml.XML(xml=doc).json())
         if time.time() - j['HOST']['@REPORTED'] > self.stale_time:
             return self.output
         else:
             for metric in j['HOST']['METRIC']:
                 if metric['@TYPE'] == 'string':
                     continue
                 if isinstance(metric['EXTRA_DATA']['EXTRA_ELEMENT'], list):
                     for e in metric['EXTRA_DATA']['EXTRA_ELEMENT']:
                         if e['@NAME'] == 'GROUP':
                             group = e['@VAL']
                 else:
                     group = metric['EXTRA_DATA']['EXTRA_ELEMENT']['@VAL']
                 try:
                     self.output += '%s{host="%s",group="%s"} %d\n' % (
                         metric['@NAME'].replace('.', '_').replace(
                             ' ', '').replace('-', '_'), self.host,
                         group.replace('.', '_').replace(' ', '').replace(
                             '-', '_'), metric['@VAL'])
                 except TypeError:
                     self.output += '%s{host="%s",group="%s"} %s\n' % (
                         metric['@NAME'].replace('.', '_').replace(
                             ' ', '').replace('-', '_'), self.host,
                         group.replace('.', '_').replace(' ', '').replace(
                             '-', '_'), metric['@VAL'])
             return self.output
    def test_sphinx_eql_stmt_05(self):
        src = '''

        CREATE FUNCTION
        ===============

        :eql-statement:

        ``CREATE FUNCTION``--creates a function.

        fooing and baring.

        Subhead
        -------

        asdasdas


        CREATE TYPE
        ===========

        :eql-statement:

        blah.


        Test
        ====

        A ref to :eql:stmt:`CREATE FUNCTION`

        A ref to :eql:stmt:`ttt <CREATE TYPE>`
        '''

        out = self.build(src, format='xml')
        x = requests_xml.XML(xml=out)

        self.assertEqual(
            x.xpath('''
                //paragraph /
                reference[@eql-type="statement" and
                          @refid="statement::CREATE-FUNCTION"] /
                literal / text()
            '''),
            ['CREATE FUNCTION'])

        self.assertEqual(
            x.xpath('''
                //paragraph /
                reference[@eql-type="statement" and
                          @refid="statement::CREATE-TYPE"] /
                literal / text()
            '''),
            ['ttt'])

        self.assertEqual(
            x.xpath('''
                //section[@eql-statement="true"]/@ids
            '''),
            ['create-function statement::CREATE-FUNCTION',
             'create-type statement::CREATE-TYPE'])

        self.assertEqual(
            x.xpath('''
                //section[@eql-statement="true"]/@summary
            '''),
            ['CREATE FUNCTION--creates a function.', 'blah.'])
    def test_sphinx_eql_inline_role_02(self):
        cases = [
            (
                '#123',
                'edgedb/edgedb/issues/123',
                None,
                '#123',
            ),
            (
                'magicstack/asyncpg/#227',
                'magicstack/asyncpg/issues/227',
                None,
                'magicstack/asyncpg/#227',
            ),
            (
                'ff123aaaaeeeee',
                'edgedb/edgedb/commit/ff123aaaaeeeee',
                None,
                'ff123aaa'
            ),
            (
                'magicstack/asyncpg/ff123aaaaeeeee',
                'magicstack/asyncpg/commit/ff123aaaaeeeee',
                None,
                'magicstack/asyncpg/ff123aaa'
            ),

            (
                '#123',
                'edgedb/edgedb/issues/123',
                'blah1',
                'blah1',
            ),
            (
                'magicstack/asyncpg/#227',
                'magicstack/asyncpg/issues/227',
                'blah2',
                'blah2',
            ),
            (
                'ff123aaaaeeeee',
                'edgedb/edgedb/commit/ff123aaaaeeeee',
                'blah3',
                'blah3',
            ),
            (
                'magicstack/asyncpg/ff123aaaaeeeee',
                'magicstack/asyncpg/commit/ff123aaaaeeeee',
                'blah4',
                'blah4',
            ),
        ]

        src = ''
        for (body, _, title, _) in cases:
            if title:
                src += f':eql:gh:`{title} <{body}>`\n'
            else:
                src += f':eql:gh:`{body}`\n'

        out = self.build(src, format='xml')
        x = requests_xml.XML(xml=out)

        for (_, expected_link, _, expected_title) in cases:
            self.assertEqual(
                x.xpath(f'''
                    //reference[
                        @eql-github="True" and
                        @name="{expected_title}" and
                        @refuri="https://github.com/{expected_link}"
                    ]/text()
                '''),
                [expected_title]
            )
示例#26
0
import json

import pandas as pd
import collections

import sqlite3

import pickle


conn = sqlite3.connect('test__9900.db')

session = requests_xml.XMLSession()

r = session.get('http://xml.cdn.betclic.com/odds_en.xml')
xml = requests_xml.XML(xml=r.text)
res = json.loads(xml.json())

def parseSport(sport, mapping):
    nameOfSport = sport['@name']
    idOfSport = sport['@id']
    sportMapping = {'nameOfSport': nameOfSport, 'idOfSport': idOfSport}
    mapping['sport'].append(sportMapping)
    
    return (idOfSport, mapping)
    

def parseLeague(league, mapping):
    
    nameOfLeague = league['@name']
    idOfLeague = league['@id']
示例#27
0
    def test_eql_func_1(self):
        src = '''
        .. eql:type:: std::int64

            An integer.

        .. eql:type:: any

            any.

        .. eql:function:: std::test(any) -> any

            :param $0: param
            :paramtype $0: int64

            :return: something
            :returntype: any

            :index: xxx YyY

            blah

        Testing :eql:func:`XXX <test>` ref.
        Testing :eql:func:`test` ref.
        '''

        out = self.build(src, format='xml')
        x = requests_xml.XML(xml=out)

        func = x.xpath('//desc[@desctype="function"]')
        self.assertEqual(len(func), 1)
        func = func[0]
        param, ret, _ = func.xpath('//field')

        self.assertEqual(func.attrs['summary'], 'blah')

        self.assertEqual(
            param.attrs, {
                'eql-name': 'parameter',
                'eql-paramname': '$0',
                'eql-paramtype': 'int64'
            })

        self.assertEqual(ret.attrs, {
            'eql-name': 'return',
            'eql-paramname': '',
            'eql-paramtype': 'any'
        })

        self.assertEqual(
            param.xpath('''
                //reference[@eql-type="type" and @refid="type::std::int64"] /
                    literal_emphasis/text()
            '''), ['int64'])

        self.assertEqual(
            x.xpath('''
                //paragraph /
                reference[@eql-type="function" and
                    @refid="function::std::test"] /
                literal / text()
            '''), ['XXX', 'test()'])

        self.assertEqual(
            x.xpath('''
                //field[@eql-name="index"] / field_body / paragraph / text()
            '''), ['xxx YyY'])