本文整理汇总了Python中MoinMoin.Page.Page.get_real_rev方法的典型用法代码示例。如果您正苦于以下问题:Python Page.get_real_rev方法的具体用法?Python Page.get_real_rev怎么用?Python Page.get_real_rev使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MoinMoin.Page.Page
的用法示例。
在下文中一共展示了Page.get_real_rev方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: createSyncPage
# 需要导入模块: from MoinMoin.Page import Page [as 别名]
# 或者: from MoinMoin.Page.Page import get_real_rev [as 别名]
def createSyncPage(self, page_name):
normalised_name = normalise_pagename(page_name, self.prefix)
if normalised_name is None:
return None
page = Page(self.request, page_name)
revno = page.get_real_rev()
if revno == 99999999: # I love sane in-band signalling
return None
return SyncPage(normalised_name, local_rev=revno, local_name=page_name, local_deleted=not page.exists())
示例2: _index_page_rev
# 需要导入模块: from MoinMoin.Page import Page [as 别名]
# 或者: from MoinMoin.Page.Page import get_real_rev [as 别名]
def _index_page_rev(self, request, connection, pagename, revno, mode='update'):
""" Index a page revision.
@param request: request suitable for indexing
@param connection: the Indexer connection object
@param pagename: the page name
@param revno: page revision number (int)
@param mode: 'add' = just add, no checks
'update' = check if already in index and update if needed (mtime)
"""
page = Page(request, pagename, rev=revno)
request.page = page # XXX for what is this needed?
wikiname = request.cfg.interwikiname or u"Self"
revision = str(page.get_real_rev())
itemid = "%s:%s:%s" % (wikiname, pagename, revision)
mtime = page.mtime_usecs()
doc = self._get_document(connection, itemid, mtime, mode)
logging.debug("%s %s %r" % (pagename, revision, doc))
if doc:
mimetype = 'text/%s' % page.pi['format'] # XXX improve this
fields = {}
fields['wikiname'] = wikiname
fields['pagename'] = pagename
fields['attachment'] = '' # this is a real page, not an attachment
fields['mtime'] = str(mtime)
fields['revision'] = revision
fields['title'] = pagename
fields['content'] = page.get_raw_body()
fields['lang'], fields['stem_lang'] = self._get_languages(page)
fields['author'] = page.edit_info().get('editor', '?')
multivalued_fields = {}
multivalued_fields['mimetype'] = [mt for mt in [mimetype] + mimetype.split('/')]
multivalued_fields['domain'] = self._get_domains(page)
multivalued_fields['linkto'] = page.getPageLinks(request)
multivalued_fields['category'] = self._get_categories(page)
self._add_fields_to_document(request, doc, fields, multivalued_fields)
try:
connection.replace(doc)
except xappy.IndexerError, err:
logging.warning("IndexerError at %r %r %r (%s)" % (
wikiname, pagename, revision, str(err)))
示例3: execute
# 需要导入模块: from MoinMoin.Page import Page [as 别名]
# 或者: from MoinMoin.Page.Page import get_real_rev [as 别名]
def execute(pagename, request):
""" Handle "action=diff"
checking for either a "rev=formerrevision" parameter
or rev1 and rev2 parameters
"""
if not request.user.may.read(pagename):
Page(request, pagename).send_page()
return
try:
date = request.values['date']
try:
date = long(date) # must be long for py 2.2.x
except StandardError:
date = 0
except KeyError:
date = 0
try:
rev1 = int(request.values.get('rev1', -1))
except StandardError:
rev1 = 0
try:
rev2 = int(request.values.get('rev2', 0))
except StandardError:
rev2 = 0
if rev1 == -1 and rev2 == 0:
rev1 = request.rev
if rev1 is None:
rev1 = -1
# spacing flag?
ignorews = int(request.values.get('ignorews', 0))
_ = request.getText
# get a list of old revisions, and back out if none are available
currentpage = Page(request, pagename)
currentrev = currentpage.current_rev()
if currentrev < 2:
request.theme.add_msg(_("No older revisions available!"), "error")
currentpage.send_page()
return
if date: # this is how we get called from RecentChanges
rev1 = 0
log = editlog.EditLog(request, rootpagename=pagename)
for line in log.reverse():
if date >= line.ed_time_usecs and int(line.rev) != 99999999:
rev1 = int(line.rev)
break
else:
rev1 = 1
rev2 = 0
if rev1 > 0 and rev2 > 0 and rev1 > rev2 or rev1 == 0 and rev2 > 0:
rev1, rev2 = rev2, rev1
if rev1 == -1:
oldrev = currentrev - 1
oldpage = Page(request, pagename, rev=oldrev)
elif rev1 == 0:
oldrev = currentrev
oldpage = currentpage
else:
oldrev = rev1
oldpage = Page(request, pagename, rev=oldrev)
if rev2 == 0:
newrev = currentrev
newpage = currentpage
else:
newrev = rev2
newpage = Page(request, pagename, rev=newrev)
oldlog = oldpage.editlog_entry()
newlog = newpage.editlog_entry()
if not oldlog or not newlog:
# We use "No log entries found." msg because we already have i18n
# for that. Better would "At least one log entry was not found.".
request.theme.add_msg(_("No log entries found."), "error")
currentpage.send_page()
return
edit_count = abs(newrev - oldrev)
# Start output
# This action generates content in the user language
request.setContentLanguage(request.lang)
request.theme.send_title(_('Diff for "%s"') % (pagename, ), pagename=pagename, allow_doubleclick=1)
f = request.formatter
request.write(f.div(1, id="content"))
oldrev = oldpage.get_real_rev()
newrev = newpage.get_real_rev()
#.........这里部分代码省略.........
示例4: do_diff
# 需要导入模块: from MoinMoin.Page import Page [as 别名]
# 或者: from MoinMoin.Page.Page import get_real_rev [as 别名]
#.........这里部分代码省略.........
rev1 = 0
log = editlog.EditLog(request, rootpagename=pagename)
for line in log.reverse():
if date >= line.ed_time_usecs and int(line.rev) != 99999999:
rev1 = int(line.rev)
break
else:
rev1 = 1
rev2 = 0
# Start output
# This action generate content in the user language
request.setContentLanguage(request.lang)
request.http_headers()
wikiutil.send_title(request, _('Diff for "%s"') % (pagename,), pagename=pagename)
if (rev1>0 and rev2>0 and rev1>rev2) or (rev1==0 and rev2>0):
rev1,rev2 = rev2,rev1
oldrev1,oldcount1 = None,0
oldrev2,oldcount2 = None,0
# get the filename of the version to compare to
edit_count = 0
for rev in revisions:
edit_count += 1
if rev <= rev1:
oldrev1,oldcount1 = rev,edit_count
if rev2 and rev >= rev2:
oldrev2,oldcount2 = rev,edit_count
if (oldrev1 and oldrev2) or (oldrev1 and not rev2):
break
if rev1 == -1:
oldpage = Page(request, pagename, rev=revisions[1])
oldcount1 = oldcount1 - 1
elif rev1 == 0:
oldpage = currentpage
# oldcount1 is still on init value 0
else:
if oldrev1:
oldpage = Page(request, pagename, rev=oldrev1)
else:
oldpage = Page(request, "$EmptyPage$") # hack
oldpage.set_raw_body("") # avoid loading from disk
oldrev1 = 0 # XXX
if rev2 == 0:
newpage = currentpage
# oldcount2 is still on init value 0
else:
if oldrev2:
newpage = Page(request, pagename, rev=oldrev2)
else:
newpage = Page(request, "$EmptyPage$") # hack
newpage.set_raw_body("") # avoid loading from disk
oldrev2 = 0 # XXX
edit_count = abs(oldcount1 - oldcount2)
# this should use the formatter, but there is none?
request.write('<div id="content">\n') # start content div
request.write('<p class="diff-header">')
request.write(_('Differences between revisions %d and %d') % (oldpage.get_real_rev(), newpage.get_real_rev()))
if edit_count > 1:
request.write(' ' + _('(spanning %d versions)') % (edit_count,))
request.write('</p>')
if request.user.show_fancy_diff:
from MoinMoin.util.diff import diff
request.write(diff(request, oldpage.get_raw_body(), newpage.get_raw_body()))
newpage.send_page(request, count_hit=0, content_only=1, content_id="content-below-diff")
else:
lines = wikiutil.linediff(oldpage.getlines(), newpage.getlines())
if not lines:
msg = _("No differences found!")
if edit_count > 1:
msg = msg + '<p>' + _('The page was saved %(count)d times, though!') % {
'count': edit_count}
request.write(msg)
else:
if ignorews:
request.write(_('(ignoring whitespace)') + '<br>')
else:
qstr = 'action=diff&ignorews=1'
if rev1: qstr = '%s&rev1=%s' % (qstr, rev1)
if rev2: qstr = '%s&rev2=%s' % (qstr, rev2)
request.write(Page(request, pagename).link_to(request,
text=_('Ignore changes in the amount of whitespace'),
querystr=qstr) + '<p>')
request.write('<pre>')
for line in lines:
if line[0] == "@":
request.write('<hr>')
request.write(wikiutil.escape(line)+'\n')
request.write('</pre>')
request.write('</div>\n') # end content div
wikiutil.send_footer(request, pagename, showpage=1)
示例5: xmlrpc_getDiff
# 需要导入模块: from MoinMoin.Page import Page [as 别名]
# 或者: from MoinMoin.Page.Page import get_real_rev [as 别名]
def xmlrpc_getDiff(self, pagename, from_rev, to_rev, n_name=None):
"""
Gets the binary difference between two page revisions.
@param pagename: unicode string qualifying the page name
@param fromRev: integer specifying the source revision. May be None to
refer to a virtual empty revision which leads to a diff
containing the whole page.
@param toRev: integer specifying the target revision. May be None to
refer to the current revision. If the current revision is the same
as fromRev, there will be a special error condition "ALREADY_CURRENT"
@param n_name: do a tag check verifying that n_name was the normalised
name of the last tag
If both fromRev and toRev are None, this function acts similar to getPage, i.e. it will diff("",currentRev).
@return: Returns a dict:
* status (not a field, implicit, returned as Fault if not SUCCESS):
* "SUCCESS" - if the diff could be retrieved successfully
* "NOT_EXIST" - item does not exist
* "FROMREV_INVALID" - the source revision is invalid
* "TOREV_INVALID" - the target revision is invalid
* "INTERNAL_ERROR" - there was an internal error
* "INVALID_TAG" - the last tag does not match the supplied normalised name
* "ALREADY_CURRENT" - this not merely an error condition. It rather means that
there is no new revision to diff against which is a good thing while
synchronisation.
* current: the revision number of the current revision (not the one which was diff'ed against)
* diff: Binary object that transports a zlib-compressed binary diff (see bdiff.py, taken from Mercurial)
* conflict: if there is a conflict on the page currently
"""
from MoinMoin.util.bdiff import textdiff, compress
from MoinMoin.wikisync import TagStore
pagename = self._instr(pagename)
if n_name is not None:
n_name = self._instr(n_name)
# User may read page?
if not self.request.user.may.read(pagename):
return self.notAllowedFault()
def allowed_rev_type(data):
if data is None:
return True
return isinstance(data, int) and data > 0
if not allowed_rev_type(from_rev):
return xmlrpclib.Fault("FROMREV_INVALID", "Incorrect type for from_rev.")
if not allowed_rev_type(to_rev):
return xmlrpclib.Fault("TOREV_INVALID", "Incorrect type for to_rev.")
currentpage = Page(self.request, pagename)
if not currentpage.exists():
return xmlrpclib.Fault("NOT_EXIST", "Page does not exist.")
revisions = currentpage.getRevList()
if from_rev is not None and from_rev not in revisions:
return xmlrpclib.Fault("FROMREV_INVALID", "Unknown from_rev.")
if to_rev is not None and to_rev not in revisions:
return xmlrpclib.Fault("TOREV_INVALID", "Unknown to_rev.")
# use lambda to defer execution in the next lines
if from_rev is None:
oldcontents = lambda: ""
else:
oldpage = Page(self.request, pagename, rev=from_rev)
oldcontents = lambda: oldpage.get_raw_body_str()
if to_rev is None:
newpage = currentpage
newcontents = lambda: currentpage.get_raw_body_str()
else:
newpage = Page(self.request, pagename, rev=to_rev)
newcontents = lambda: newpage.get_raw_body_str()
if oldcontents() and oldpage.get_real_rev() == newpage.get_real_rev():
return xmlrpclib.Fault("ALREADY_CURRENT", "There are no changes.")
if n_name is not None:
tags = TagStore(newpage)
last_tag = tags.get_last_tag()
if last_tag is not None and last_tag.normalised_name != n_name:
return xmlrpclib.Fault("INVALID_TAG", "The used tag is incorrect because the normalised name does not match.")
newcontents = newcontents()
conflict = wikiutil.containsConflictMarker(newcontents)
diffblob = xmlrpclib.Binary(compress(textdiff(oldcontents(), newcontents)))
return {"conflict": conflict, "diff": diffblob, "diffversion": 1, "current": currentpage.get_real_rev()}
示例6: execute
# 需要导入模块: from MoinMoin.Page import Page [as 别名]
# 或者: from MoinMoin.Page.Page import get_real_rev [as 别名]
def execute(pagename, request):
form = values_to_form(request.values)
util = form.get('util', [None])[0]
if util == "format":
txt = form.get('text', [None])[0]
request.write(format_wikitext(request, txt))
elif util == "getTemplate":
template = form.get('name', [None])[0]
template_page = wikiutil.unquoteWikiname(template)
if request.user.may.read(template_page):
Page(request, template_page).send_raw()
elif util == "newPage":
page = form.get('page', [None])[0]
content = form.get('content', [""])[0]
request.content_type = "application/json"
if request.environ['REQUEST_METHOD'] != 'POST':
return
if not page:
msg = "Page name not defined!"
json.dump(dict(status="error", msg=msg), request)
return
if not request.user.may.write(page):
msg = "You are not allowed to edit this page"
json.dump(dict(status="error", msg=msg), request)
return
p = Page(request, page)
if p.exists():
msg = "Page already exists"
json.dump(dict(status="error", msg=msg), request)
return
editor = PageEditor(request, page)
msg = editor.saveText(content, p.get_real_rev())
json.dump(dict(status="ok", msg=msg), request)
elif util == "getProperties":
request.content_type = "application/json"
key = form.get('key', [''])[0]
json.dump(get_properties(request, key), request)
return
elif util == "uploadFile":
request.content_type = "application/json"
if not request.user.may.write(pagename):
msg = u"You are not allowed to edit this page!"
json.dump(dict(status="error", msg=msg), request)
request.status_code = 403
return
from MoinMoin.action.AttachFile import add_attachment, AttachmentAlreadyExists
try:
overwrite = int(form.get('overwrite', ['0'])[0])
except:
overwrite = 0
response = dict(success=list(), failed=list())
for name in request.files:
_file = request.files.get(name)
filename = _file.filename
try:
t,s = add_attachment(request, pagename, filename, _file.stream, overwrite=overwrite)
response['success'].append(filename)
except AttachmentAlreadyExists:
response['failed'].append(filename)
json.dump(response, request)
return
elif util == "getAttachments":
request.content_type = "application/json"
from MoinMoin.action.AttachFile import _get_files, getAttachUrl
files = _get_files(request, pagename)
response = []
for name in files:
response.append(dict(url=getAttachUrl(pagename, name, request),name=name))
json.dump(response, request)
return
示例7: execute
# 需要导入模块: from MoinMoin.Page import Page [as 别名]
# 或者: from MoinMoin.Page.Page import get_real_rev [as 别名]
def execute(pagename, request):
""" Handle "action=diff"
checking for either a "rev=formerrevision" parameter
or rev1 and rev2 parameters
"""
if not request.user.may.read(pagename):
Page(request, pagename).send_page()
return
try:
date = request.form['date'][0]
try:
date = long(date) # must be long for py 2.2.x
except StandardError:
date = 0
except KeyError:
date = 0
try:
rev1 = int(request.form.get('rev1', [-1])[0])
except StandardError:
rev1 = 0
try:
rev2 = int(request.form.get('rev2', [0])[0])
except StandardError:
rev2 = 0
if rev1 == -1 and rev2 == 0:
rev1 = request.rev
if rev1 is None:
rev1 = -1
# spacing flag?
ignorews = int(request.form.get('ignorews', [0])[0])
_ = request.getText
# get a list of old revisions, and back out if none are available
currentpage = Page(request, pagename)
currentrev = currentpage.current_rev()
if currentrev < 2:
request.theme.add_msg(_("No older revisions available!"), "error")
currentpage.send_page()
return
if date: # this is how we get called from RecentChanges
rev1 = 0
log = editlog.EditLog(request, rootpagename=pagename)
for line in log.reverse():
if date >= line.ed_time_usecs and int(line.rev) != 99999999:
rev1 = int(line.rev)
break
else:
rev1 = 1
rev2 = 0
# Start output
# This action generates content in the user language
request.setContentLanguage(request.lang)
request.emit_http_headers()
request.theme.send_title(_('Diff for "%s"') % (pagename, ), pagename=pagename, allow_doubleclick=1)
if rev1 > 0 and rev2 > 0 and rev1 > rev2 or rev1 == 0 and rev2 > 0:
rev1, rev2 = rev2, rev1
if rev1 == -1:
oldrev = currentrev - 1
oldpage = Page(request, pagename, rev=oldrev)
elif rev1 == 0:
oldrev = currentrev
oldpage = currentpage
else:
oldrev = rev1
oldpage = Page(request, pagename, rev=oldrev)
if rev2 == 0:
newrev = currentrev
newpage = currentpage
else:
newrev = rev2
newpage = Page(request, pagename, rev=newrev)
edit_count = abs(newrev - oldrev)
f = request.formatter
request.write(f.div(1, id="content"))
oldrev = oldpage.get_real_rev()
newrev = newpage.get_real_rev()
revlist = currentpage.getRevList()
# code below assumes that the page exists and has at least
# one revision in the revlist, just bail out if not. Users
# shouldn't really run into this anyway.
if not revlist:
request.write(f.div(0)) # end content div
request.theme.send_footer(pagename)
request.theme.send_closing_html()
#.........这里部分代码省略.........