Ejemplo n.º 1
0
    def inline_object_repl(self, stack, object, object_url=None, object_item=None,
                           object_text=None, object_args=None):
        """Handles objects included in the page."""
        if object_args:
            args = parse_arguments(object_args).keyword  # XXX needs different parsing
        else:
            args = {}

        query_keys = {}
        attrib = {}
        whitelist = ['width', 'height', 'class']
        for attr, value in args.iteritems():
            if attr.startswith('&'):
                query_keys[attr[1:]] = value
            elif attr in whitelist:
                attrib[html(attr)] = value
        if object_text:
            attrib[html.alt] = object_text
        if object_item is not None:
            # img tag
            query = url_encode(query_keys, charset=CHARSET, encode_keys=True)
            att = 'attachment:'  # moin 1.9 needed this for an attached file
            if object_item.startswith(att):
                object_item = '/' + object_item[len(att):]  # now we have a subitem
            target = Iri(scheme='wiki.local', path=object_item, query=query, fragment=None)
            attrib[xinclude.href] = target
            element = xinclude.include(attrib=attrib)
            stack.top_append(element)
        else:
            # object tag
            target = Iri(object_url)
            attrib[xlink.href] = target
            element = moin_page.object(attrib)
            stack.top_append(element)
Ejemplo n.º 2
0
    def inline_object_repl(self, stack, object, object_url=None, object_item=None,
                           object_text=None, object_args=None):
        """Handles objects included in the page."""
        if object_args:
            args = parse_arguments(object_args).keyword  # XXX needs different parsing
        else:
            args = {}
        if object_item is not None:
            query = url_encode(args, charset=CHARSET, encode_keys=True)
            att = 'attachment:'  # moin 1.9 needed this for an attached file
            if object_item.startswith(att):
                object_item = '/' + object_item[len(att):]  # now we have a subitem
            target = Iri(scheme='wiki.local', path=object_item, query=query, fragment=None)
            text = object_item

            attrib = {xinclude.href: target}
            element = xinclude.include(attrib=attrib)
            stack.top_append(element)
        else:
            target = Iri(object_url)
            text = object_url

            attrib = {xlink.href: target}
            if object_text is not None:
                attrib[moin_page.alt] = object_text

            element = moin_page.object(attrib)
            stack.push(element)
            if object_text:
                self.parse_inline(object_text, stack, self.inlinedesc_re)
            else:
                stack.top_append(text)
            stack.pop()
Ejemplo n.º 3
0
    def inline_object_repl(self, stack, object, object_url=None, object_item=None,
                           object_text=None, object_args=None):
        """Handles objects transcluded within the page."""
        if object_args:
            args = parse_arguments(object_args).keyword  # XXX needs different parsing
        else:
            args = {}

        query_keys = {}
        attrib = {}
        whitelist = ['width', 'height', 'class']
        for attr, value in args.iteritems():
            if attr.startswith('&'):
                query_keys[attr[1:]] = value
            elif attr in whitelist:
                attrib[html(attr)] = value
        if object_text:
            attrib[html.alt] = object_text
        if object_item is not None:
            # img tag
            query = url_encode(query_keys, charset=CHARSET, encode_keys=True)
            # TODO: moin 1.9 needed this for an attached file; move functionality to script/migration/moin/import19.py
            att = 'attachment:'
            if object_item.startswith(att):
                object_item = '/' + object_item[len(att):]  # now we have a subitem
            target = Iri(scheme='wiki.local', path=object_item, query=query, fragment=None)
            attrib[xinclude.href] = target
            element = xinclude.include(attrib=attrib)
            stack.top_append(element)
        else:
            # object tag
            target = Iri(object_url)
            attrib[xlink.href] = target
            element = moin_page.object(attrib)
            stack.top_append(element)
