Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_parse_inline_text():
page = Page()
result = page.new('span: Hello There')
assert isinstance(result, view.Raw)
assert len(result.children) == 1
child = result.children[0]
assert isinstance(child, view.Inline)
assert child.text == 'Hello There'
assert len(obj) == 1
element_configuration = {
'kwargs': {
'props': {}
},
'kwargs_children': set(),
'prop_children': {},
'children': [],
'field': None
}
key, value = list(obj.items())[0]
element_type, additional_kwargs = self._parse_str(key)
element_configuration['element_type'] = element_type
element_configuration['kwargs'].update(additional_kwargs)
if isinstance(value, six.string_types):
if issubclass(element_type, view.Raw):
value = [{'Inline': value}]
else:
element_configuration['kwargs']['_awe_arg'] = value
value = []
value = value or []
if not isinstance(value, list):
raise ValueError('Value should be a string or a list, got: {}'.format(value))
if value and isinstance(value[0], list):
self._parse_element_configuration(element_configuration, element_type, value[0])
value = value[1:]
for item in value:
if isinstance(item, six.string_types) and not self._is_element_type(item):
item = {'Inline': item}
else:
item = self._normalize_element(item)
child_element_configuration = self._parse_dict(item)
def _parse_str(self, obj_str):
assert obj_str
if obj_str[0].islower():
return view.Raw, {'tag': obj_str}
elif obj_str in view.builtin_element_types:
return view.builtin_element_types[obj_str], {}
elif obj_str in self.registry.element_types:
return self.registry.element_types[obj_str], {}
raise ValueError('No such element: {}'.format(obj_str))
def new_link(self, link, **kwargs):
"""
Add a new link element.
:param link: The link (URL)
:return: The created link element.
"""
props = kwargs.setdefault('props', {})
props.setdefault('href', link)
return self._new_child(Raw, tag='a', **kwargs)