Пример #1
0
    def __init__(self, fn, format='sniffed'):
        (self._fn, self._format) = (fn, format)
        fp = open(fn)
        try:
            first_line = fp.readline()
            sniffed = csv.Sniffer().sniff(first_line)
            csv.register_dialect('sniffed', sniffed)
            csv_header = first_line.strip().split(sniffed.delimiter) + [None]
            psp_list = list(csv.DictReader(fp, csv_header, dialect=format))
        finally:
            fp.close()
        for psp in psp_list:
            psp.pop(None, None)
            if None in psp.values():
                raise ParameterError('Malformed entry in csv file %r: {%s}' %
                                     (fn, str_dict_linear(psp)))

        def _cleanup_dict(
            mapping
        ):  # strip all key value entries and filter empty parameters
            tmp = tuple(
                imap(lambda item: lmap(str.strip, item), mapping.items()))
            return dict(lfilter(lambda k_v: k_v[0] != '', tmp))

        output_vn_list = sorted(imap(ParameterMetadata, lidfilter(csv_header)),
                                key=lambda k: k.value)
        InternalParameterSource.__init__(self, lmap(_cleanup_dict, psp_list),
                                         output_vn_list)
Пример #2
0
	def __init__(self, output_vn, source_vn, regex_dict, regex_order, default=None):
		SingleParameterSource.__init__(self, '!%s' % output_vn,
			[output_vn, source_vn, regex_order, str_dict_linear(regex_dict)])
		(self._source_vn, self._default) = (source_vn, default)
		(self._regex_order, self._regex_dict) = (regex_order, regex_dict)
		self._regex_comp = {}  # precompile regex
		for regex_pattern in self._regex_order:
			self._regex_comp[regex_pattern] = re.compile(regex_pattern)
Пример #3
0
 def __init__(self,
              output_vn,
              source_vn,
              regex_dict,
              regex_order,
              default=None):
     SingleParameterSource.__init__(
         self, '!%s' % output_vn,
         [output_vn, source_vn, regex_order,
          str_dict_linear(regex_dict)])
     (self._source_vn, self._default) = (source_vn, default)
     (self._regex_order, self._regex_dict) = (regex_order, regex_dict)
     self._regex_comp = {}  # precompile regex
     for regex_pattern in self._regex_order:
         self._regex_comp[regex_pattern] = re.compile(regex_pattern)
Пример #4
0
	def __init__(self, fn, format='sniffed'):
		(self._fn, self._format) = (fn, format)
		fp = open(fn)
		try:
			first_line = fp.readline()
			sniffed = csv.Sniffer().sniff(first_line)
			csv.register_dialect('sniffed', sniffed)
			csv_header = first_line.strip().split(sniffed.delimiter) + [None]
			psp_list = list(csv.DictReader(fp, csv_header, dialect=format))
		finally:
			fp.close()
		for psp in psp_list:
			psp.pop(None, None)
			if None in psp.values():
				raise ParameterError('Malformed entry in csv file %r: {%s}' % (fn, str_dict_linear(psp)))

		def _cleanup_dict(mapping):  # strip all key value entries and filter empty parameters
			tmp = tuple(imap(lambda item: lmap(str.strip, item), mapping.items()))
			return dict(lfilter(lambda k_v: k_v[0] != '', tmp))
		output_vn_list = sorted(imap(ParameterMetadata, lidfilter(csv_header)), key=lambda k: k.value)
		InternalParameterSource.__init__(self, lmap(_cleanup_dict, psp_list), output_vn_list)
Пример #5
0
	def show_psrc(self):
		return ['%s: seeds = {%s}' % (self.__class__.__name__, str_dict_linear(self._seed_dict))]
Пример #6
0
	def __repr__(self):
		return 'multi_counter(%s)' % str_dict_linear(self._seed_dict)
Пример #7
0
	def __init__(self, **kwargs):
		self._seed_dict = kwargs
		ImmutableParameterSource.__init__(self, [str_dict_linear(self._seed_dict)])
		self._meta_list = lmap(lambda vn: ParameterMetadata(vn, untracked=True), self._seed_dict)
Пример #8
0
 def __repr__(self):
     return 'regex_transform(%r, %r, %r)' % (
         self._output_vn, self._source_vn, str_dict_linear(
             self._regex_dict))
Пример #9
0
 def __repr__(self):
     return '%s(values = {%s}, matcher = %r, only_first = %r, always_default = %r)' % (
         self.__class__.__name__, str_dict_linear(
             self._values, self._order), self._matcher, self._only_first,
         self._always_default)
Пример #10
0
	def __repr__(self):
		return '%s(values = {%s}, matcher = %r, only_first = %r, always_default = %r)' % (
			self.__class__.__name__, str_dict_linear(self._values, self._order), self._matcher,
			self._only_first, self._always_default)
Пример #11
0
 def __repr__(self):
     return '%s(%s)' % (self.__class__.__name__,
                        str_dict_linear(self.__dict__))
Пример #12
0
 def show_psrc(self):
     return [
         '%s: seeds = {%s}' %
         (self.__class__.__name__, str_dict_linear(self._seed_dict))
     ]
Пример #13
0
 def __repr__(self):
     return 'multi_counter(%s)' % str_dict_linear(self._seed_dict)
Пример #14
0
 def __init__(self, **kwargs):
     self._seed_dict = kwargs
     ImmutableParameterSource.__init__(self,
                                       [str_dict_linear(self._seed_dict)])
     self._meta_list = lmap(
         lambda vn: ParameterMetadata(vn, untracked=True), self._seed_dict)
Пример #15
0
 def show_psrc(self):
     return [
         '%s: var = %s, source_vn = %r, regex_dict = %r' %
         (self.__class__.__name__, self._output_vn, self._source_vn,
          str_dict_linear(self._regex_dict))
     ]
Пример #16
0
 def __repr__(self):
     return 'Result(%s)' % str_dict_linear(self.__dict__)
Пример #17
0
	def __repr__(self):
		return 'Result(%s)' % str_dict_linear(self.__dict__)
Пример #18
0
	def __repr__(self):
		return 'regex_transform(%r, %r, %r)' % (self._output_vn, self._source_vn,
			str_dict_linear(self._regex_dict))
Пример #19
0
	def __repr__(self):
		return '%s(%s)' % (self.__class__.__name__, str_dict_linear(self.__dict__))
Пример #20
0
	def show_psrc(self):
		return ['%s: var = %s, source_vn = %r, regex_dict = %r' %
			(self.__class__.__name__, self._output_vn, self._source_vn, str_dict_linear(self._regex_dict))]