コード例 #1
0
    def test_basic_conf(self):

        settings.WIRECLOUD_PLUGINS = ()

        core_plugins = len(get_plugins())
        core_features = len(get_active_features())
        core_classic_javascripts = len(get_extra_javascripts('classic'))
        core_smartphone_javascripts = len(get_extra_javascripts('smartphone'))
        core_classic_extensions = len(get_widget_api_extensions('classic', {}))
        core_smartphone_extensions = len(
            get_widget_api_extensions('smartphone', {}))

        settings.WIRECLOUD_PLUGINS = (
            'wirecloud.platform.tests.plugins.WirecloudTestPlugin1',
            'wirecloud.platform.tests.plugins.WirecloudTestPlugin2',
        )
        clear_cache()

        self.assertEqual(len(get_plugins()), core_plugins + 2)
        self.assertEqual(len(get_active_features()), core_features + 2)
        self.assertEqual(len(get_extra_javascripts('classic')),
                         core_classic_javascripts + 2)
        self.assertEqual(len(get_extra_javascripts('smartphone')),
                         core_smartphone_javascripts + 1)
        self.assertEqual(len(get_widget_api_extensions('classic', {})),
                         core_classic_extensions + 1)
        self.assertEqual(len(get_widget_api_extensions('smartphone', {})),
                         core_smartphone_extensions + 0)
コード例 #2
0
ファイル: utils.py プロジェクト: netzahdzc/wirecloud
def fix_widget_code(widget_code, content_type, request, encoding, use_platform_style, requirements, mode, theme):

    # This line is here for raising UnicodeDecodeError in case the widget_code is not encoded using the expecified encoding
    widget_code.decode(encoding)

    if content_type in ('text/html', 'application/xhtml+xml') and widget_code.strip() == b'':
        widget_code = b'<html></html>'

    if content_type == 'text/html':
        parser = etree.HTMLParser(encoding=encoding)
        serialization_options = {'method': 'html'}

    elif content_type == 'application/xhtml+xml':
        parser = etree.XMLParser(encoding=encoding)
        serialization_options = {'method': 'xml', 'xml_declaration': False}

    else:
        return widget_code

    xmltree = etree.parse(BytesIO(widget_code), parser)

    prefix = xmltree.getroot().prefix
    xmlns = None
    if prefix in xmltree.getroot().nsmap:
        xmlns = xmltree.getroot().nsmap[prefix]

    # Fix head element
    head_elements = xpath(xmltree, '/xhtml:html/xhtml:head', xmlns)
    if len(head_elements) == 0:
        head_element = etree.Element("head")
        xmltree.getroot().insert(0, head_element)
    else:
        head_element = head_elements[0]

    # Fix base element
    base_elements = xpath(xmltree, '/xhtml:html/xhtml:head/xhtml:base', xmlns)
    for base_element in base_elements[1:]:
        base_element.getparent().remove(base_element)

    # Fix scripts
    scripts = xpath(xmltree, '/xhtml:html//xhtml:script', xmlns)
    for script in scripts:

        if 'src' in script.attrib:
            script.text = ''

    head_element.insert(0, etree.Element('script', type="text/javascript", src=get_absolute_static_url('js/WirecloudAPI/WirecloudAPIClosure.js', request=request, versioned=True)))
    files = get_widget_api_extensions(mode, requirements)
    files.reverse()
    for file in files:
        head_element.insert(0, etree.Element('script', type="text/javascript", src=get_absolute_static_url(file, request=request, versioned=True)))
    for file in get_widget_api_files(request):
        head_element.insert(0, etree.Element('script', type="text/javascript", src=file))

    if use_platform_style:
        for file in get_widget_platform_style(theme):
            head_element.insert(0, etree.Element('link', rel="stylesheet", type="text/css", href=file))

    # return modified code
    return etree.tostring(xmltree, pretty_print=False, encoding=encoding, **serialization_options)
