Commit 51bc42684794319cf0feb7ae850a31d5e093a0d3
- Diff rendering mode:
- inline
- side by side
ChangeLog
(4 / 0)
|   | |||
| 1 | 1 | 2009-07-02 Krister Svanlund <krister.svanlund@gmail.com> | |
| 2 | 2 | ||
| 3 | 3 | * kofoo_mediawiki.py (do_wiki_get_list): Added command for retrieving lists to IRC. | |
| 4 | (do_wiki_get_section): Added command for retrieving sections to IRC. | ||
| 5 | (mw_add_to_page): Rewrote mw_add_to_page because earlier version did not add text | ||
| 6 | correctly. | ||
| 7 | (do_wiki): Implemented proper commands for adding things to lists and sections. | ||
| 4 | 8 | ||
| 5 | 9 | * kofoo.py (KoFoo.handle_command): Fixed bug causing crash on empty string passed | |
| 6 | 10 | to handle_command. |
kofoo_mediawiki.py
(259 / 41)
|   | |||
| 86 | 86 | if args: | |
| 87 | 87 | if args[0] == 'get' and args[1:]: | |
| 88 | 88 | ### wiki get table|list|section "itemname" on "pagename" ### | |
| 89 | get_pat = re.compile(r'("?)(.*?) on ("?)(\S+)\3 | ||
| 89 | get_pat = re.compile(r'([\"\']?)(.*?) (on|from) ([\"\']?)(\S+)\4 | ||
| 90 | 90 | if args[1] == 'table': | |
| 91 | 91 | m = get_pat.match(' '.join(args[2:])) | |
| 92 | 92 | if m: | |
| 93 | 93 | tablename = m.group(2) | |
| 94 | pagename = m.group(4) | ||
| 94 | pagename = m.group(5) | ||
| 95 | 95 | return do_wiki_get_table(bot, server, sender, target, pagename, tablename) | |
| 96 | 96 | elif args[1] == 'list': | |
| 97 | 97 | m = get_pat.match(' '.join(args[2:])) | |
| 98 | 98 | if m: | |
| 99 | 99 | listname = m.group(2) | |
| 100 | pagename = m.group(4) | ||
| 100 | pagename = m.group(5) | ||
| 101 | 101 | return do_wiki_get_list(bot, server, sender, target, pagename, listname) | |
| 102 | 102 | elif args[1] == 'section': | |
| 103 | 103 | m = get_pat.match(' '.join(args[2:])) | |
| 104 | 104 | if m: | |
| 105 | 105 | sectionname = m.group(2) | |
| 106 | pagename = m.group(4) | ||
| 106 | pagename = m.group(5) | ||
| 107 | return do_wiki_get_section(bot, server, sender, target, pagename, sectionname) | ||
| 107 | 108 | else: | |
| 108 | 109 | bot.respond(server, sender, target, "\x02%s\x02 is not a valid argument." % args[1]) | |
| 109 | 110 | return False | |
| 111 | elif args[0] == 'add' and args[1:]: | ||
| 112 | if args[1] == 'section': | ||
| 113 | return do_wiki_add_section(bot, server, sender, target, args[2:]) | ||
| 114 | elif args[1] == 'table' and args[2:]: | ||
| 115 | return do_wiki_add_table(bot, server, sender, target, args[2:]) | ||
| 116 | elif args[1] == 'to' and args[2:]: | ||
| 117 | if args[2] == 'list' and args[3:]: | ||
| 118 | return do_wiki_add_to_list(bot, server, sender, target, args[3:]) | ||
| 119 | elif args[2] == 'table' and args[3:]: | ||
| 120 | return do_wiki_add_to_table(bot, server, sender, target, args[3:]) | ||
| 121 | elif args[2] == 'section' and args[3:]: | ||
| 122 | return do_wiki_add_to_section(bot, server, sender, target, args[3:]) | ||
| 123 | elif args[2] == 'page' and args[3:]: | ||
| 124 | return do_wiki_add_to_page(bot, server, sender, target, args[3:]) | ||
| 125 | else: | ||
| 126 | bot.respond(server, sender, target, "\x02%s\x02 is not a valid argument or not enough arguments." % args[2]) | ||
| 127 | return False | ||
| 128 | else: | ||
| 129 | bot.respond(server, sender, target, "\x02%s\x02 is not a valid argument or not enough arguments." % args[1]) | ||
| 130 | return False | ||
| 110 | 131 | else: | |
| 111 | 132 | bot.respond(server, sender, target, "\x02%s\x02 is not a valid argument or not enough arguments." % args[0]) | |
| 112 | 133 | return False | |
| … | … | ||
| 139 | 139 | # | |
| 140 | 140 | #### | |
| 141 | 141 | ||
| 142 | def do_wiki_add_table(bot, server, sender, target, args): | ||
| 143 | add_table_pat = re.compile(r'([\"\']?)(.*?)\1 in ([\"\']?)(.*?)\3 on ([\"\']?)(\S+)\5[:;] ([\"\']?)(.+)\7(\sat top|)') | ||
| 144 | args = ' '.join(args) | ||
| 145 | print args | ||
| 146 | m = add_table_pat.match(args) | ||
| 147 | if m: | ||
| 148 | print m.groups() | ||
| 149 | tablename = m.group(2) | ||
| 150 | sectionname = m.group(4) | ||
| 151 | pagename = m.group(6) | ||
| 152 | header_row = '"%s"' % m.group(8) | ||
| 153 | at_top = (len(m.group(9)) > 0) | ||
| 154 | print " + At top: %s %s" % (str(at_top), m.group(8)) | ||
| 155 | headers = [] | ||
| 156 | print " + Create table '%s' on '%s'." % (tablename, pagename) | ||
| 157 | for m in re.finditer(r'\s*"(.*?)"', header_row): | ||
| 158 | headers.append(m.group(1)) | ||
| 159 | if headers: | ||
| 160 | if mw_add_table(pagename, tablename, sectionname, headers, not at_top): | ||
| 161 | bot.respond(server, sender, target, "Successfully added table.") | ||
| 162 | else: | ||
| 163 | bot.respond(server, sender, target, "Could not add table to page.") | ||
| 164 | return True | ||
| 165 | else: | ||
| 166 | bot.respond(server, sender, target, "No headers specified.") | ||
| 167 | return False | ||
| 168 | else: | ||
| 169 | bot.respond(server, sender, target, "Could not parse arguments.") | ||
| 170 | return False | ||
| 171 | |||
| 172 | def do_wiki_add_to_table(bot, server, sender, target, args): | ||
| 173 | add_to_table_pat = re.compile(r'([\"\']?)(.*?)\1 on ([\"\']?)(\S+)\3[:;] (.+)(\sat top|)') | ||
| 174 | m = add_to_table_pat.match(' '.join(args)) | ||
| 175 | if m: | ||
| 176 | tablename = m.group(2) | ||
| 177 | pagename = m.group(4) | ||
| 178 | new_row = m.group(5) | ||
| 179 | at_top = len(m.group(6)) > 0 | ||
| 180 | row = [] | ||
| 181 | print " + To table '%s' on '%s'." % (tablename, pagename) | ||
| 182 | for m in re.finditer(r'\s*"(.*?)"', new_row): | ||
| 183 | row.append(m.group(1)) | ||
| 184 | if row: | ||
| 185 | print " + Add: \"%s\"" % '", "'.join(row) | ||
| 186 | if mw_add_to_table(pagename, tablename, [row], not at_top): | ||
| 187 | print " + Added row to table." | ||
| 188 | else: | ||
| 189 | print " - Failed to add row." | ||
| 190 | return True | ||
| 191 | else: | ||
| 192 | bot.respond(server, sender, target, "Nothing to add.") | ||
| 193 | return False | ||
| 194 | else: | ||
| 195 | bot.respond(server, sender, target, "Could not parse arguments.") | ||
| 196 | return False | ||
| 197 | |||
| 198 | def do_wiki_add_to_list(bot, server, sender, target, args): | ||
| 199 | add_to_list_pat = re.compile(r'([\"\']?)(.*?)\1 on ([\"\']?)(\S+)\3[:;] ([\"\']?)(.*?)\5(\sat top|)') | ||
| 200 | m = add_to_list_pat.match(' '.join(args)) | ||
| 201 | if m: | ||
| 202 | listname = m.group(2) | ||
| 203 | pagename = m.group(4) | ||
| 204 | new_item = m.group(6) | ||
| 205 | at_top = len(m.group(7)) > 0 | ||
| 206 | level = 1 | ||
| 207 | return mw_add_to_list(pagename, listname, new_item, level, not at_top) | ||
| 208 | else: | ||
| 209 | bot.respond(server, sender, target, "Could not parse arguments.") | ||
| 210 | return False | ||
| 211 | |||
| 212 | def do_wiki_add_to_page(bot, server, sender, target, args): | ||
| 213 | add_to_page_pat = re.compile(r'([\"\']?)(\S+)\1[:;] ([\"\']?)(.*?)\3(\sat top|)') | ||
| 214 | m = add_to_page_pat.match(' '.join(args)) | ||
| 215 | if m: | ||
| 216 | pagename = m.group(2) | ||
| 217 | text_to_add = m.group(4) | ||
| 218 | at_top = len(m.group(5)) > 0 | ||
| 219 | return mw_add_to_page(pagename, "", text_to_add, "Text added by bot.", not at_top) | ||
| 220 | else: | ||
| 221 | bot.respond(server, sender, target, "Could not parse arguments.") | ||
| 222 | return False | ||
| 223 | |||
| 224 | def do_wiki_add_to_section(bot, server, sender, target, args): | ||
| 225 | add_to_section_pat = re.compile(r'([\"\']?)(.*?)\1 on ([\"\']?)(\S+)\3[:;] ([\"\']?)(.*?)\5(\sat top|)') | ||
| 226 | m = add_to_section_pat.match(' '.join(args)) | ||
| 227 | if m: | ||
| 228 | sectionname = m.group(2) | ||
| 229 | pagename = m.group(4) | ||
| 230 | text_to_add = m.group(6) | ||
| 231 | at_top = len(m.group(7)) > 0 | ||
| 232 | return mw_add_to_page(pagename, sectionname, text_to_add, "Text added by bot.", not at_top) | ||
| 233 | else: | ||
| 234 | bot.respond(server, sender, target, "Could not parse arguments.") | ||
| 235 | return False | ||
| 236 | |||
| 237 | def do_wiki_add_section(bot, server, sender, target, args): | ||
| 238 | add_section_pat = re.compile(r'([\"\']?)(.*?)\1 (to|on) ([\"\']?)(\S+)\4(\sat top|)') | ||
| 239 | add_section_level_pat = re.compile(r'([\"\']?)(.*?)\1 level ([0-9]+) (to|on) ([\"\']?)(\S+)\5(\sat top|)') | ||
| 240 | add_section_parent_pat = re.compile(r'([\"\']?)(.*?)\1 below ([\"\']?)(.*?)\3 (to|on) ([\"\']?)(\S+)\6(\sat top|)') | ||
| 241 | m = add_section_parent_pat.match(' '.join(args)) | ||
| 242 | if m: | ||
| 243 | sectionname = m.group(2) | ||
| 244 | sectionlevel = 1 | ||
| 245 | sectionparent = m.group(4) | ||
| 246 | pagename = m.group(7) | ||
| 247 | at_top = (len(m.group(8)) > 0) | ||
| 248 | else: | ||
| 249 | m = add_section_level_pat.match(' '.join(args)) | ||
| 250 | if m: | ||
| 251 | sectionname = m.group(2) | ||
| 252 | try: | ||
| 253 | sectionlevel = int(m.group(3)) | ||
| 254 | except TypeError: | ||
| 255 | sectionlevel = 1 | ||
| 256 | sectionparent = "" | ||
| 257 | pagename = m.group(6) | ||
| 258 | at_top = (len(m.group(7)) > 0) | ||
| 259 | else: | ||
| 260 | m = add_section_pat.match(' '.join(args)) | ||
| 261 | if m: | ||
| 262 | sectionname = m.group(2) | ||
| 263 | sectionlevel = 1 | ||
| 264 | sectionparent = "" | ||
| 265 | pagename = m.group(5) | ||
| 266 | at_top = (len(m.group(6)) > 0) | ||
| 267 | print " + At top: %s" % at_top | ||
| 268 | else: | ||
| 269 | bot.respond(server, sender, target, "Could not parse arguments.") | ||
| 270 | return False | ||
| 271 | if sectionparent: | ||
| 272 | print " + Add section '%s' below %s on '%s'." % (sectionname, sectionparent, pagename) | ||
| 273 | else: | ||
| 274 | print " + Add section '%s' with level %d on '%s'." % (sectionname, sectionlevel, pagename) | ||
| 275 | success = mw_add_section(pagename, sectionname, sectionlevel, sectionparent, not at_top) | ||
| 276 | if success: | ||
| 277 | bot.respond(server, sender, target, "New section created on '%s'." % pagename) | ||
| 278 | else: | ||
| 279 | bot.respond(server, sender, target, "Could not create section.") | ||
| 280 | return True | ||
| 281 | |||
| 142 | 282 | def do_wiki_get_table(bot, server, sender, target, pagename, tablename): | |
| 143 | 283 | print "Get '%s' from '%s'." % (tablename, pagename) | |
| 144 | 284 | table = mw_get_table(pagename, tablename) | |
| … | … | ||
| 287 | 287 | table['title'] = mw_rewrite_wiki_links(table.get('title', "")) | |
| 288 | 288 | table['content'] = [[mw_rewrite_wiki_links(s) for s in r] for r in table.get('content', [])] | |
| 289 | 289 | table['headers'] = [mw_rewrite_wiki_links(s) for s in table.get('headers', [])] | |
| 290 | ret_list = ["\x02\x1F%s\x1F\x02" % (table.get('title', ''))] | ||
| 290 | ret_list = ['\x02\x1F%s\x1F\x02' % table.get('title', '')] | ||
| 291 | 291 | width = {} | |
| 292 | 292 | for i in xrange(len(table.get('headers', []))): | |
| 293 | 293 | width[i] = len(table['headers'][i]) | |
| … | … | ||
| 297 | 297 | #width = max([max([len(s) for s in r]) for r in table.get('content', [])]) | |
| 298 | 298 | headers = "" | |
| 299 | 299 | for i, header in zip(xrange(len(table.get('headers', []))), table.get('headers', [])): | |
| 300 | headers += " \x02{0:{1}}\x02 ".format(header.encode("latin-1"), width.get(i, 0)) | ||
| 300 | headers += " \x02{0:^{1}}\x02 ".format(header.encode("latin-1"), width.get(i, 0)) | ||
| 301 | 301 | ret_list.append(headers.decode("latin-1")) | |
| 302 | 302 | for row in table.get('content', []): | |
| 303 | 303 | new_row = "" | |
| … | … | ||
| 305 | 305 | new_row += " {0:{1}} ".format(item.encode("latin-1"), width.get(i, 0)) | |
| 306 | 306 | ret_list.append(new_row.decode("latin-1")) | |
| 307 | 307 | for s in ret_list: | |
| 308 | bot.respond(server, sender, target, bot.convert_to_irc_string(s.strip())) | ||
| 308 | bot.respond(server, sender, target, bot.convert_to_irc_string(s)) | ||
| 309 | 309 | bot.respond(server, sender, target, "End of table.") | |
| 310 | 310 | print " + Printed all rows to IRC." | |
| 311 | 311 | return True | |
| … | … | ||
| 329 | 329 | bot.respond(server, sender, target, "No list or empty list found.") | |
| 330 | 330 | return True | |
| 331 | 331 | ||
| 332 | def do_wiki_get_section(bot, server, sender, target, pagename, sectionname): | ||
| 333 | print "Get '%s' from '%s'." % (sectionname, pagename) | ||
| 334 | section = mw_get_section(pagename, sectionname) | ||
| 335 | if section: | ||
| 336 | print " + Got section." | ||
| 337 | bot.respond(server, sender, target, "Section \x02'%s\x02:" % sectionname) | ||
| 338 | for s in section.splitlines(): | ||
| 339 | s = ' '+mw_rewrite_wiki_links(s) | ||
| 340 | bot.respond(server, sender, target, bot.convert_to_irc_string(s)) | ||
| 341 | bot.respond(server, sender, target, "End of section.") | ||
| 342 | return True | ||
| 343 | else: | ||
| 344 | bot.respond(server, sender, target, "No section with that name.") | ||
| 345 | return True | ||
| 346 | |||
| 332 | 347 | ##### | |
| 333 | 348 | # Helper functions after this point | |
| 334 | 349 | ## | |
| … | … | ||
| 351 | 351 | exp_end_of_section = r'(\n\s*?=+\s*%s\s*=+\s*\n.*)(\n+\s*=+)' | |
| 352 | 352 | exp_start_of_section = r'(\n\s*?=+\s*%s\s*=+\s*)(\n.*?\n)' | |
| 353 | 353 | ||
| 354 | def mw_add_to_page(pagename, section, add_text, summary, at_end = True): | ||
| 355 | print "Add '%s' to page %s below '%s'." % (add_text, pagename, section) | ||
| 356 | if pagename and add_text: | ||
| 357 | page = wiki_site.Pages[pagename] | ||
| 358 | text = page.edit() | ||
| 359 | new_text, subcount = re.subn((exp_start_of_section, exp_end_of_section)[at_end] % section, r'\1\n%s\2' % add_text, text) | ||
| 360 | if subcount == 0: | ||
| 361 | print "Failed to substitute." | ||
| 354 | def mw_add_to_page(pagename, parentsection, text_to_add, summary, at_end): | ||
| 355 | print "Add text to '%s'." % text_to_add | ||
| 356 | page = wiki_site.Pages[pagename] | ||
| 357 | text = page.edit() | ||
| 358 | if parentsection: | ||
| 359 | ### Get the section, add the text and replace the old section with the new section. ### | ||
| 360 | section = mw_get_section(pagename, parentsection, text) | ||
| 361 | if section: | ||
| 362 | 362 | if at_end: | |
| 363 | new_text, subcount = re.subn(r'(\n+\s*=+)', r'\n%s\1' % add_text, text, 1) | ||
| 364 | if subcount > 0: | ||
| 365 | print "Before first title." | ||
| 366 | else: | ||
| 367 | if at_end: | ||
| 368 | new_text = text + "\n%s" % add_text | ||
| 369 | else: | ||
| 370 | new_text = "%s\n%s" % (add_text, text) | ||
| 371 | print "Added after text." | ||
| 363 | print " + Add text at end of section '%s'." % section | ||
| 364 | new_section = section+'\n'+text_to_add | ||
| 372 | 365 | else: | |
| 373 | new_text = "%s\n%s" % (add_text, text) | ||
| 374 | try: | ||
| 375 | page.save(new_text, summary=summary) | ||
| 376 | print " + Added text to %s." % pagename | ||
| 377 | return True | ||
| 378 | except Exception, e: | ||
| 379 | print " - Failed to save new wiki page: %s" % str(e) | ||
| 380 | return False | ||
| 366 | print " + Add text at start of section '%s'." % section | ||
| 367 | new_section = [] | ||
| 368 | added_lines = False | ||
| 369 | for line in section.splitlines(): | ||
| 370 | if not added_lines and line: | ||
| 371 | m = re.match(r'\s*(=+)(.*?)\1', line) | ||
| 372 | if not m: | ||
| 373 | print " + Add text." | ||
| 374 | new_section.append(text_to_add) | ||
| 375 | added_lines = True | ||
| 376 | else: | ||
| 377 | print " + Found a title: %s" % m.group(2) | ||
| 378 | new_section.append(line) | ||
| 379 | new_section = '\n'.join(new_section) | ||
| 380 | if new_section: | ||
| 381 | text = text.replace(section, new_section) | ||
| 382 | print " + Replace the old section with the new section." | ||
| 381 | 383 | else: | |
| 382 | print " - Not enough arguments." | ||
| 384 | if at_end: | ||
| 385 | print " + Add text to end of page." | ||
| 386 | new_text = text+'\n'+text_to_add | ||
| 387 | else: | ||
| 388 | print " + Add text before first header in text." | ||
| 389 | new_text = [] | ||
| 390 | added_lines = False | ||
| 391 | for line in text.splitlines(): | ||
| 392 | if not added_lines and line: | ||
| 393 | m = re.match(r'\s*(=+)(.*?)\1', line) | ||
| 394 | if m: | ||
| 395 | print " + Found a title: '%s'" % m.group(2) | ||
| 396 | new_text.append(text_to_add) | ||
| 397 | added_lines = True | ||
| 398 | new_text.append(line) | ||
| 399 | if not added_lines: | ||
| 400 | print " + Text has not been added so add at end of page." | ||
| 401 | new_text.append(text_to_add) | ||
| 402 | new_text = '\n'.join(new_text) | ||
| 403 | if new_text: | ||
| 404 | text = new_text | ||
| 405 | try: | ||
| 406 | page.save(text, summary=summary) | ||
| 407 | print " + Added text to '%s'." % pagename | ||
| 408 | return True | ||
| 409 | except Exception, e: | ||
| 410 | print " - Failed to save new wiki page: %s" % str(e) | ||
| 383 | 411 | return False | |
| 384 | 412 | ||
| 385 | def mw_add_section(pagename, section, parent = ""): | ||
| 413 | def mw_add_section(pagename, section, sectionlevel = 1, parent = "", to_bottom = True): | ||
| 386 | 414 | print "Add section '%s' to page '%s'." % (section, pagename) | |
| 387 | 415 | if pagename and section: | |
| 388 | 416 | if parent: | |
| … | … | ||
| 420 | 420 | if parent and not parent_level: | |
| 421 | 421 | print " - Failed to find parent level." | |
| 422 | 422 | return False | |
| 423 | section_level = parent_level + 1 | ||
| 424 | if mw_add_to_page(pagename, parent, "%s %s %s" % ('='*section_level, section, '='*section_level), "Section added by bot.", True): | ||
| 423 | section_level = max(parent_level + 1, sectionlevel) | ||
| 424 | if mw_add_to_page(pagename, parent, "%s %s %s" % ('='*section_level, section, '='*section_level), "Section added by bot.", to_bottom): | ||
| 425 | 425 | print " + Section added." | |
| 426 | 426 | return True | |
| 427 | 427 | else: | |
| … | … | ||
| 440 | 440 | if type(new_rows) is not list: | |
| 441 | 441 | new_rows = [new_rows] | |
| 442 | 442 | for row in new_rows: | |
| 443 | if type(row) is not tuple: | ||
| 444 | row = (row,) | ||
| 443 | if type(row) is not list: | ||
| 444 | row = [row] | ||
| 445 | 445 | rows += '| %s \n' % ' || '.join(row) | |
| 446 | 446 | rows = '\n|-\n'.join(rows.splitlines()) | |
| 447 | 447 | for table in re.finditer(r'\{\|.*?\|\}', text, re.S): | |
| … | … | ||
| 450 | 450 | print " + Has right name." | |
| 451 | 451 | else: | |
| 452 | 452 | print " - Not the right name." | |
| 453 | return False | ||
| 453 | continue | ||
| 454 | 454 | new_table = [] | |
| 455 | 455 | row_added = False | |
| 456 | 456 | has_header = False | |
| … | … | ||
| 490 | 490 | print " - Not enough arguments." | |
| 491 | 491 | return False | |
| 492 | 492 | ||
| 493 | def create_table(tablename, headers): | ||
| 494 | table = """\ | ||
| 495 | {| style="width:100%%" | ||
| 496 | |+ '''%s''' | ||
| 497 | ! %s | ||
| 498 | |- | ||
| 499 | |}""" % (tablename, ' || '.join(headers)) | ||
| 500 | return table | ||
| 501 | |||
| 502 | def mw_add_table(pagename, tablename, sectionname, headers, to_bottom): | ||
| 503 | table = create_table(tablename, headers) | ||
| 504 | print table | ||
| 505 | print " + At end: %s" % str(to_bottom) | ||
| 506 | return mw_add_to_page(pagename, sectionname, table, "Table '%s' added by bot." % tablename, to_bottom) | ||
| 507 | |||
| 493 | 508 | def mw_add_to_list(pagename, listname, new_points, level = 1, to_bottom = True): | |
| 494 | 509 | print "Add point to list '%s' on page '%s'." % (listname, pagename) | |
| 495 | 510 | if pagename and listname: | |
| … | … | ||
| 537 | 537 | inside_list = False | |
| 538 | 538 | print " + Add point to bottom of list." | |
| 539 | 539 | print " + Add: '%s'." % ', '.join(new_points) | |
| 540 | new_section.append(line) | ||
| 541 | 540 | new_section.extend([' '*indent+p for p in points]) | |
| 541 | new_section.append(line) | ||
| 542 | 542 | added_points = True | |
| 543 | 543 | else: | |
| 544 | 544 | new_section.append(line) | |
| … | … | ||
| 717 | 717 | text = text.replace(outer.group(0), ' '.join(matches[1:])) | |
| 718 | 718 | else: | |
| 719 | 719 | text = text.replace(outer.group(0), matches[0]) | |
| 720 | print outer.group(1) | ||
| 721 | 720 | return text |

