コード例 #1
0
def Split(param, delimiter):
    if param:
        if not is_seq(param):
            param = str(param).split(delimiter)
        return param
    else:
        return []
コード例 #2
0
  def insert(self, files):
    """Insert the contents of a file without parsing."""
    # TODO: Clean this up; unify the way "files" is passed to this routine.
    files = unscalar(files)
    if is_seq(files):
      files = unscalar_list(files)
    else:
      files = [unscalar(files)]
    prefix = providers = text = None
    output = cStringIO.StringIO()

    for file in files:
      prefix, name = split_prefix(file)
      if prefix:
        providers = self.__prefix_map.get(prefix)
        if not providers:
          self.throw(ERROR_FILE, "no providers for file prefix '%s'" % prefix)
      else:
        providers = self.__prefix_map.get("default") or self.__load_templates

      for provider in providers:
        try:
          text = provider.load(name, prefix)
        except Exception, e:
          self.throw(ERROR_FILE, str(e))
        if text is not None:
          output.write(text)
          break
      else:
        self.throw(ERROR_FILE, "%s: not found" % file)
コード例 #3
0
def list_splice(seq, start=0, length=None, *replace):
  start = util.numify(start)
  if start < 0:
    start = len(seq) + start
  if length is not None:
    stop = start + length
  else:
    stop = len(seq)
  if len(replace) == 1 and util.is_seq(replace[0]):
    replace = replace[0]
  s = slice(start, stop)
  removed = seq[s]
  seq[s] = replace
  return removed
コード例 #4
0
def list_splice(seq, start=0, length=None, *replace):
    start = util.numify(start)
    if start < 0:
        start = len(seq) + start
    if length is not None:
        stop = start + length
    else:
        stop = len(seq)
    if len(replace) == 1 and util.is_seq(replace[0]):
        replace = replace[0]
    s = slice(start, stop)
    removed = seq[s]
    seq[s] = replace
    return removed
コード例 #5
0
  def getref(self, ident, args=None):
    """Returns a "reference" to a particular item.

    This is represented as a function which will return the actual
    stash item when called.  WARNING: still experimental!
    """
    root = self
    if util.is_seq(ident):
      chopped = list(util.chop(ident, 2))
      for i, (item, args) in enumerate(chopped):
        if i == len(chopped) - 1:
          break
        root = self.__dotop(root, item, args)
        if root is None:
          break
    else:
      item = ident
    if root is not None:
      return lambda *x: self.__dotop(root, item, tuple(args or ()) + x)
    else:
      return lambda *x: ""
コード例 #6
0
    def getref(self, ident, args=None):
        """Returns a "reference" to a particular item.

    This is represented as a function which will return the actual
    stash item when called.  WARNING: still experimental!
    """
        root = self
        if util.is_seq(ident):
            chopped = list(util.chop(ident, 2))
            for i, (item, args) in enumerate(chopped):
                if i == len(chopped) - 1:
                    break
                root = self.__dotop(root, item, args)
                if root is None:
                    break
        else:
            item = ident
        if root is not None:
            return lambda *x: self.__dotop(root, item, tuple(args or ()) + x)
        else:
            return lambda *x: ""
コード例 #7
0
def Args(key, val):
    key = escape(key)
    if not util.is_seq(val):
        val = [val]
    return ["%s=%s" % (key, escape(v)) for v in val]
コード例 #8
0
ファイル: url.py プロジェクト: vaMuchenje/Template-Python
def Args(key, val):
    key = escape(key)
    if not util.is_seq(val):
        val = [val]
    return ["%s=%s" % (key, escape(v)) for v in val]