How to use the awe.parser function in awe

To help you get started, we’ve selected a few awe examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github dankilman / awe / tests / test_parser.py View on Github external
def test_is_parsable():
    assert parser.is_parsable('')
    assert parser.is_parsable({})
    assert parser.is_parsable([])

    assert not parser.is_parsable(None)
    assert not parser.is_parsable(view.Element)
    assert not parser.is_parsable(view.CustomElement)
github dankilman / awe / tests / test_parser.py View on Github external
def test_prepare():
    obj1 = object()
    assert parser._prepare(obj1) is obj1
    assert parser._prepare('one') == 'one'
    assert parser._prepare('"one"') == 'one'
    assert parser._prepare('[]') == []
    assert parser._prepare('{}') == {}
github dankilman / awe / awe / view.py View on Github external
If ``obj`` is a class that inherits from Element, a new element of that type will be created.
        If ``obj`` is a dict or list, it will be parsed and the parser result will be created.
        If ``obj`` is a string, it will be yaml loaded and that result will be passed to the parser.

        When result is passed to the parser, an additional ``inputs`` argument can be supplied as a dict from keys
        to values that are referenced in the DSL using the ``$`` intrinsic function.

        :param obj: The ``Element`` subclass, a dict/list or a string to be passed to the parser.
        :param kwargs: Arguments that should be passed to the ``_init`` method of the created element or one of
                       ``props``, ``style``, ``id``, ``inputs`` if valid.
        :return: The created element.
        """
        from . import parser
        if CustomElement._is_custom(obj) and not obj._registered:
            self.register(obj)
        if parser.is_parsable(obj):
            context = parser.ParserContext(inputs=kwargs.pop('inputs', None))
            element_configuration = self._parse(obj, context)
            return self._new_children(element_configuration, **kwargs)
        else:
            return self._new_child(obj, **kwargs)
github dankilman / awe / awe / view.py View on Github external
If ``obj`` is a dict or list, it will be parsed and the parser result will be created.
        If ``obj`` is a string, it will be yaml loaded and that result will be passed to the parser.

        When result is passed to the parser, an additional ``inputs`` argument can be supplied as a dict from keys
        to values that are referenced in the DSL using the ``$`` intrinsic function.

        :param obj: The ``Element`` subclass, a dict/list or a string to be passed to the parser.
        :param kwargs: Arguments that should be passed to the ``_init`` method of the created element or one of
                       ``props``, ``style``, ``id``, ``inputs`` if valid.
        :return: The created element.
        """
        from . import parser
        if CustomElement._is_custom(obj) and not obj._registered:
            self.register(obj)
        if parser.is_parsable(obj):
            context = parser.ParserContext(inputs=kwargs.pop('inputs', None))
            element_configuration = self._parse(obj, context)
            return self._new_children(element_configuration, **kwargs)
        else:
            return self._new_child(obj, **kwargs)
github dankilman / awe / awe / page.py View on Github external
:param websocket_port: Websocket port.
        :param width: Set the page content width. (defaults to ``1200px``)
        :param style: Set custom javascript style object.
        :param export_fn: Override default export function.
        :param offline: Offline mode means start/block don't do anything. Useful when exporting directly from python.
        :param serializers: Custom serializers for custom element implementations.
        """
        super(Page, self).__init__(owner=self, element_id='root')
        self._registry = registry.Registry()
        self._register(self)
        self._offline = (offline or os.environ.get('AWE_OFFLINE'))
        self._port = port
        self._title = title
        self._style = self._set_default_style(style, width)
        self._element_updater = element_updater.ElementUpdater()
        self._parser = parser.Parser(
            registry=self._registry
        )
        self._encoder = encoding.Encoder(
            element_cls=view.Element,
            serializers=serializers
        )
        self._message_handler = messages.MessageHandler(
            registry=self._registry,
            dispatch=self._dispatch
        )
        self._custom_component = custom.CustomComponentHandler(
            registry=self._registry,
            encoder=self._encoder
        )
        self._exporter = export.Exporter(
            export_fn=export_fn,