Esempio n. 1
0
    def __init__(self, context, filename, params=None):
        Plugin.__init__(self)
        params = params or {}
        delim = params.get("delim") or ":"
        items = []
        line = None
        names = None
        splitter = re.compile(r'\s*%s\s*' % re.escape(delim))

        try:
            f = open(filename)
        except IOError as e:
            return self.fail("%s: %s" % (filename, e))

        for line in f:
            line = line.rstrip("\n\r")
            if not line or line.startswith("#") or line.isspace():
                continue
            fields = splitter.split(line)
            if names is None:
                names = fields
            else:
                fields.extend([None] * (len(names) - len(fields)))
                items.append(dict(zip(names, fields)))

        f.close()
        self.items = items
  def __init__(self, context, filename, params=None):
    Plugin.__init__(self)
    params = params or {}
    delim = params.get("delim") or ":"
    items = []
    line = None
    names = None
    splitter = re.compile(r'\s*%s\s*' % re.escape(delim))

    try:
      f = open(filename)
    except IOError, e:
      return self.fail("%s: %s" % (filename, e))
Esempio n. 3
0
    def __init__(self, context, filename, params=None):
        Plugin.__init__(self)
        params = params or {}
        delim = params.get("delim") or ":"
        items = []
        line = None
        names = None
        splitter = re.compile(r'\s*%s\s*' % re.escape(delim))

        try:
            f = open(filename)
        except IOError, e:
            return self.fail("%s: %s" % (filename, e))
Esempio n. 4
0
 def __init__(self, context, *args):
     Plugin.__init__(self)
     args, config = self._split_arguments(args)
     if "text" in config:
         self._text = config["text"]
     elif args:
         self._text = args[0]
     else:
         self._text = ""
     self.filters = []
     self._CONTEXT = context
     filter = config.get("filter") or config.get("filters")
     if filter:
         self.output_filter(filter)
 def __init__(self, context, *args):
   Plugin.__init__(self)
   args, config = self._split_arguments(args)
   if "text" in config:
     self._text = config["text"]
   elif args:
     self._text = args[0]
   else:
     self._text = ""
   self.filters = []
   self._CONTEXT = context
   filter = config.get("filter") or config.get("filters")
   if filter:
     self.output_filter(filter)
Esempio n. 6
0
 def __init__(self, context, name=None, config=None):
   if isinstance(name, dict):
     name, config = None, name
   Plugin.__init__(self)
   if not isinstance(config, dict):
     config = {}
   if name is None:
     name = config.get("name")
   if not name:
     return self.throw("no image file specfied")
   root = config.get("root")
   if root:
     file = os.path.join(root, name)
   else:
     file = config.get("file") or name
   self.__name = name
   self.__file = file
   self.__root = root
   self.__size = None
   self.__width = None
   self.__height = None
   self.__alt = config.get("alt", "")
Esempio n. 7
0
 def __init__(self, context, name=None, config=None):
     if isinstance(name, dict):
         name, config = None, name
     Plugin.__init__(self)
     if not isinstance(config, dict):
         config = {}
     if name is None:
         name = config.get("name")
     if not name:
         return self.throw("no image file specfied")
     root = config.get("root")
     if root:
         file = os.path.join(root, name)
     else:
         file = config.get("file") or name
     self.__name = name
     self.__file = file
     self.__root = root
     self.__size = None
     self.__width = None
     self.__height = None
     self.__alt = config.get("alt", "")
Esempio n. 8
0
 def __init__(self, context, config=None):
     Plugin.__init__(self)
     self.__config = config  # unused
