Skip to content

Commit

Permalink
pe-scopedata: attach arbitrary data to scope
Browse files Browse the repository at this point in the history
Like the `pe-data` tag attaches to component, this /attempts/ to
attach to scope.
  • Loading branch information
xrg committed May 19, 2019
1 parent 46f052e commit 0cc7a25
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion behave_manners/pagelems/page_elements.py
Expand Up @@ -1099,6 +1099,23 @@ def _locate_attrs(self, webelem=None, scope=None, xpath_prefix=''):
yield self._attr_name, property(lambda *c: data) # deep copy?


class PEScopeDataElement(DPageElement):
"""Attach arbitrary data as a scope attribute
WARNING: this data will only work if the component containing this tag
is 'discovered', ie. attached to that scope.
"""
_name = 'tag.pe-scopedata'
_inherit = 'tag.pe-data'

def _locate_attrs(self, webelem=None, scope=None, xpath_prefix=''):
if scope is None:
return ()
data = deepcopy(self._attr_value)
setattr(scope, self._attr_name, data)
return ()


class ConsumeTmplMixin(object):
"""Common between Head and Body elements, temporarily hold templates
"""
Expand Down Expand Up @@ -1443,7 +1460,8 @@ class GBodyElement(ConsumeTmplMixin, DPageElement):


class PageParser(BaseDPOParser):
CDATA_CONTENT_ELEMENTS = BaseDPOParser.CDATA_CONTENT_ELEMENTS + ('pe-regex', 'pe-data')
CDATA_CONTENT_ELEMENTS = BaseDPOParser.CDATA_CONTENT_ELEMENTS + \
('pe-regex', 'pe-data', 'pe-scopedata')
logger = logging.getLogger(__name__ + '.PageParser')

def __init__(self, root_element):
Expand Down

0 comments on commit 0cc7a25

Please sign in to comment.