def test_files(self):
        for fullpath in self._rbrs():
            with open(fullpath) as f:
                ast = build_ast(f.read())

            if ast is None:
                raise AssertionError(fullpath)
Esempio n. 2
0
    def test_files(self):
        for fullpath in self._rbrs():
            with open(fullpath) as f:
                ast = build_ast(f.read())

            if ast is None:
                raise AssertionError(fullpath)
Esempio n. 3
0
    def test_describe(self):
        ast = build_ast(_RBR)
        resp_headers = ast[0].right[2].right
        params = {'url': '/',
                  'use': 'do.something',
                  'response-headers': resp_headers}

        hook = WebHook(params)
        self.assertEqual(hook.describe('response-headers'), '<p>here</p>')
Esempio n. 4
0
    def test_describe(self):
        ast = build_ast(_RBR)
        resp_headers = ast[0].right[2].right
        params = {
            'url': '/',
            'use': 'do.something',
            'response-headers': resp_headers
        }

        hook = WebHook(params)
        self.assertEqual(hook.describe('response-headers'), '<p>here</p>')
    def _load_rbr(self, load_ast=True):
        if load_ast:
            self.ast = build_ast(self.rbr_content)
            # looking for the root path
            for definition in self.ast:
                if definition.type != 'root':
                    continue
                self.root_path = definition.value
                break

        self.globs = self._create_globs()
        self.types = self._create_types()
        self.mapper = WebMapper(self)
    def test_one_val_paren(self):
        path = os.path.join(_SAMPLES, 'html.rbr')
        with open(path) as f:
            ast = build_ast(f.read())

        response_headers = ast[0].right[4].right

        # we want a list of assignements
        self.assertTrue(isinstance(response_headers, list))

        # we have a single assignement
        content_type = response_headers[0]
        self.assertEqual(content_type.collapse(level=-1),
                         'set content-type "text/html"')
Esempio n. 7
0
    def test_one_val_paren(self):
        path = os.path.join(_SAMPLES, 'html.rbr')
        with open(path) as f:
            ast = build_ast(f.read())

        response_headers = ast[0].right[4].right

        # we want a list of assignements
        self.assertTrue(isinstance(response_headers, list))

        # we have a single assignement
        content_type = response_headers[0]
        self.assertEqual(content_type.collapse(level=-1),
                         'set content-type "text/html"')
Esempio n. 8
0
def check_syntax(args=None):
    parser = argparse.ArgumentParser(
        description='Checks the syntax of a RBR file.')
    parser.add_argument('path', type=str, help='Path of the RBR file')
    parser.add_argument('--verbose', action='store_true')
    args = parser.parse_args(args=args)
    from redbarrel.dsl import build_ast
    with open(args.path) as f:
        res = build_ast(f.read(), args.verbose)

    if res is None:
        print("Syntax Error.")
        sys.exit(1)
    else:
        print("Syntax OK.")
        sys.exit(0)
def check_syntax(args=None):
    parser = argparse.ArgumentParser(
        description='Checks the syntax of a RBR file.')
    parser.add_argument('path', type=str, help='Path of the RBR file')
    parser.add_argument('--verbose', action='store_true')
    args = parser.parse_args(args=args)
    from redbarrel.dsl import build_ast
    with open(args.path) as f:
        res = build_ast(f.read(), args.verbose)

    if res is None:
        print("Syntax Error.")
        sys.exit(1)
    else:
        print("Syntax OK.")
        sys.exit(0)
Esempio n. 10
0
    def test_several(self):
        path = os.path.join(_SAMPLES, 'service.rbr')
        with open(path) as f:
            ast = build_ast(f.read())

        wanted = {200: 'Success',
                503: 'Problems with looking up the user or sending the email',
                400: 'No email address on file for user',
                404: 'User not found'}

        response_status =  ast[0].right[4].right

        for status in response_status:
            code = status.value.left
            desc = status.value.right
            self.assertEquals(wanted[code], desc)
    def test_several(self):
        path = os.path.join(_SAMPLES, 'service.rbr')
        with open(path) as f:
            ast = build_ast(f.read())

        wanted = {
            200: 'Success',
            503: 'Problems with looking up the user or sending the email',
            400: 'No email address on file for user',
            404: 'User not found'
        }

        response_status = ast[0].right[4].right

        for status in response_status:
            code = status.value.left
            desc = status.value.right
            self.assertEquals(wanted[code], desc)
