old_contents: # -*- coding: utf-8 -*-
  
  import re
  from bz2 import compress, decompress
  from base64 import b64encode, b64decode
  
  from trac.core import *
  from trac.util.html import html
  from trac.web import IRequestHandler
  from trac.wiki import IWikiMacroProvider
  from trac.wiki.formatter import system_message
  
  from . import diag
  from .cache import memoize
  
  _descriptions = {
      'blockdiag': 'description',
      'seqdiag': 'description',
      'actdiag': 'description',
      'nwdiag': 'description',
      'rackdiag': 'description'
  }
  
  macro_defs = {}
  for name in diag.loader.available_builders():
      macro_defs[name] = _descriptions[name]
  
  content_types = {'png': 'image/png',
                   'svg': 'image/svg+xml'}
  _conf_section = 'tracblockdiag'
  
  
  class BlockdiagRenderer(Component):
      implements(IWikiMacroProvider, IRequestHandler)
  
      def __init__(self):
          self.font = self.config.getlist(_conf_section, 'font')
          cachetime = self.config.getint(_conf_section, 'cachetime', 300)
          gc_interval = self.config.getint(_conf_section, 'gc_interval', 100)
          self.url = re.compile(r'/blockdiag/([a-z]+)/(png|svg)/(.+)')
          self.src = 'blockdiag/%(type)s/%(fmt)s/%(data)s'
          self.get_diag = memoize(cachetime, gc_interval)(diag.get_diag)
  
      def get_macros(self):
          return macro_defs.keys()
  
      def get_macro_description(self, name):
          return macro_defs.get(name, '')
  
      def expand_macro(self, formatter, name, content, args=None):
          args = args or {}
          params = {'type': name[:-4], 'data': b64encode(compress(content)),
                    'fmt': args.pop('type', 'png')}
          args['src'] = formatter.req.href(self.src % params)
          return html.img(**args)
  
      def match_request(self, req):
          return bool(self.url.match(req.path_info))
  
      def process_request(self, req):
          type_, fmt, data = self.url.match(req.path_info).groups()
          text = decompress(b64decode(data))
          diag = self.get_diag(type_, text, fmt, self.font)
          req.send(diag, content_types.get(fmt.lower(), ''), status=200)
  
new_contents: # -*- coding: utf-8 -*-
  
  import re
  from bz2 import compress, decompress
  from base64 import b64encode, b64decode
  
  from trac.core import *
  from trac.util.html import html
  from trac.web import IRequestHandler
  from trac.wiki import IWikiMacroProvider
  from trac.wiki.formatter import system_message
  
  from . import diag
  from .cache import memoize
  
  _template = u"""
  = What's this? =
  Generate %(kind)s diagram from source text.
  
  See [http://blockdiag.com/en/%(module)s/ %(module)s (en)] or
  [http://blockdiag.com/ja/%(module)s/ for Japanese]
  
  == Arguments (Only Trac 0.12 or later) ==
   `type`:: Image format (png or svg)
   `others`:: Used to IMG tag attributes
  """
  
  _descriptions = {
      'blockdiag': {'kind': 'block', 'module': 'blockdiag'},
      'seqdiag': {'kind': 'sequence', 'module': 'seqdiag'},
      'actdiag': {'kind': 'activity', 'module': 'actdiag'},
      'nwdiag': {'kind': 'network', 'module': 'nwdiag'},
      'rackdiag': {'kind': 'rack', 'module': 'nwdiag'}
  }
  
  macro_defs = {}
  for name in diag.loader.available_builders():
      macro_defs[name] = _template % _descriptions[name]
  
  content_types = {'png': 'image/png',
                   'svg': 'image/svg+xml'}
  _conf_section = 'tracblockdiag'
  
  
  class BlockdiagRenderer(Component):
      implements(IWikiMacroProvider, IRequestHandler)
  
      def __init__(self):
          self.font = self.config.getlist(_conf_section, 'font')
          cachetime = self.config.getint(_conf_section, 'cachetime', 300)
          gc_interval = self.config.getint(_conf_section, 'gc_interval', 100)
          self.url = re.compile(r'/blockdiag/([a-z]+)/(png|svg)/(.+)')
          self.src = 'blockdiag/%(type)s/%(fmt)s/%(data)s'
          self.get_diag = memoize(cachetime, gc_interval)(diag.get_diag)
  
      def get_macros(self):
          return macro_defs.keys()
  
      def get_macro_description(self, name):
          return macro_defs.get(name, '')
  
      def expand_macro(self, formatter, name, content, args=None):
          args = args or {}
          params = {'type': name[:-4], 'data': b64encode(compress(content)),
                    'fmt': args.pop('type', 'png')}
          args['src'] = formatter.req.href(self.src % params)
          return html.img(**args)
  
      def match_request(self, req):
          return bool(self.url.match(req.path_info))
  
      def process_request(self, req):
          type_, fmt, data = self.url.match(req.path_info).groups()
          text = decompress(b64decode(data))
          diag = self.get_diag(type_, text, fmt, self.font)
          req.send(diag, content_types.get(fmt.lower(), ''), status=200)
  
subject: fix macro description