コード例 #3
0
ファイル: plugins.py プロジェクト: Fiware/apps.Wirecloud
    def test_basic_conf(self):

        settings.WIRECLOUD_PLUGINS = ()

        core_plugins = len(get_plugins())
        core_features = len(get_active_features())
        core_classic_javascripts = len(get_extra_javascripts('classic'))
        core_smartphone_javascripts = len(get_extra_javascripts('smartphone'))
        core_classic_extensions = len(get_widget_api_extensions('classic', {}))
        core_smartphone_extensions = len(get_widget_api_extensions('smartphone', {}))

        settings.WIRECLOUD_PLUGINS = (
            'wirecloud.platform.tests.plugins.WirecloudTestPlugin1',
            'wirecloud.platform.tests.plugins.WirecloudTestPlugin2',
        )
        clear_cache()

        self.assertEqual(len(get_plugins()), core_plugins + 2)
        self.assertEqual(len(get_active_features()), core_features + 2)
        self.assertEqual(len(get_extra_javascripts('classic')), core_classic_javascripts + 2)
        self.assertEqual(len(get_extra_javascripts('smartphone')), core_smartphone_javascripts + 1)
        self.assertEqual(len(get_widget_api_extensions('classic', {})), core_classic_extensions + 1)
        self.assertEqual(len(get_widget_api_extensions('smartphone', {})), core_smartphone_extensions + 0)
コード例 #4
0
ファイル: utils.py プロジェクト: fispace/wirecloud
def fix_widget_code(widget_code, base_url, content_type, request, use_platform_style, force_base=False):

    if content_type == 'text/html':
        parser = etree.HTMLParser()
        xmltree = etree.parse(StringIO(str(widget_code)), parser)
        serialization_method = 'html'
    elif content_type == 'application/xhtml+xml':
        xmltree = etree.fromstring(widget_code).getroottree()
        serialization_method = 'xml'
    else:
        return widget_code

    prefix = xmltree.getroot().prefix
    xmlns = None
    if prefix in xmltree.getroot().nsmap:
        xmlns = xmltree.getroot().nsmap[prefix]

    # Fix head element
    head_elements = xpath(xmltree, '/xhtml:html/xhtml:head', xmlns)
    if len(head_elements) == 0:
        head_element = etree.Element("head")
        xmltree.getroot().insert(0, head_element)
    else:
        head_element = head_elements[0]

    # Fix base element
    base_elements = xpath(xmltree, '/xhtml:html/xhtml:head/xhtml:base', xmlns)
    for base_element in base_elements[1:]:
        base_element.parent.remove(base_element)

    if len(base_elements) >= 1 and force_base:
        base_elements[0].set('href', base_url)
    elif len(base_elements) == 0:
        head_element.insert(0, etree.Element('base', href=base_url))

    # Fix scripts
    uses_old_api = False
    scripts = xpath(xmltree, '/xhtml:html//xhtml:script', xmlns)
    for script in scripts:

        if 'src' in script.attrib:
            script.text = ''

        if script.get('src', '') == '/ezweb/js/WirecloudAPI/WirecloudAPI.js':

            script.getparent().remove(script)

        elif script.get('src', '') == '/ezweb/js/EzWebAPI/EzWebAPI.js':
            uses_old_api = True
            script.set('src', get_absolute_static_url('js/EzWebAPI/EzWebAPI.js', request=request))

            files = get_old_widget_api_extensions('index')
            files.reverse()
            for file in files:
                script.addnext(etree.Element('script', type="text/javascript", src=get_absolute_static_url(file, request=request)))

    if not uses_old_api:
        head_element.insert(0, etree.Element('script', type="text/javascript", src=get_absolute_static_url('js/WirecloudAPI/WirecloudAPIClosure.js', request=request)))
        files = get_widget_api_extensions('index')
        files.reverse()
        for file in files:
            head_element.insert(0, etree.Element('script', type="text/javascript", src=get_absolute_static_url(file, request=request)))
        head_element.insert(0, etree.Element('script', type="text/javascript", src=get_absolute_static_url('js/WirecloudAPI/WirecloudAPI.js', request=request)))

        if use_platform_style:
            head_element.insert(0, etree.Element('link', rel="stylesheet", type="text/css", href=get_absolute_static_url('js/EzWebAPI_ext/EzWebGadgets.css', request=request)))
            head_element.insert(0, etree.Element('link', rel="stylesheet", type="text/css", href=get_absolute_static_url('css/gadget.css', request=request)))
    else:
        # Redirect all script starting with /ezweb/ to the platform only when using the old api version
        for script in scripts:
            if script.get('src', '').startswith('/ezweb/'):
                script.set('src', get_absolute_static_url(script.get('src')[7:], request=request))


    # return modified code
    return etree.tostring(xmltree, pretty_print=False, method=serialization_method)
