Example #1
0
    def parse_page(self):
        """ Parses the parameter page and returns the read arguments. """
        options = {
            "remotePrefix": "",
            "localPrefix": "",
            "remoteWiki": "",
            "pageMatch": None,
            "pageList": None,
            "groupList": None,
            "direction": "foo", # is defaulted below
            "user": None, # XXX should be refactored into a password agent or OpenID like solution
            "password": None,
        }

        options.update(Dict(self.request, self.pagename))

        # Convert page and group list strings to lists
        if options["pageList"] is not None:
            options["pageList"] = unpackLine(options["pageList"], ",")
        if options["groupList"] is not None:
            options["groupList"] = unpackLine(options["groupList"], ",")

        options["direction"] = directions_map.get(options["direction"].lower(), BOTH)

        return options
Example #2
0
    def parse_page(self):
        """ Parses the parameter page and returns the read arguments. """
        options = {
            "remotePrefix": "",
            "localPrefix": "",
            "remoteWiki": "",
            "pageMatch": None,
            "pageList": None,
            "groupList": None,
            "direction": "foo", # is defaulted below
            "user": "", # XXX should be refactored into a password agent or OpenID like solution
            "password": "",
        }

        options.update(self.request.dicts[self.pagename])

        # Convert page and group list strings to lists
        if options["pageList"] is not None:
            options["pageList"] = unpackLine(options["pageList"], ",")
        if options["groupList"] is not None:
            options["groupList"] = unpackLine(options["groupList"], ",")

        options["direction"] = directions_map.get(options["direction"].lower(), BOTH)

        return options
Example #3
0
 def fetch(self, iwid_full, direction=None):
     iwid_full = unpackLine(iwid_full)
     matching_tags = []
     for t in self.tags:
         t_iwid_full = unpackLine(t.remote_wiki)
         if ((t_iwid_full[0] == iwid_full[0]) # either match IWID or IW name
             or (len(t_iwid_full) == 2 and len(iwid_full) == 2 and t_iwid_full[1] == iwid_full[1])
             ) and (direction is None or t.direction == direction):
             matching_tags.append(t)
     return matching_tags
Example #4
0
 def fetch(self, iwid_full, direction=None):
     iwid_full = unpackLine(iwid_full)
     matching_tags = []
     for t in self.tags:
         t_iwid_full = unpackLine(t.remote_wiki)
         if ((t_iwid_full[0] == iwid_full[0]
              )  # either match IWID or IW name
                 or (len(t_iwid_full) == 2 and len(iwid_full) == 2
                     and t_iwid_full[1] == iwid_full[1])) and (
                         direction is None or t.direction == direction):
             matching_tags.append(t)
     return matching_tags
Example #5
0
    def package(self):
        """ Calls collectpackage() with the arguments specified. """
        _ = self.request.getText

        # Get new name from form and normalize.
        pagelist = self.request.values.get('pagelist', u'')
        packagename = self.request.values.get('packagename', u'')
        include_attachments = self.request.values.get('include_attachments',
                                                      False)

        if not self.request.values.get('submit'):
            self.request.theme.add_msg(self.makeform(), "dialog")
            raise ActionError

        target = wikiutil.taintfilename(packagename)

        if not target:
            self.request.theme.add_msg(
                self.makeform(
                    _('Invalid filename "%s"!') %
                    wikiutil.escape(packagename)), "error")
            raise ActionError

        request = self.request
        filelike = cStringIO.StringIO()
        package = self.collectpackage(unpackLine(pagelist, ","), filelike,
                                      target, include_attachments)
        request.headers['Content-Type'] = 'application/zip'
        request.headers['Content-Length'] = filelike.tell()
        request.headers[
            'Content-Disposition'] = 'inline; filename="%s"' % target
        request.write(filelike.getvalue())
        filelike.close()
Example #6
0
    def package(self):
        """ Calls collectpackage() with the arguments specified. """
        _ = self.request.getText

        # Get new name from form and normalize.
        pagelist = self.request.values.get('pagelist', u'')
        packagename = self.request.values.get('packagename', u'')
        include_attachments = self.request.values.get('include_attachments', False)

        if not self.request.values.get('submit'):
            self.request.theme.add_msg(self.makeform(), "dialog")
            raise ActionError

        target = wikiutil.taintfilename(packagename)

        if not target:
            self.request.theme.add_msg(self.makeform(_('Invalid filename "%s"!') % wikiutil.escape(packagename)), "error")
            raise ActionError

        request = self.request
        filelike = cStringIO.StringIO()
        package = self.collectpackage(unpackLine(pagelist, ","), filelike, target, include_attachments)
        request.headers['Content-Type'] = 'application/zip'
        request.headers['Content-Length'] = filelike.tell()
        request.headers['Content-Disposition'] = 'inline; filename="%s"' % target
        request.write(filelike.getvalue())
        filelike.close()