Ejemplo n.º 4
0
    def inline_object_repl(self,
                           stack,
                           object,
                           object_page=None,
                           object_url=None,
                           object_text=None):
        """Handles objects included in the page."""

        if object_page is not None:
            att = 'attachment:'  # moin 1.9 needed this for an attached file
            if object_page.startswith(att):
                object_page = '/' + object_page[len(
                    att):]  # now we have a subitem
            target = Iri(scheme='wiki.local', path=object_page)
            text = object_page

            attrib = {xinclude.href: target}
            element = xinclude.include(attrib=attrib)
            stack.top_append(element)

        else:
            target = object_url
            text = object_url

            element = moin_page.object({xlink.href: target})
            stack.push(element)
            self.parse_inline(object_text or text, stack, self.link_desc_re)
            stack.pop()
Ejemplo n.º 5
0
 def visit_img(self, element):
     """
     <img src="URI" /> --> <object xlink:href="URI />
     """
     key = xlink('href')
     attrib = {}
     attrib[key] = element.attrib.get("src")
     return moin_page.object(attrib)
Ejemplo n.º 6
0
 def visit_xhtml_img(self, element):
     """
     <img src="URI" /> --> <object xlink:href="URI />
     """
     key = xlink('href')
     attrib = {}
     if self.base_url:
         attrib[key] = ''.join([self.base_url, element.get(html.src)])
     else:
         attrib[key] = element.get(html.src)
     return moin_page.object(attrib)
Ejemplo n.º 7
0
 def visit_xhtml_img(self, element):
     """
     <img src="URI" /> --> <object xlink:href="URI />
     """
     key = xlink('href')
     attrib = {}
     if self.base_url:
         attrib[key] = ''.join([self.base_url, element.get(html.src)])
     else:
         attrib[key] = element.get(html.src)
     return moin_page.object(attrib)
Ejemplo n.º 8
0
 def visit_xhtml_img(self, element):
     """
     <img src="URI" /> --> <object xlink:href="URI />
     """
     key = xlink('href')
     attrib = self.convert_attributes(element)
     # adding type_ attrib makes html_out create an image tag rather than an object tag
     attrib[moin_page.type_] = 'image/'
     if self.base_url:
         attrib[key] = ''.join([self.base_url, element.get(html.src)])
     else:
         attrib[key] = element.get(html.src)
     return moin_page.object(attrib)
Ejemplo n.º 9
0
    def visit_xhtml_object(self, element):
        """
        <object data="href"></object> --> <object xlink="href" />
        """
        key = xlink('href')
        attrib = {}
        if self.base_url:
            attrib[key] = ''.join([self.base_url, element.get(html.data)])
        else:
            attrib[key] = element.get(html.data)

        # Convert the href attribute into unicode
        attrib[key] = unicode(attrib[key])
        return moin_page.object(attrib)
Ejemplo n.º 10
0
    def visit_object(self, element):
        """
        <object data="href"></object> --> <object xlink="href" />
        """
        key = xlink('href')
        attrib = {}
        if self.base_url:
            attrib[key] = ''.join([self.base_url, element.get(html.data)])
        else:
            attrib[key] = element.get(html.data)

        # Convert the href attribute into unicode
        attrib[key] = unicode(attrib[key])
        return moin_page.object(attrib)
Ejemplo n.º 11
0
    def visit_image(self, node):
        """
        Processes images and other transcluded objects.
        """
        whitelist = [
            'width',
            'height',
            'alt',
        ]
        attrib = {}
        for key in whitelist:
            if node.get(key):
                attrib[html(key)] = node.get(key)

        # there is no 'scale' attribute, hence absent from whitelist, handled separately
        if node.get('scale'):
            scaling_factor = int(node.get('scale')) / 100.0
            for key in ('width', 'height'):
                if html(key) in attrib:
                    attrib[html(key)] = int(
                        int(attrib[html(key)]) * scaling_factor)

        # "align" parameter is invalid in HTML5. Convert it to a class defined in userstyles.css.
        userstyles = {
            'left': 'left',
            'center': 'center',
            'right': 'right',
            'top':
            'top',  # rst parser creates error messages for top, bottom, and middle
            'bottom': 'bottom',
            'middle': 'middle',
        }
        alignment = userstyles.get(node.get('align'))
        if alignment:
            attrib[html.class_] = alignment

        url = Iri(node['uri'])
        if url.scheme is None:
            # img
            target = Iri(scheme='wiki.local', path=node['uri'], fragment=None)
            attrib[xinclude.href] = target
            new_node = xinclude.include(attrib=attrib)
        else:
            # obj
            new_node = moin_page.object(attrib)
            new_node.set(xlink.href, url)

        self.open_moin_page_node(new_node)
