Show More
@@ -6,7 +6,7 b'' | |||||
6 | # This software may be used and distributed according to the terms of the |
|
6 | # This software may be used and distributed according to the terms of the | |
7 | # GNU General Public License version 2 or any later version. |
|
7 | # GNU General Public License version 2 or any later version. | |
8 |
|
8 | |||
9 |
import os |
|
9 | import os | |
10 | from mercurial import ui, hg, hook, error, encoding, templater, util, repoview |
|
10 | from mercurial import ui, hg, hook, error, encoding, templater, util, repoview | |
11 | from mercurial.templatefilters import websub |
|
11 | from mercurial.templatefilters import websub | |
12 | from mercurial.i18n import _ |
|
12 | from mercurial.i18n import _ | |
@@ -60,7 +60,6 b" def makebreadcrumb(url, prefix=''):" | |||||
60 | urlel = os.path.dirname(urlel) |
|
60 | urlel = os.path.dirname(urlel) | |
61 | return reversed(breadcrumb) |
|
61 | return reversed(breadcrumb) | |
62 |
|
62 | |||
63 |
|
||||
64 | class requestcontext(object): |
|
63 | class requestcontext(object): | |
65 | """Holds state/context for an individual request. |
|
64 | """Holds state/context for an individual request. | |
66 |
|
65 | |||
@@ -163,7 +162,7 b' class hgweb(object):' | |||||
163 | # web.templates in .hg/hgrc to get access to any file readable |
|
162 | # web.templates in .hg/hgrc to get access to any file readable | |
164 | # by the user running the CGI script |
|
163 | # by the user running the CGI script | |
165 | self.templatepath = self.config('web', 'templates', untrusted=False) |
|
164 | self.templatepath = self.config('web', 'templates', untrusted=False) | |
166 |
self.websubtable = |
|
165 | self.websubtable = webutil.getwebsubs(r) | |
167 |
|
166 | |||
168 | # The CGI scripts are often run by a user different from the repo owner. |
|
167 | # The CGI scripts are often run by a user different from the repo owner. | |
169 | # Trust the settings from the .hg/hgrc files by default. |
|
168 | # Trust the settings from the .hg/hgrc files by default. | |
@@ -369,47 +368,6 b' class hgweb(object):' | |||||
369 | return [''] |
|
368 | return [''] | |
370 | return tmpl('error', error=inst.message) |
|
369 | return tmpl('error', error=inst.message) | |
371 |
|
370 | |||
372 | def loadwebsub(self): |
|
|||
373 | websubtable = [] |
|
|||
374 | websubdefs = self.repo.ui.configitems('websub') |
|
|||
375 | # we must maintain interhg backwards compatibility |
|
|||
376 | websubdefs += self.repo.ui.configitems('interhg') |
|
|||
377 | for key, pattern in websubdefs: |
|
|||
378 | # grab the delimiter from the character after the "s" |
|
|||
379 | unesc = pattern[1] |
|
|||
380 | delim = re.escape(unesc) |
|
|||
381 |
|
||||
382 | # identify portions of the pattern, taking care to avoid escaped |
|
|||
383 | # delimiters. the replace format and flags are optional, but |
|
|||
384 | # delimiters are required. |
|
|||
385 | match = re.match( |
|
|||
386 | r'^s%s(.+)(?:(?<=\\\\)|(?<!\\))%s(.*)%s([ilmsux])*$' |
|
|||
387 | % (delim, delim, delim), pattern) |
|
|||
388 | if not match: |
|
|||
389 | self.repo.ui.warn(_("websub: invalid pattern for %s: %s\n") |
|
|||
390 | % (key, pattern)) |
|
|||
391 | continue |
|
|||
392 |
|
||||
393 | # we need to unescape the delimiter for regexp and format |
|
|||
394 | delim_re = re.compile(r'(?<!\\)\\%s' % delim) |
|
|||
395 | regexp = delim_re.sub(unesc, match.group(1)) |
|
|||
396 | format = delim_re.sub(unesc, match.group(2)) |
|
|||
397 |
|
||||
398 | # the pattern allows for 6 regexp flags, so set them if necessary |
|
|||
399 | flagin = match.group(3) |
|
|||
400 | flags = 0 |
|
|||
401 | if flagin: |
|
|||
402 | for flag in flagin.upper(): |
|
|||
403 | flags |= re.__dict__[flag] |
|
|||
404 |
|
||||
405 | try: |
|
|||
406 | regexp = re.compile(regexp, flags) |
|
|||
407 | websubtable.append((regexp, format)) |
|
|||
408 | except re.error: |
|
|||
409 | self.repo.ui.warn(_("websub: invalid regexp for %s: %s\n") |
|
|||
410 | % (key, regexp)) |
|
|||
411 | return websubtable |
|
|||
412 |
|
||||
413 | def templater(self, req): |
|
371 | def templater(self, req): | |
414 |
|
372 | |||
415 | # determine scheme, port and server name |
|
373 | # determine scheme, port and server name |
@@ -7,6 +7,7 b'' | |||||
7 | # GNU General Public License version 2 or any later version. |
|
7 | # GNU General Public License version 2 or any later version. | |
8 |
|
8 | |||
9 | import os, copy |
|
9 | import os, copy | |
|
10 | import re | |||
10 | from mercurial import match, patch, error, ui, util, pathutil, context |
|
11 | from mercurial import match, patch, error, ui, util, pathutil, context | |
11 | from mercurial.i18n import _ |
|
12 | from mercurial.i18n import _ | |
12 | from mercurial.node import hex, nullid, short |
|
13 | from mercurial.node import hex, nullid, short | |
@@ -540,3 +541,44 b' class wsgiui(ui.ui):' | |||||
540 | # default termwidth breaks under mod_wsgi |
|
541 | # default termwidth breaks under mod_wsgi | |
541 | def termwidth(self): |
|
542 | def termwidth(self): | |
542 | return 80 |
|
543 | return 80 | |
|
544 | ||||
|
545 | def getwebsubs(repo): | |||
|
546 | websubtable = [] | |||
|
547 | websubdefs = repo.ui.configitems('websub') | |||
|
548 | # we must maintain interhg backwards compatibility | |||
|
549 | websubdefs += repo.ui.configitems('interhg') | |||
|
550 | for key, pattern in websubdefs: | |||
|
551 | # grab the delimiter from the character after the "s" | |||
|
552 | unesc = pattern[1] | |||
|
553 | delim = re.escape(unesc) | |||
|
554 | ||||
|
555 | # identify portions of the pattern, taking care to avoid escaped | |||
|
556 | # delimiters. the replace format and flags are optional, but | |||
|
557 | # delimiters are required. | |||
|
558 | match = re.match( | |||
|
559 | r'^s%s(.+)(?:(?<=\\\\)|(?<!\\))%s(.*)%s([ilmsux])*$' | |||
|
560 | % (delim, delim, delim), pattern) | |||
|
561 | if not match: | |||
|
562 | repo.ui.warn(_("websub: invalid pattern for %s: %s\n") | |||
|
563 | % (key, pattern)) | |||
|
564 | continue | |||
|
565 | ||||
|
566 | # we need to unescape the delimiter for regexp and format | |||
|
567 | delim_re = re.compile(r'(?<!\\)\\%s' % delim) | |||
|
568 | regexp = delim_re.sub(unesc, match.group(1)) | |||
|
569 | format = delim_re.sub(unesc, match.group(2)) | |||
|
570 | ||||
|
571 | # the pattern allows for 6 regexp flags, so set them if necessary | |||
|
572 | flagin = match.group(3) | |||
|
573 | flags = 0 | |||
|
574 | if flagin: | |||
|
575 | for flag in flagin.upper(): | |||
|
576 | flags |= re.__dict__[flag] | |||
|
577 | ||||
|
578 | try: | |||
|
579 | regexp = re.compile(regexp, flags) | |||
|
580 | websubtable.append((regexp, format)) | |||
|
581 | except re.error: | |||
|
582 | repo.ui.warn(_("websub: invalid regexp for %s: %s\n") | |||
|
583 | % (key, regexp)) | |||
|
584 | return websubtable |
General Comments 0
You need to be logged in to leave comments.
Login now