Esempio n. 9
0
    def __init__(self, context, data, params=None):
        """Initialises the object to iterate through the data set passed
    by list as the first parameter.

    It calculates the shape of the permutation table based on the ROWS
    or COLS parameters specified in the params dictionary.  The
    OVERLAP parameter may be provided to specify the number of common
    items that should be shared between subseqent columns.
    """
        Plugin.__init__(self)
        if isinstance(data, Iterator):
            data, error = data.get_all()
            if error:
                raise Error("iterator failed to provide data for table: %s" %
                            error)
        if not isinstance(data, (tuple, list)):
            raise Error("invalid table data, expecting a list")

        if params is None:
            params = {}
        if not isinstance(params, dict):
            raise Error("invalid table parameters, expecting a dict")

        # ensure keys are folded to upper case
        params.update(
            dict((str(key).upper(), value)
                 for key, value in params.iteritems()))

        size = len(data)
        overlap = params.get("OVERLAP", 0)

        rows = params.get("ROWS")
        cols = params.get("COLS")
        if rows:
            if size < rows:
                rows = size
                cols = 1
                coloff = 0
            else:
                coloff = rows - overlap
                cols = size / coloff + int(size % coloff > overlap)
        elif cols:
            if size < cols:
                cols = size
                rows = 1
                coloff = 1
            else:
                coloff = size / cols + int(size % cols > overlap)
                rows = coloff + overlap
        else:
            rows = size
            cols = 1
            coloff = 0

        self._DATA = data
        self._SIZE = size
        self._NROWS = rows
        self._NCOLS = cols
        self._COLOFF = coloff
        self._OVERLAP = overlap
        self._PAD = params.get("PAD")
        if self._PAD is None:
            self._PAD = 1
Esempio n. 10
0
 def __init__(self, context, value):
     Plugin.__init__(self)
     self.__value = value
Esempio n. 11
0
 def __init__(self, context, *args):
     Plugin.__init__(self)
     self._args, self._config = self._split_arguments(args)
     self._dynamic = self.DYNAMIC
     self._context = context
     self._cached_filter = None
Esempio n. 12
0
 def __init__(self, context, config=None):
     Plugin.__init__(self)
     self.__config = config  # unused
Esempio n. 13
0
 def __init__(self, context, args=None):
     Plugin.__init__(self)
     self.__sorted = bool(args and args.get("sorted"))
Esempio n. 14
0
 def __init__(self, context, value):
   Plugin.__init__(self)
   self.__value = value
Esempio n. 15
0
  def __init__(self, context, data, params=None):
    """Initialises the object to iterate through the data set passed
    by list as the first parameter.

    It calculates the shape of the permutation table based on the ROWS
    or COLS parameters specified in the params dictionary.  The
    OVERLAP parameter may be provided to specify the number of common
    items that should be shared between subseqent columns.
    """
    Plugin.__init__(self)
    if isinstance(data, Iterator):
      data, error = data.get_all()
      if error:
        raise Error("iterator failed to provide data for table: %s" % error)
    if not isinstance(data, (tuple, list)):
      raise Error("invalid table data, expecting a list")

    if params is None:
      params = {}
    if not isinstance(params, dict):
      raise Error("invalid table parameters, expecting a dict")

    # ensure keys are folded to upper case
    params.update(dict((str(key).upper(), value)
                  for key, value in params.iteritems()))

    size = len(data)
    overlap = params.get("OVERLAP", 0)

    rows = params.get("ROWS")
    cols = params.get("COLS")
    if rows:
      if size < rows:
        rows = size
        cols = 1
        coloff = 0
      else:
        coloff = rows - overlap
        cols = size / coloff + int(size % coloff > overlap)
    elif cols:
      if size < cols:
        cols = size
        rows = 1
        coloff = 1
      else:
        coloff = size / cols + int(size % cols > overlap)
        rows = coloff + overlap
    else:
      rows = size
      cols = 1
      coloff = 0

    self._DATA = data
    self._SIZE = size
    self._NROWS = rows
    self._NCOLS = cols
    self._COLOFF = coloff
    self._OVERLAP = overlap
    self._PAD = params.get("PAD")
    if self._PAD is None:
      self._PAD = 1
Esempio n. 16
0
 def __init__(self, context, args=None):
   Plugin.__init__(self)
   self.__sorted = bool(args and args.get("sorted"))