Ejemplo n.º 12
0
 def inline_object_repl(self, stack, object, object_page=None, object_url=None, object_text=None):
     """Handles objects included in the page."""
     attrib = {}
     if object_text:
         attrib[html.alt] = object_text
     if object_page is not None:
         att = 'attachment:'  # moin 1.9 needed this for an attached file
         if object_page.startswith(att):
             object_page = '/' + object_page[len(att):]  # now we have a subitem
         target = Iri(scheme='wiki.local', path=object_page)
         attrib[xinclude.href] = target
         element = xinclude.include(attrib=attrib)
     else:
         attrib[xlink.href] = object_url
         element = moin_page.object(attrib)
     stack.top_append(element)
Ejemplo n.º 13
0
 def visit_img(self, element):
     """
     <img src="URI" /> --> <object xlink:href="URI />
     """
     attrib = {}
     url = Iri(element.attrib.get('src'))
     if element.attrib.get('alt'):
         attrib[html.alt] = element.attrib.get('alt')
     if url.scheme is None:
         # img tag
         target = Iri(scheme='wiki.local', path=element.attrib.get("src"), fragment=None)
         attrib[xinclude.href] = target
         new_node = xinclude.include(attrib=attrib)
     else:
         # object tag
         attrib[xlink.href] = url
         new_node = moin_page.object(attrib)
     return new_node
Ejemplo n.º 14
0
 def visit_img(self, element):
     """
     <img src="URI" /> --> <object xlink:href="URI />
     """
     attrib = {}
     url = Iri(element.attrib.get('src'))
     if element.attrib.get('alt'):
         attrib[html.alt] = element.attrib.get('alt')
     if url.scheme is None:
         # img tag
         target = Iri(scheme='wiki.local', path=element.attrib.get("src"), fragment=None)
         attrib[xinclude.href] = target
         new_node = xinclude.include(attrib=attrib)
     else:
         # object tag
         attrib[xlink.href] = url
         new_node = moin_page.object(attrib)
     return new_node
Ejemplo n.º 15
0
    def visit_image(self, node):
        new_node = moin_page.object(attrib={xlink.href: node['uri']})
        # TODO: rewrite this more compact
        alt = node.get('alt', None)
        if alt:
            new_node.set(moin_page.alt, node['uri'])
        arg = node.get('width', u'')
        if arg:
            new_node.set(moin_page.width, arg)
        arg = node.get('height', u'')
        if arg:
            new_node.set(moin_page.height, arg)

        # TODO: there is no 'scale' attribute in moinwiki
        arg = node.get('scale', u'')
        if arg:
            new_node.set(moin_page.scale, arg)

        self.open_moin_page_node(new_node)
Ejemplo n.º 16
0
    def inline_object_repl(self,
                           stack,
                           object,
                           object_url=None,
                           object_item=None,
                           object_text=None,
                           object_args=None):
        """Handles objects included in the page."""
        if object_args:
            args = parse_arguments(
                object_args).keyword  # XXX needs different parsing
        else:
            args = {}
        if object_item is not None:
            query = url_encode(args, charset=config.charset, encode_keys=True)
            att = 'attachment:'  # moin 1.9 needed this for an attached file
            if object_item.startswith(att):
                object_item = '/' + object_item[len(
                    att):]  # now we have a subitem
            target = Iri(scheme='wiki.local',
                         path=object_item,
                         query=query,
                         fragment=None)
            text = object_item

            attrib = {xinclude.href: target}
            element = xinclude.include(attrib=attrib)
            stack.top_append(element)
        else:
            target = Iri(object_url)
            text = object_url

            attrib = {xlink.href: target}
            if object_text is not None:
                attrib[moin_page.alt] = object_text

            element = moin_page.object(attrib)
            stack.push(element)
            if object_text:
                self.parse_inline(object_text, stack, self.inlinedesc_re)
            else:
                stack.top_append(text)
            stack.pop()