Esempio n. 12
0
def _run_server(args):
    logger.info("Serving on port %d..." % args.port)

    # loading the rbr to get the workers/arbiters
    from redbarrel.dsl import build_ast
    from redbarrel.dsl.runners import resolve_runner

    workers = {}
    arbiters = {}

    for path in args.path:
        with open(path) as f:
            ast = build_ast(f.read())

        for definition in ast:
            type_ = definition.type
            if type_ not in ('worker', 'arbiter'):
                continue

            name = definition[1]
            logger.info('Loading %s %r' % (type_, name))
            runner = resolve_runner(definition[2])
            if type_ == 'worker':
                workers[name] = runner
            else:
                arbiters[name] = runner

    # default arbiters and workers
    from redbarrel.server.arbiters import ARBITERS
    arbiters.update(ARBITERS)

    from redbarrel.server.workers import WORKERS
    workers.update(WORKERS)

    # now loading the workers and arbiters, given a config
    specs = []
    from pistil.arbiter import Arbiter

    conf = {"address": ("127.0.0.1", args.port),
            "debug": True,
            "memory": True,
            "num_workers": 1,  #args.workers,
            "path": args.path,
            "timeout": 9000  # XXXX
            }

    for name, num in args.workers:
        # is it an arbiter or a worker ?
        if name in arbiters:
            klass = arbiters[name]
            type_ = 'supervisor'
        elif name in workers:
            klass = workers[name]
            type_ = 'worker'
        else:
            raise ValueError(name)

        timeout = 90000  # XXX to be defined
        specs.append((klass, timeout, type_, {}, name))
        # XXX conf ?
        #

    arbiter = Arbiter(conf, specs)
    arbiter.run()
 def test_collapse(self):
     for fullpath in self._rbrs():
         with open(fullpath) as f:
             dsl = f.read()
             ast = build_ast(dsl)
         self.assertEquals(ast.collapse(), dsl)
def _run_server(args):
    logger.info("Serving on port %d..." % args.port)

    # loading the rbr to get the workers/arbiters
    from redbarrel.dsl import build_ast
    from redbarrel.dsl.runners import resolve_runner

    workers = {}
    arbiters = {}

    for path in args.path:
        with open(path) as f:
            ast = build_ast(f.read())

        for definition in ast:
            type_ = definition.type
            if type_ not in ('worker', 'arbiter'):
                continue

            name = definition[1]
            logger.info('Loading %s %r' % (type_, name))
            runner = resolve_runner(definition[2])
            if type_ == 'worker':
                workers[name] = runner
            else:
                arbiters[name] = runner

    # default arbiters and workers
    from redbarrel.server.arbiters import ARBITERS
    arbiters.update(ARBITERS)

    from redbarrel.server.workers import WORKERS
    workers.update(WORKERS)

    # now loading the workers and arbiters, given a config
    specs = []
    from pistil.arbiter import Arbiter

    conf = {
        "address": ("127.0.0.1", args.port),
        "debug": True,
        "memory": True,
        "num_workers": 1,  #args.workers,
        "path": args.path,
        "timeout": 9000  # XXXX
    }

    for name, num in args.workers:
        # is it an arbiter or a worker ?
        if name in arbiters:
            klass = arbiters[name]
            type_ = 'supervisor'
        elif name in workers:
            klass = workers[name]
            type_ = 'worker'
        else:
            raise ValueError(name)

        timeout = 90000  # XXX to be defined
        specs.append((klass, timeout, type_, {}, name))
        # XXX conf ?
        #

    arbiter = Arbiter(conf, specs)
    arbiter.run()
Esempio n. 15
0
 def test_collapse(self):
     for fullpath in self._rbrs():
         with open(fullpath) as f:
             dsl = f.read()
             ast = build_ast(dsl)
         self.assertEquals(ast.collapse(), dsl)
 def add_content(self, content):
     # syntax check
     try:
         ast = build_ast(content)
     except Exception, e:
         raise SyntaxError(e)