How to use the pyquery.pyquery.FlexibleElement function in pyquery

To help you get started, we’ve selected a few pyquery 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 gawel / pyquery / pyquery / pyquery.py View on Github external
key = key.replace('_', '-')
                    current.append('%s: %s' % (key, value))
                tag.set('style', '; '.join(current))
        elif isinstance(value, basestring):
            attr = attr.replace('_', '-')
            for tag in self:
                current = [
                    el.strip()
                    for el in (tag.get('style') or '').split(';')
                    if (el.strip() and
                        not el.split(':')[0].strip() == attr.strip())]
                current.append('%s: %s' % (attr, value))
                tag.set('style', '; '.join(current))
        return self

    css = FlexibleElement(pget=css, pset=css)

    ###################
    # CORE UI EFFECTS #
    ###################
    def hide(self):
        """Remove display:none to elements style:

            &gt;&gt;&gt; print(PyQuery('<div style="display:none;">').hide())
            <div style="display: none">

        """
        return self.css('display', 'none')

    def show(self):
        """Add display:block to elements style:
</div></div>
github dsc / pyquery / pyquery / pyquery.py View on Github external
for key, value in attr.items():
                    key = key.replace('_', '-')
                    current.append('%s: %s' % (key, value))
                tag.set('style', '; '.join(current))
        elif isinstance(value, basestring):
            attr = attr.replace('_', '-')
            for tag in self:
                current = [el.strip()
                           for el in (tag.get('style') or '').split(';')
                           if el.strip()
                              and not el.split(':')[0].strip() == attr.strip()]
                current.append('%s: %s' % (attr, value))
                tag.set('style', '; '.join(current))
        return self

    css = FlexibleElement(pget=css, pset=css)

    ###################
    # CORE UI EFFECTS #
    ###################
    def hide(self):
        """remove display:none to elements style

            &gt;&gt;&gt; print(PyQuery('<div style="display:none;">').hide())
            <div style="display: none">

        """
        return self.css('display', 'none')

    def show(self):
        """add display:block to elements style
</div></div>
github dsc / pyquery / pyquery / pyquery.py View on Github external
return self

    def removeAttr(self, name):
        """Remove an attribute::

            &gt;&gt;&gt; d = PyQuery('<div id="myid"></div>')
            &gt;&gt;&gt; d.removeAttr('id')
            [<div>]

        ..
        """
        for tag in self:
            del tag.attrib[name]
        return self

    attr = FlexibleElement(pget=attr, pdel=removeAttr)

    #######
    # CSS #
    #######
    def height(self, value=no_default):
        """set/get height of element
        """
        return self.attr('height', value)

    def width(self, value=no_default):
        """set/get width of element
        """
        return self.attr('width', value)

    def hasClass(self, name):
        """Return True if element has class::</div>
github gawel / pyquery / pyquery / pyquery.py View on Github external
&gt;&gt;&gt; d = PyQuery('<div id="myid"></div>')
            &gt;&gt;&gt; d.remove_attr('id')
            [<div>]
            &gt;&gt;&gt; d.removeAttr('id')
            [<div>]

        ..
        """
        for tag in self:
            try:
                del tag.attrib[name]
            except KeyError:
                pass
        return self

    attr = FlexibleElement(pget=attr, pdel=remove_attr)

    #######
    # CSS #
    #######
    def height(self, value=no_default):
        """set/get height of element
        """
        return self.attr('height', value)

    def width(self, value=no_default):
        """set/get width of element
        """
        return self.attr('width', value)

    @with_camel_case_alias
    def has_class(self, name):</div></div>