Ejemplo n.º 17
0
    def visit_image(self, node):
        new_node = moin_page.object(attrib={xlink.href: node['uri']})
        # TODO: rewrite this more compact
        alt = node.get('alt', None)
        if alt:
            new_node.set(moin_page.alt, node['uri'])
        arg = node.get('width', u'')
        if arg:
            new_node.set(moin_page.width, arg)
        arg = node.get('height', u'')
        if arg:
            new_node.set(moin_page.height, arg)

        # TODO: there is no 'scale' attribute in moinwiki
        arg = node.get('scale', u'')
        if arg:
            new_node.set(moin_page.scale, arg)

        self.open_moin_page_node(new_node)
Ejemplo n.º 18
0
    def visit_image(self, node):
        """
        Processes images and other transcluded objects.
        """
        whitelist = ['width', 'height', 'alt', ]
        attrib = {}
        for key in whitelist:
            if node.get(key):
                attrib[html(key)] = node.get(key)

        # there is no 'scale' attribute, hence absent from whitelist, handled separately
        if node.get('scale'):
            scaling_factor = int(node.get('scale')) / 100.0
            for key in ('width', 'height'):
                if html(key) in attrib:
                    attrib[html(key)] = int(int(attrib[html(key)]) * scaling_factor)

        # "align" parameter is invalid in HTML5. Convert it to a class defined in userstyles.css.
        userstyles = {
            'left': 'left',
            'center': 'center',
            'right': 'right',
            'top': 'top',  # rst parser creates error messages for top, bottom, and middle
            'bottom': 'bottom',
            'middle': 'middle',
        }
        alignment = userstyles.get(node.get('align'))
        if alignment:
            attrib[html.class_] = alignment

        url = Iri(node['uri'])
        if url.scheme is None:
            # img
            target = Iri(scheme='wiki.local', path=node['uri'], fragment=None)
            attrib[xinclude.href] = target
            new_node = xinclude.include(attrib=attrib)
        else:
            # obj
            new_node = moin_page.object(attrib)
            new_node.set(xlink.href, url)

        self.open_moin_page_node(new_node)
Ejemplo n.º 19
0
    def inline_object_repl(self, stack, object, object_page=None, object_url=None, object_text=None):
        """Handles objects included in the page."""

        if object_page is not None:
            att = "attachment:"  # moin 1.9 needed this for an attached file
            if object_page.startswith(att):
                object_page = "/" + object_page[len(att) :]  # now we have a subitem
            target = Iri(scheme="wiki.local", path=object_page)
            text = object_page

            attrib = {xinclude.href: target}
            element = xinclude.include(attrib=attrib)
            stack.top_append(element)

        else:
            target = object_url
            text = object_url

            element = moin_page.object({xlink.href: target})
            stack.push(element)
            self.parse_inline(object_text or text, stack, self.link_desc_re)
            stack.pop()