Example #7
0
    def xmlrpc_mergeDiff(self, pagename, diff, local_rev, delta_remote_rev,
                         last_remote_rev, interwiki_name, normalised_name):
        """
        Merges a diff sent by the remote machine and returns the number of the new revision.
        Additionally, this method tags the new revision.

        @param pagename: The pagename that is currently dealt with.
        @param diff: The diff that can be applied to the version specified by delta_remote_rev.
            If it is None, the page is deleted.
        @param local_rev: The revno of the page on the other wiki system, used for the tag.
        @param delta_remote_rev: The revno that the diff is taken against.
        @param last_remote_rev: The last revno of the page `pagename` that is known by the other wiki site.
        @param interwiki_name: Used to build the interwiki tag.
        @param normalised_name: The normalised pagename that is common to both wikis.

        @return: Returns the current revision number after the merge was done. Or one of the following errors:
            * "SUCCESS" - the page could be merged and tagged successfully.
            * "NOT_EXIST" - item does not exist and there was not any content supplied.
            * "LASTREV_INVALID" - the page was changed and the revision got invalid
            * "INTERNAL_ERROR" - there was an internal error
            * "NOT_ALLOWED" - you are not allowed to do the merge operation on the page
        """
        from MoinMoin.util.bdiff import decompress, patch
        from MoinMoin.wikisync import TagStore, BOTH
        from MoinMoin.packages import unpackLine
        LASTREV_INVALID = xmlrpclib.Fault("LASTREV_INVALID",
                                          "The page was changed")

        pagename = self._instr(pagename)

        comment = u"Remote Merge - %r" % unpackLine(interwiki_name)[-1]

        # User may read page?
        if not self.request.user.may.read(
                pagename) or not self.request.user.may.write(pagename):
            return xmlrpclib.Fault(
                "NOT_ALLOWED", "You are not allowed to write to this page.")

        # XXX add locking here!

        # current version of the page
        currentpage = PageEditor(self.request, pagename, do_editor_backup=0)

        if last_remote_rev is not None and currentpage.get_real_rev(
        ) != last_remote_rev:
            return LASTREV_INVALID

        if not currentpage.exists() and diff is None:
            return xmlrpclib.Fault(
                "NOT_EXIST",
                "The page does not exist and no diff was supplied.")

        if diff is None:  # delete the page
            try:
                currentpage.deletePage(comment)
            except PageEditor.AccessDenied, (msg, ):
                return xmlrpclib.Fault("NOT_ALLOWED", msg)
            return currentpage.get_real_rev()
    def xmlrpc_mergeDiff(self, pagename, diff, local_rev, delta_remote_rev, last_remote_rev, interwiki_name, normalised_name):
        """
        Merges a diff sent by the remote machine and returns the number of the new revision.
        Additionally, this method tags the new revision.

        @param pagename: The pagename that is currently dealt with.
        @param diff: The diff that can be applied to the version specified by delta_remote_rev.
            If it is None, the page is deleted.
        @param local_rev: The revno of the page on the other wiki system, used for the tag.
        @param delta_remote_rev: The revno that the diff is taken against.
        @param last_remote_rev: The last revno of the page `pagename` that is known by the other wiki site.
        @param interwiki_name: Used to build the interwiki tag.
        @param normalised_name: The normalised pagename that is common to both wikis.

        @return: Returns the current revision number after the merge was done. Or one of the following errors:
            * "SUCCESS" - the page could be merged and tagged successfully.
            * "NOT_EXIST" - item does not exist and there was not any content supplied.
            * "LASTREV_INVALID" - the page was changed and the revision got invalid
            * "INTERNAL_ERROR" - there was an internal error
            * "NOT_ALLOWED" - you are not allowed to do the merge operation on the page
        """
        from MoinMoin.util.bdiff import decompress, patch
        from MoinMoin.wikisync import TagStore, BOTH
        from MoinMoin.packages import unpackLine
        LASTREV_INVALID = xmlrpclib.Fault("LASTREV_INVALID", "The page was changed")

        pagename = self._instr(pagename)

        comment = u"Remote Merge - %r" % unpackLine(interwiki_name)[-1]

        # User may read page?
        if not self.request.user.may.read(pagename) or not self.request.user.may.write(pagename):
            return xmlrpclib.Fault("NOT_ALLOWED", "You are not allowed to write to this page.")

        # XXX add locking here!

        # current version of the page
        currentpage = PageEditor(self.request, pagename, do_editor_backup=0)

        if last_remote_rev is not None and currentpage.get_real_rev() != last_remote_rev:
            return LASTREV_INVALID

        if not currentpage.exists() and diff is None:
            return xmlrpclib.Fault("NOT_EXIST", "The page does not exist and no diff was supplied.")

        if diff is None: # delete the page
            try:
                currentpage.deletePage(comment)
            except PageEditor.AccessDenied, (msg, ):
                return xmlrpclib.Fault("NOT_ALLOWED", msg)
            return currentpage.get_real_rev()
