Exemplo n.º 1
0
  def store(self, name, filter):
    """Stores a new filter in the internal __filters dictionary."""
    self.__filters[name] = filter

  def tolerant(self):
    """Simple accessor for the tolerant flag."""
    return self.__tolerant


class Error(Exception):
  """A trivial local exception class."""
  pass


register = util.registrar(Filters.FILTERS)

@register("html")
def html_filter(text):
  return str(text) \
         .replace("&", "&") \
         .replace("<", "&lt;") \
         .replace(">", "&gt;") \
         .replace('"', "&quot;")


@register("html_para")
def html_paragraph(text):
  return ("<p>\n"
          + "\n</p>\n\n<p>\n".join(re.split(r"(?:\r?\n){2,}", str(text)))
          + "</p>\n")
Exemplo n.º 2
0
    It is expected that func be able to handle the type that it will
    be called upon.
    """
    try:
      self.OPS[type.lower()][name] = func
    except KeyError:
      raise Error("invalid vmethod type: %s\n" % type)


class Error(Exception):
  """A trivial local exception class."""
  pass


scalar_op = util.registrar(Stash.SCALAR_OPS)

list_op = util.registrar(Stash.LIST_OPS)

hash_op = util.registrar(Stash.HASH_OPS)


@scalar_op("item")
def scalar_item(scalar):
  return scalar


@scalar_op("list")
def scalar_list(scalar):
  return [scalar]
Exemplo n.º 3
0
  def store(self, name, filter):
    """Stores a new filter in the internal __filters dictionary."""
    self.__filters[name] = filter

  def tolerant(self):
    """Simple accessor for the tolerant flag."""
    return self.__tolerant


class Error(Exception):
  """A trivial local exception class."""
  pass


register = util.registrar(Filters.FILTERS)

@register("html")
def html_filter(text):
  return str(text) \
         .replace("&", "&amp;") \
         .replace("<", "&lt;") \
         .replace(">", "&gt;") \
         .replace('"', "&quot;")


@register("html_para")
def html_paragraph(text):
  return ("<p>\n"
          + "\n</p>\n\n<p>\n".join(re.split(r"(?:\r?\n){2,}", str(text)))
          + "</p>\n")
Exemplo n.º 4
0
    It is expected that func be able to handle the type that it will
    be called upon.
    """
        try:
            self.OPS[type.lower()][name] = func
        except KeyError:
            raise Error("invalid vmethod type: %s\n" % type)


class Error(Exception):
    """A trivial local exception class."""
    pass


scalar_op = util.registrar(Stash.SCALAR_OPS)

list_op = util.registrar(Stash.LIST_OPS)

hash_op = util.registrar(Stash.HASH_OPS)


@scalar_op("item")
def scalar_item(scalar):
    return scalar


@scalar_op("list")
def scalar_list(scalar):
    return [scalar]
Exemplo n.º 5
0
#  the terms under which this file may be distributed.
#

import re

from template.util import chop, is_seq, numify, registrar


class VMethods:
  ROOT = { }
  TEXT = { }
  HASH = { }
  LIST = { }


root_op = registrar(VMethods.ROOT)

scalar_op = registrar(VMethods.TEXT)

hash_op = registrar(VMethods.HASH)

list_op = registrar(VMethods.LIST)


@root_op("inc")
def root_inc(x):
  return x + 1


@root_op("dec")
def root_dec(x):
Exemplo n.º 6
0
#  the terms under which this file may be distributed.
#

import re

from template.util import chop, is_seq, numify, registrar


class VMethods:
  ROOT = { }
  TEXT = { }
  HASH = { }
  LIST = { }


root_op = registrar(VMethods.ROOT)

scalar_op = registrar(VMethods.TEXT)

hash_op = registrar(VMethods.HASH)

list_op = registrar(VMethods.LIST)


@root_op("inc")
def root_inc(x):
  return x + 1


@root_op("dec")
def root_dec(x):