Exemplo n.º 1
0
 def _shref_formatter(self, match, fullmatch):
     if self.parent_match is None:
         return super(EmbeddedLinkFormatter, self)._shref_formatter(
                 match, fullmatch)
     ns = fullmatch.group('sns')
     target = unquote_label(fullmatch.group('stgt'))
     label = (self.parent_match['label']
              if self.parent_match['label'] != self.parent_match['target']
              else target)
     return self._make_link(ns, target, match, label, fullmatch)
Exemplo n.º 2
0
 def _shref_formatter(self, match, fullmatch):
     if self.parent_match is None:
         return super(EmbeddedLinkFormatter,
                      self)._shref_formatter(match, fullmatch)
     ns = fullmatch.group('sns')
     target = unquote_label(fullmatch.group('stgt'))
     label = (self.parent_match['label']
              if self.parent_match['label'] != self.parent_match['target']
              else target)
     return self._make_link(ns, target, match, label, fullmatch)
Exemplo n.º 3
0
 def _lhref_formatter(self, match, fullmatch):
     if self.parent_match is None:
         return super(EmbeddedLinkFormatter, self)._lhref_formatter(
                 match, fullmatch)
     rel = fullmatch.group('rel')
     ns = fullmatch.group('lns')
     target = unquote_label(fullmatch.group('ltgt'))
     label = (self.parent_match['label']
              if self.parent_match['label'] != self.parent_match['target']
              else fullmatch.group('label'))
     return self._make_lhref_link(match, fullmatch, rel, ns, target, label)
Exemplo n.º 4
0
 def _lhref_formatter(self, match, fullmatch):
     if self.parent_match is None:
         return super(EmbeddedLinkFormatter,
                      self)._lhref_formatter(match, fullmatch)
     rel = fullmatch.group('rel')
     ns = fullmatch.group('lns')
     target = unquote_label(fullmatch.group('ltgt'))
     label = (self.parent_match['label']
              if self.parent_match['label'] != self.parent_match['target']
              else fullmatch.group('label'))
     return self._make_lhref_link(match, fullmatch, rel, ns, target, label)
Exemplo n.º 5
0
 def _format_link(self,
                  formatter,
                  ns,
                  pagename,
                  label,
                  ignore_missing,
                  original_label=None):
     pagename, query, fragment = formatter.split_link(pagename)
     version = None
     if '@' in pagename:
         pagename, version = pagename.split('@', 1)
     if version and query:
         query = '&' + query[1:]
     pagename = pagename.rstrip('/') or self.START_PAGE
     referrer = ''
     if formatter.resource and formatter.resource.realm == self.realm:
         referrer = formatter.resource.id
     if pagename.startswith('/'):
         pagename = pagename.lstrip('/')
     elif pagename.startswith(('./', '../')) or pagename in ('.', '..'):
         pagename = self._resolve_relative_name(pagename, referrer)
     else:
         pagename = self._resolve_scoped_name(pagename, referrer)
     label = unquote_label(label)
     if 'WIKI_VIEW' in formatter.perm(self.realm, pagename, version):
         href = formatter.href.wiki(pagename, version=version) + query \
                + fragment
         if self.has_page(pagename):
             return tag.a(label, href=href, class_='wiki')
         else:
             if ignore_missing:
                 return original_label or label
             if 'WIKI_CREATE' in \
                     formatter.perm(self.realm, pagename, version):
                 return tag.a(label,
                              class_='missing wiki',
                              href=href,
                              rel='nofollow')
             else:
                 return tag.a(label, class_='missing wiki')
     elif ignore_missing and not self.has_page(pagename):
         return original_label or label
     else:
         return tag.a(label,
                      class_='forbidden wiki',
                      title=_("no permission to view this wiki page"))
