Ejemplo n.º 1
0
    def convert_prefixed_properties(self, doc, filename):
        """ Searches a BeautifulSoup |doc| for any CSS properties requiring the -webkit- prefix and converts them.

        Returns the list of converted properties and the modified document as a string """

        converted_properties = []

        # Look for inline and document styles.
        inline_styles = doc.findAll(style=re.compile('.*'))
        style_tags = doc.findAll('style')
        all_styles = inline_styles + style_tags

        for tag in all_styles:

            # Get the text whether in a style tag or style attribute.
            style_text = ''
            if tag.name == 'style':
                if not tag.contents:
                    continue
                style_text = tag.contents[0]
            else:
                style_text = tag['style']

            updated_style_text = self.add_webkit_prefix_to_unprefixed_properties(style_text, filename)

            # Rewrite tag only if changes were made.
            if updated_style_text[0]:
                converted_properties.extend(updated_style_text[0])

                new_tag = Tag(doc, tag.name, tag.attrs)
                new_tag.insert(0, updated_style_text[1])

                self.replace_tag(tag, new_tag)

        return (converted_properties, doc.prettify())
Ejemplo n.º 2
0
    def convert_prefixed_properties(self, doc, filename):
        """ Searches a BeautifulSoup |doc| for any CSS properties requiring the -webkit- prefix and converts them.

        Returns the list of converted properties and the modified document as a string """

        converted_properties = []

        # Look for inline and document styles.
        inline_styles = doc.findAll(style=re.compile('.*'))
        style_tags = doc.findAll('style')
        all_styles = inline_styles + style_tags

        for tag in all_styles:

            # Get the text whether in a style tag or style attribute.
            style_text = ''
            if tag.name == 'style':
                if not tag.contents:
                    continue
                style_text = tag.contents[0]
            else:
                style_text = tag['style']

            updated_style_text = self.add_webkit_prefix_to_unprefixed_properties(style_text, filename)

            # Rewrite tag only if changes were made.
            if updated_style_text[0]:
                converted_properties.extend(updated_style_text[0])

                new_tag = Tag(doc, tag.name, tag.attrs)
                new_tag.insert(0, updated_style_text[1])

                self.replace_tag(tag, new_tag)

        return (converted_properties, doc.prettify())
Ejemplo n.º 3
0
    def convert_testharness_paths(self, doc, new_path):
        """ Update links to testharness.js in the BeautifulSoup |doc| to point to the copy in |new_path|.

        Returns whether the document was modified."""

        # Look for the W3C-style path to any testharness files - scripts (.js) or links (.css)
        pattern = re.compile('/resources/testharness')
        script_tags = doc.findAll(src=pattern)
        link_tags = doc.findAll(href=pattern)
        testharness_tags = script_tags + link_tags

        if not testharness_tags:
            return False

        resources_path = self.path_from_webkit_root('LayoutTests', 'resources')
        resources_relpath = self._filesystem.relpath(resources_path, new_path)

        for tag in testharness_tags:
            attr = 'src'
            if tag.name != 'script':
                attr = 'href'

            old_path = tag[attr]
            new_tag = Tag(doc, tag.name, tag.attrs)
            new_tag[attr] = re.sub(pattern, resources_relpath + '/testharness',
                                   old_path)

            self.replace_tag(tag, new_tag)

        return True
    def convert_prefixed_properties(self, doc, filename):
        """ Searches a BeautifulSoup |doc| for any CSS properties requiring the -webkit- prefix and converts them.

        Returns the list of converted properties and the modified document as a string """

        converted_properties = []

        # Look for inline and document styles.
        inline_styles = doc.findAll(style=re.compile('.*'))
        style_tags = doc.findAll('style')
        all_styles = inline_styles + style_tags

        for tag in all_styles:

            # Get the text whether in a style tag or style attribute.
            style_text = ''
            if tag.name == 'style':
                if not tag.contents:
                    continue
                style_text = tag.contents[0]
            else:
                style_text = tag['style']

            updated_style_text = self.add_webkit_prefix_to_unprefixed_properties(
                style_text, filename)

            # Rewrite tag only if changes were made.
            if updated_style_text[0]:
                converted_properties.extend(list(updated_style_text[0]))

                new_tag = Tag(doc, tag.name, tag.attrs)
                new_tag.insert(0, updated_style_text[1])

                self.replace_tag(tag, new_tag)

        # FIXME: Doing the replace in the parsed document and then writing it back out
        # is normalizing the HTML, which may in fact alter the intent of some tests.
        # We should probably either just do basic string-replaces, or have some other
        # way of flagging tests that are sensitive to being rewritten.
        # https://bugs.webkit.org/show_bug.cgi?id=119159

        return (converted_properties, doc.prettify())
Ejemplo n.º 5
0
    def convert_prefixed_properties(self, doc, filename):
        """ Searches a BeautifulSoup |doc| for any CSS properties requiring the -webkit- prefix and converts them.

        Returns the list of converted properties and the modified document as a string """

        converted_properties = []

        # Look for inline and document styles.
        inline_styles = doc.findAll(style=re.compile('.*'))
        style_tags = doc.findAll('style')
        all_styles = inline_styles + style_tags

        for tag in all_styles:

            # Get the text whether in a style tag or style attribute.
            style_text = ''
            if tag.name == 'style':
                if not tag.contents:
                    continue
                style_text = tag.contents[0]
            else:
                style_text = tag['style']

            updated_style_text = self.add_webkit_prefix_to_unprefixed_properties(style_text, filename)

            # Rewrite tag only if changes were made.
            if updated_style_text[0]:
                converted_properties.extend(list(updated_style_text[0]))

                new_tag = Tag(doc, tag.name, tag.attrs)
                new_tag.insert(0, updated_style_text[1])

                self.replace_tag(tag, new_tag)

        # FIXME: Doing the replace in the parsed document and then writing it back out
        # is normalizing the HTML, which may in fact alter the intent of some tests.
        # We should probably either just do basic string-replaces, or have some other
        # way of flagging tests that are sensitive to being rewritten.
        # https://bugs.webkit.org/show_bug.cgi?id=119159

        return (converted_properties, doc.prettify())
Ejemplo n.º 6
0
    def convert_testharness_paths(self, doc, new_path, filename):
        """ Update links to testharness.js in the BeautifulSoup |doc| to point to the copy in |new_path|.

        Returns whether the document was modified."""

        # Look for the W3C-style path to any testharness files - scripts (.js) or links (.css)
        pattern = re.compile('/resources/testharness')
        script_tags = doc.findAll(src=pattern)
        link_tags = doc.findAll(href=pattern)
        testharness_tags = script_tags + link_tags

        if not testharness_tags:
            return False

        resources_path = self.path_from_webkit_root('LayoutTests', 'resources')
        resources_relpath = self._filesystem.relpath(resources_path, new_path)

        for tag in testharness_tags:
            # FIXME: We need to handle img, audio, video tags also.
            attr = 'src'
            if tag.name != 'script':
                attr = 'href'

            if not attr in tag.attrMap:
                # FIXME: Figure out what to do w/ invalid tags. For now, we return False
                # and leave the document unmodified, which means that it'll probably fail to run.
                _log.error("Missing an attr in %s" % filename)
                return False

            old_path = tag[attr]
            new_tag = Tag(doc, tag.name, tag.attrs)
            new_tag[attr] = re.sub(pattern, resources_relpath + '/testharness',
                                   old_path)

            self.replace_tag(tag, new_tag)

        return True