Modify

Opened 4 years ago

Closed 4 years ago

#6890 closed defect (fixed)

support for trac 0.10?

Reported by: abeld@… Owned by: Amfortas
Priority: normal Component: TracBibPlugin
Severity: normal Keywords:
Cc: Trac Release: 0.11

Description

Is TracBibPlugin compatible with trac 0.10? It appears as such on the trac-hacks.org opening page (i.e. it has the 0.10 tag), but compatibility is not mentioned on the TracBibPlugin page, and the 0.10 svn branch is empty.

So, is 0.10 supported?

Attachments (0)

Change History (3)

comment:1 Changed 4 years ago by Amfortas

  • Status changed from new to assigned

I never tried it.
When i did so today, it turned out that trac 0.10 does not know "parse_args", so a little bit of rewriting would be needed. I will have a look at it the next days.

So currently no support for 0.10.

comment:2 Changed 4 years ago by abeld@…

This diff apparently makes it work with trac 0.10:
(apart from parse_args, the api of WikiMacroBase also changed, also, genshi is new in 0.11)

$ svn diff tracbib/tracbib.py
Index: tracbib/tracbib.py
===================================================================
--- tracbib/tracbib.py	(revision 365)
+++ tracbib/tracbib.py	(working copy)
@@ -1,9 +1,57 @@
 from trac.core import *
-from trac.wiki.api import IWikiMacroProvider, parse_args
+from trac.wiki.api import IWikiMacroProvider
+try:
+  from trac.wiki.api import parse_args
+except ImportError: # for trac 0.10:
+  import re
+  # following is from
+  # http://trac.edgewall.org/browser/trunk/trac/wiki/api.py
+  def parse_args(args, strict=True):
+      """Utility for parsing macro "content" and splitting them into arguments.
+
+      The content is split along commas, unless they are escaped with a
+      backquote (like this: \,).
+
+      :param args: macros arguments, as plain text
+      :param strict: if `True`, only Python-like identifiers will be
+                     recognized as keyword arguments
+
+      Example usage:
+
+      >>> parse_args('')
+      ([], {})
+      >>> parse_args('Some text')
+      (['Some text'], {})
+      >>> parse_args('Some text, mode= 3, some other arg\, with a comma.')
+      (['Some text', ' some other arg, with a comma.'], {'mode': ' 3'})
+      >>> parse_args('milestone=milestone1,status!=closed', strict=False)
+      ([], {'status!': 'closed', 'milestone': 'milestone1'})
+
+      """   
+      largs, kwargs = [], {}
+      if args:
+          for arg in re.split(r'(?<!\\),', args):
+              arg = arg.replace(r'\,', ',')
+              if strict:
+                  m = re.match(r'\s*[a-zA-Z_]\w+=', arg)
+              else:
+                  m = re.match(r'\s*[^=]+=', arg)
+              if m:
+                  kw = arg[:m.end()-1].strip()
+                  if strict:
+                      kw = unicode(kw).encode('utf-8')
+                  kwargs[kw] = arg[m.end():]
+              else:
+                  largs.append(arg)
+      return largs, kwargs
+
 from trac.wiki.macros import WikiMacroBase
 from trac.attachment import Attachment
 from trac.env import Environment
-from genshi.builder import tag
+try:
+  from genshi.builder import tag
+except ImportError: # for trac 0.10:
+  from trac.util.html import html as tag
 from trac.wiki.model import WikiPage
 from trac.wiki.formatter import WikiProcessor
 from trac.util.text import to_unicode
@@ -68,6 +116,9 @@
 class BibAddMacro(WikiMacroBase):
   implements(IWikiMacroProvider)
 
+  def render_macro(self, request,name,content):
+    return self.expand_macro(request,name,content)
+
   def expand_macro(self,formatter,name,content):
     args, kwargs = parse_args(content, strict=False)
     if len(args) != 1:
@@ -148,6 +199,9 @@
 
 class BibCiteMacro(WikiMacroBase):
   implements(IWikiMacroProvider)
+
+  def render_macro(self, request,name,content):
+    return self.expand_macro(request,name,content)
   
   def expand_macro(self,formatter,name,content):
 
@@ -174,6 +228,9 @@
 class BibNoCiteMacro(WikiMacroBase):
   implements(IWikiMacroProvider)
   
+  def render_macro(self, request,name,content):
+    return self.expand_macro(request,name,content)
+
   def expand_macro(self,formatter,name,content):
 
     args, kwargs = parse_args(content, strict=False)
@@ -198,6 +255,9 @@
 class BibRefMacro(WikiMacroBase):
   implements(IWikiMacroProvider)
 
+  def render_macro(self, request,name,content):
+    return self.expand_macro(request,name,content)
+
   def expand_macro(self,formatter,name,content):
     citelist = getattr(formatter, CITELIST,[])
     bibdb = getattr(formatter, BIBDB,{})

comment:3 Changed 4 years ago by Amfortas

  • Resolution set to fixed
  • Status changed from assigned to closed

Thank you for sharing your patch. It's in the repository now..

Add Comment

Modify Ticket

Action
as closed .
as The resolution will be set. Next status will be 'closed'.
to The owner will be changed from Amfortas. Next status will be 'closed'.
The resolution will be deleted. Next status will be 'reopened'.
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.