Exemplo n.º 6
0
 def get_wiki_syntax(self):
     yield (r'(?<!\S)!?(?P<pid>%s)%s(?P<ptarget>%s:(?:%s)|%s|%s(?:%s*%s)?)' %
                 (IDENTIFIER,
                  PRODUCT_SYNTAX_DELIMITER_RE,
                  WikiParser.LINK_SCHEME, WikiParser.QUOTED_STRING,
                  WikiParser.QUOTED_STRING, WikiParser.SHREF_TARGET_FIRST,
                  WikiParser.SHREF_TARGET_MIDDLE, WikiParser.SHREF_TARGET_LAST),
            lambda f, m, fm :
                 self._format_link(f, 'product',
                                   '%s:%s' % (fm.group('pid'),
                                              unquote_label(fm.group('ptarget'))),
                                   fm.group(0), fm))
     if self.env[ProductTicketModule] is not None:
         yield (r"(?<!\S)!?(?P<jtp>%s)-(?P<jtt>\d+)(?P<jtf>[?#]\S+)?" %
                     (IDENTIFIER,),
                lambda f, m, fm :
                     self._format_link(f, 'product',
                                       '%s:ticket:%s' %
                                             (fm.group('jtp'),
                                              fm.group('jtt') +
                                              (fm.group('jtf') or '')),
                                       m, fm))
Exemplo n.º 7
0
 def get_wiki_syntax(self):
     yield (r'(?<!\S)!?(?P<pid>%s)%s(?P<ptarget>%s:(?:%s)|%s|%s(?:%s*%s)?)' %
                 (IDENTIFIER,
                  PRODUCT_SYNTAX_DELIMITER_RE,
                  WikiParser.LINK_SCHEME, WikiParser.QUOTED_STRING,
                  WikiParser.QUOTED_STRING, WikiParser.SHREF_TARGET_FIRST,
                  WikiParser.SHREF_TARGET_MIDDLE, WikiParser.SHREF_TARGET_LAST),
            lambda f, m, fm :
                 self._format_link(f, 'product',
                                   '%s:%s' % (fm.group('pid'),
                                              unquote_label(fm.group('ptarget'))),
                                   fm.group(0), fm))
     if self.env[ProductTicketModule] is not None:
         yield (r"(?<!\S)!?(?P<jtp>%s)-(?P<jtt>\d+)(?P<jtf>[?#]\S+)?" %
                     (IDENTIFIER,),
                lambda f, m, fm :
                     self._format_link(f, 'product',
                                       '%s:ticket:%s' %
                                             (fm.group('jtp'),
                                              fm.group('jtt') +
                                              (fm.group('jtf') or '')),
                                       m, fm))
Exemplo n.º 8
0
Arquivo: api.py Projeto: pkdevbox/trac
 def _format_link(self, formatter, ns, pagename, label, ignore_missing,
                  original_label=None):
     pagename, query, fragment = formatter.split_link(pagename)
     version = None
     if '@' in pagename:
         pagename, version = pagename.split('@', 1)
     if version and query:
         query = '&' + query[1:]
     pagename = pagename.rstrip('/') or 'WikiStart'
     referrer = ''
     if formatter.resource and formatter.resource.realm == self.realm:
         referrer = formatter.resource.id
     if pagename.startswith('/'):
         pagename = pagename.lstrip('/')
     elif pagename.startswith(('./', '../')) or pagename in ('.', '..'):
         pagename = self._resolve_relative_name(pagename, referrer)
     else:
         pagename = self._resolve_scoped_name(pagename, referrer)
     label = unquote_label(label)
     if 'WIKI_VIEW' in formatter.perm(self.realm, pagename, version):
         href = formatter.href.wiki(pagename, version=version) + query \
                + fragment
         if self.has_page(pagename):
             return tag.a(label, href=href, class_='wiki')
         else:
             if ignore_missing:
                 return original_label or label
             if 'WIKI_CREATE' in \
                     formatter.perm(self.realm, pagename, version):
                 return tag.a(label + '?', class_='missing wiki',
                              href=href, rel='nofollow')
             else:
                 return tag.a(label + '?', class_='missing wiki')
     elif ignore_missing and not self.has_page(pagename):
         return original_label or label
     else:
         return tag.a(label, class_='forbidden wiki',
                      title=_("no permission to view this wiki page"))