~bjornt/editmoin/factor-out-edit-function

« back to all changes in this revision

Viewing changes to editmoin

  • Committer: niemeyer
  • Date: 2005-09-04 03:01:31 UTC
  • Revision ID: niemeyer-0e2153bc1f17c6b7407b804519ec805769ab8eea
Added support to Moin 1.3.5.

Show diffs side-by-side

added added

removed removed

Lines of Context:
35
35
                    re.M|re.DOTALL)
36
36
DATESTAMPRE = re.compile('<input.*?name="datestamp".*?value="(.*?)".*?>')
37
37
NOTIFYRE = re.compile('<input.*?name="notify".*?value="(.*?)".*?>')
38
 
MESSAGERE = re.compile('<div class="message">(.*?)</div>', re.M|re.DOTALL)
39
 
OLDMESSAGERE = re.compile('^</table>(.*?)<a.*?>Clear message</a>', re.M|re.DOTALL)
 
38
MESSAGERE1 = re.compile('^</table>(.*?)<a.*?>Clear message</a>', re.M|re.DOTALL)
 
39
MESSAGERE2 = re.compile('<div class="message">(.*?)</div>', re.M|re.DOTALL)
 
40
MESSAGERE3 = re.compile('<div id="message">\s*<p>(.*?)</p>', re.M|re.DOTALL)
40
41
 
41
42
CANCELRE = re.compile('<input type="submit" name="button_cancel" value="(.*?)">')
42
43
 
55
56
        self.id = id
56
57
        self.data = open(filename).read()
57
58
        self.body = self._get_data(BODYRE, "body")
58
 
        self.datestamp = self._get_data(DATESTAMPRE, "datestamp")
 
59
        try:
 
60
            self.datestamp = self._get_data(DATESTAMPRE, "datestamp")
 
61
        except Error:
 
62
            self.datestamp = None
59
63
        try:
60
64
            self.notify = self._get_data(NOTIFYRE, "notify")
61
65
            self.comment = "None"
147
151
 
148
152
def get_message(data):
149
153
    message = None
150
 
    match = MESSAGERE.search(data)
 
154
    match = MESSAGERE3.search(data)
 
155
    if not match:
 
156
        # Check for moin < 1.3.5 (not sure the precise version it changed).
 
157
        match = MESSAGERE2.search(data)
151
158
    if not match:
152
159
        # Check for moin <= 0.9.
153
 
        match = OLDMESSAGERE.search(data)
 
160
        match = MESSAGERE1.search(data)
154
161
    if match:
155
162
        message = match.group(1)
156
163
        message = re.subn("\n", " ", message)[0]
185
192
    if template:
186
193
        geturl += "&template=" + urllib.quote(template)
187
194
    filename, headers = urlopener.retrieve(geturl)
 
195
    os.system("cp -f %s /tmp/moinfile" % filename)
188
196
    return MoinFile(filename, id)
189
197
 
190
198
def editfile(moinfile):
207
215
            comment += urllib.quote(moinfile.comment)
208
216
    else:
209
217
        comment = ""
210
 
    data = "action=savepage&button_save=1&datestamp=%s&savetext=%s%s" \
211
 
           % (moinfile.datestamp, urllib.quote(moinfile.body), comment)
 
218
    data = "action=savepage&button_save=1&savetext=%s%s" \
 
219
           % (urllib.quote(moinfile.body), comment)
 
220
    if moinfile.datestamp:
 
221
        data += "&datestamp=%s" % moinfile.datestamp
212
222
    if moinfile.notify == "Yes":
213
223
        data += "&notify=1"
214
224
    if moinfile.add_category and moinfile.add_category != "None":
226
236
def sendcancel(urlopener, url, moinfile):
227
237
    if not moinfile.has_cancel():
228
238
        return
229
 
    data = "action=savepage&button_cancel=1&datestamp=%s" % moinfile.datestamp
 
239
    data = "action=savepage&button_cancel=1"
 
240
    if moinfile.datestamp:
 
241
        data += "&datestamp=%s" % moinfile.datestamp
230
242
    url = urlopener.open(url, data)
231
243
    answer = url.read()
232
244
    url.close()