コード例 #5
0
ファイル: utils.py プロジェクト: perezdf/wirecloud
def fix_widget_code(
    widget_code, base_url, content_type, request, encoding, use_platform_style, requirements, force_base, mode
):

    # This line is here for raising UnicodeDecodeError in case the widget_code is not encoded using the expecified encoding
    widget_code.decode(encoding)

    if content_type in ("text/html", "application/xhtml+xml") and widget_code.strip() == b"":
        widget_code = b"<html></html>"

    if content_type == "text/html":
        parser = etree.HTMLParser(encoding=encoding)
        serialization_options = {"method": "html"}

    elif content_type == "application/xhtml+xml":
        parser = etree.XMLParser(encoding=encoding)
        serialization_options = {"method": "xml", "xml_declaration": False}

    else:
        return widget_code

    xmltree = etree.parse(BytesIO(widget_code), parser)

    prefix = xmltree.getroot().prefix
    xmlns = None
    if prefix in xmltree.getroot().nsmap:
        xmlns = xmltree.getroot().nsmap[prefix]

    # Fix head element
    head_elements = xpath(xmltree, "/xhtml:html/xhtml:head", xmlns)
    if len(head_elements) == 0:
        head_element = etree.Element("head")
        xmltree.getroot().insert(0, head_element)
    else:
        head_element = head_elements[0]

    # Fix base element
    base_elements = xpath(xmltree, "/xhtml:html/xhtml:head/xhtml:base", xmlns)
    for base_element in base_elements[1:]:
        base_element.getparent().remove(base_element)

    if len(base_elements) >= 1 and force_base:
        base_elements[0].set("href", base_url)
    elif len(base_elements) == 0:
        head_element.insert(0, etree.Element("base", href=base_url))

    # Fix scripts
    scripts = xpath(xmltree, "/xhtml:html//xhtml:script", xmlns)
    for script in scripts:

        if "src" in script.attrib:
            script.text = ""

    head_element.insert(
        0,
        etree.Element(
            "script",
            type="text/javascript",
            src=get_absolute_static_url("js/WirecloudAPI/WirecloudAPIClosure.js", request=request, versioned=True),
        ),
    )
    files = get_widget_api_extensions(mode, requirements)
    files.reverse()
    for file in files:
        head_element.insert(
            0,
            etree.Element(
                "script", type="text/javascript", src=get_absolute_static_url(file, request=request, versioned=True)
            ),
        )
    head_element.insert(
        0,
        etree.Element(
            "script",
            type="text/javascript",
            src=get_absolute_static_url("js/WirecloudAPI/WirecloudAPICommon.js", request=request, versioned=True),
        ),
    )
    head_element.insert(
        0,
        etree.Element(
            "script",
            type="text/javascript",
            src=get_absolute_static_url("js/WirecloudAPI/WirecloudWidgetAPI.js", request=request, versioned=True),
        ),
    )
    head_element.insert(
        0,
        etree.Element(
            "script",
            type="text/javascript",
            src=get_absolute_static_url("js/WirecloudAPI/WirecloudAPIBootstrap.js", request=request, versioned=True),
        ),
    )

    if use_platform_style:
        for file in get_widget_platform_style():
            head_element.insert(0, etree.Element("link", rel="stylesheet", type="text/css", href=file))

    # return modified code
    return etree.tostring(xmltree, pretty_print=False, encoding=encoding, **serialization_options)