Ejemplo n.º 20
0
    def inline_link_repl(self, stack, link, link_url=None, link_item=None,
                         link_args=u'', external_link_url=None, alt_text=u''):
        """Handle all kinds of links."""
        link_text = ''
        link_args_list = []
        # Remove the first pipe/space, example of link_args : |arg1|arg2 or " arg1 arg2"
        parsed_args = self.parse_args(link_args[1:])
        query = None
        if parsed_args.keyword:
            query = url_encode(parsed_args.keyword, charset=CHARSET, encode_keys=True)
        # Take the last of positional parameters as link_text(caption)
        if parsed_args.positional:
            link_text = parsed_args.positional.pop()
        if link_item is not None:
            if '#' in link_item:
                path, fragment = link_item.rsplit('#', 1)
            else:
                path, fragment = link_item, None
            target = Iri(scheme='wiki.local', path=path, query=query, fragment=fragment)
            text = link_item
        else:
            if link_url and len(link_url.split(':')) > 0 and link_url.split(':')[0] == 'File':
                object_item = ':'.join(link_url.split(':')[1:])
                args = parsed_args.keyword
                if object_item is not None:
                    if 'do' not in args:
                        # by default, we want the item's get url for transclusion of raw data:
                        args['do'] = 'get'
                    query = url_encode(args, charset=CHARSET, encode_keys=True)
                    target = Iri(scheme='wiki.local', path=object_item, query=query, fragment=None)
                    text = object_item
                else:
                    target = Iri(scheme='wiki.local', path=object_url)
                    text = object_url

                if not link_text:
                    link_text = text
                attrib = {xlink.href: target}
                attrib[moin_page.alt] = link_text

                element = moin_page.object(attrib)
                stack.push(element)
                if link_text:
                    self.preprocessor.push()
                    self.parse_inline(link_text, stack, self.inlinedesc_re)
                    self.preprocessor.pop()
                else:
                    stack.top_append(text)
                stack.pop()
                return
            target = Iri(scheme='wiki.local', path=link_url)
            text = link_url
        if external_link_url:
            target = Iri(external_link_url)
            text = alt_text
        element = moin_page.a(attrib={xlink.href: target})
        stack.push(element)
        if link_text:
            self.preprocessor.push()
            self.parse_inline(link_text, stack, self.inlinedesc_re)
            self.preprocessor.pop()
        else:
            stack.top_append(text)
        stack.pop()
Ejemplo n.º 21
0
    def inline_link_repl(self,
                         stack,
                         link,
                         link_url=None,
                         link_item=None,
                         link_args=None,
                         external_link_url=None,
                         alt_text=''):
        """Handle all kinds of links."""
        link_text = ''
        if link_args and len(link_args.split('|')) > 2:
            link_args = parse_arguments(' '.join(link_args.split(
                '|')[:-1]))  # TODO needs parsing for mediawiki_args
            query = url_encode(link_args.keyword,
                               charset=config.charset,
                               encode_keys=True)
        else:
            if link_args:
                link_text = link_args.split('|')[-1]
                link_args = parse_arguments(' '.join(
                    link_args.split('|')[:-1]))

            query = None
        if link_item is not None:
            if '#' in link_item:
                path, fragment = link_item.rsplit('#', 1)
            else:
                path, fragment = link_item, None
            target = Iri(scheme='wiki.local',
                         path=path,
                         query=query,
                         fragment=fragment)
            text = link_item
        else:
            if link_url and len(link_url.split(':')) > 0 and link_url.split(
                    ':')[0] == 'File':
                object_item = ':'.join(link_url.split(':')[1:])
                args = link_args.keyword
                if object_item is not None:
                    if 'do' not in args:
                        # by default, we want the item's get url for transclusion of raw data:
                        args['do'] = 'get'
                    query = url_encode(args,
                                       charset=config.charset,
                                       encode_keys=True)
                    target = Iri(scheme='wiki.local',
                                 path=object_item,
                                 query=query,
                                 fragment=None)
                    text = object_item
                else:
                    target = Iri(object_url)
                    text = object_url

                attrib = {xlink.href: target}
                if link_text is not None:
                    attrib[moin_page.alt] = link_text

                element = moin_page.object(attrib)
                stack.push(element)
                if link_text:
                    self.preprocessor.push()
                    self.parse_inline(link_text, stack, self.inlinedesc_re)
                    self.preprocessor.pop()
                else:
                    stack.top_append(text)
                stack.pop()
                return
            target = Iri(link_url)
            text = link_url
        if external_link_url:
            target = Iri(external_link_url)
            text = alt_text
        element = moin_page.a(attrib={xlink.href: target})
        stack.push(element)
        if link_text:
            self.preprocessor.push()
            self.parse_inline(link_text, stack, self.inlinedesc_re)
            self.preprocessor.pop()
        else:
            stack.top_append(text)
        stack.pop()