Example #9
0
def execute(macro, args):
    """ args consists of a character specifiying the separator and then a
    packLine sequence describing a list. The first element of it is the message
    and the remaining elements are substituted in the message using string
    substitution.
    """
    sep = args[0]
    args = unpackLine(args[1:], sep)
    if args:
        translation = macro.request.getText(args[0])
    else:
        translation = u""
    message = translation % tuple(args[1:])

    return macro.formatter.text(message)
Example #10
0
def execute(macro, args):
    """ args consists of a character specifiying the separator and then a
    packLine sequence describing a list. The first element of it is the message
    and the remaining elements are substituted in the message using string
    substitution.
    """
    msg = u''
    if args:
        sep = args[0]
        args = unpackLine(args[1:], sep)
        if args:
            msg, args = args[0], tuple(args[1:])
            msg = macro.request.getText(msg)
            try:
                msg = msg % args
            except TypeError:
                # % operator will raise TypeError if msg has named placeholders
                msg = msg % dict([arg.split('=', 1) for arg in args if '=' in arg])
    return macro.formatter.text(msg)
Example #11
0
def execute(macro, args):
    """ args consists of a character specifiying the separator and then a
    packLine sequence describing a list. The first element of it is the message
    and the remaining elements are substituted in the message using string
    substitution.
    """
    msg = u''
    if args:
        sep = args[0]
        args = unpackLine(args[1:], sep)
        if args:
            msg, args = args[0], tuple(args[1:])
            msg = macro.request.getText(msg)
            try:
                msg = msg % args
            except TypeError:
                # % operator will raise TypeError if msg has named placeholders
                msg = msg % dict(
                    [arg.split('=', 1) for arg in args if '=' in arg])
    return macro.formatter.text(msg)
Example #12
0
    def package(self):
        """ Calls collectpackage() with the arguments specified. """
        _ = self.request.getText
        form = self.request.form

        # Get new name from form and normalize.
        pagelist = form.get('pagelist', [u''])[0]
        packagename = form.get('packagename', [u''])[0]
        include_attachments = form.get('include_attachments', [False])[0]

        if not form.get('submit', [None])[0]:
            self.request.theme.add_msg(self.makeform(), "dialog")
            raise ActionError

        target = wikiutil.taintfilename(packagename)

        if not target:
            self.request.theme.add_msg(self.makeform(_('Invalid filename "%s"!') % wikiutil.escape(packagename)), "error")
            raise ActionError

        # get directory, and possibly create it
        attach_dir = Page(self.request, self.page.page_name).getPagePath("attachments", check_create=1)
        fpath = os.path.join(attach_dir, target).encode(config.charset)
        if os.path.exists(fpath):
            self.request.theme.add_msg(_("Attachment '%(target)s' (remote name '%(filename)s') already exists.") % {
                'target': wikiutil.escape(target), 'filename': wikiutil.escape(target)}, "error")
            raise ActionError

        # Generate a package
        output = open(fpath, "wb")
        package = self.collectpackage(unpackLine(pagelist, ","), output, target, include_attachments)

        if package:
            self.request.theme.add_msg(self.makeform(), "dialog")
            raise ActionError

        _addLogEntry(self.request, 'ATTNEW', self.pagename, target)

        self.request.theme.add_msg(_("Created the package %s containing the pages %s.") % (wikiutil.escape(target), wikiutil.escape(pagelist)))
        raise ActionError
Example #13
0
 def testQuoting(self):
     for line in ([':foo', 'is\\', 'ja|', u't|�', u'baAz�'], [], ['', '']):
         assert line == unpackLine(packLine(line))
Example #14
0
 def testQuoting(self):
     for line in ([':foo', 'is\\', 'ja|', u't|�',
                   u'baAz�'], [], ['', '']):
         assert line == unpackLine(packLine(line))
Example #15
0
 def testQuoting(self):
     for line in ([':foo', 'is\\', 'ja|', u't|ü', u'baAzß'], [], ['', '']):
         self.assertEqual(line, unpackLine(packLine(line)))