Beispiel #1
0
 def parse(self, lines, keyParser={}, valueParser={}):
     defaultKeyParser = keyParser.get(None, lambda k: parseType(k.lower()))
     defaultValueParser = valueParser.get(None, parseType)
     data = {}
     doAdd = False
     currentline = ""
     try:
         lines = lines.splitlines()
     except Exception:
         pass
     for line in lines:
         if self.escapeString:
             # Switch accumulate on/off when odd number of quotes found
             if (line.count('"') - line.count('\\"')) % 2 == 1:
                 doAdd = not doAdd
             currentline += line
             if doAdd:
                 continue
         else:
             currentline = line
         try:  # split at first occurence of delimeter and strip spaces around
             key, value = map(str.strip, currentline.split(self.delimeter, 1))
             currentline = ""
         except Exception:  # in case no delimeter was found
             currentline = ""
             continue
         if self.escapeString:
             value = value.strip('"').replace('\\"', '"').replace("\\$", "$")
         key = keyParser.get(key, defaultKeyParser)(key)
         data[key] = valueParser.get(key, defaultValueParser)(value)  # do .encode('utf-8') ?
     if doAdd:
         raise RuntimeError("Invalid dict format in %s" % fp.name)
     return data
Beispiel #2
0
 def fillParameterInfo(self, pNum, result):
     tmp = dict(
         imap(lambda k_v: (str(k_v[0]), parseType(str(k_v[1]))),
              result.items()))
     try:
         result[self._key] = eval(self._fmt, tmp)  # pylint:disable=eval-used
     except Exception:
         result[self._key] = self._default
Beispiel #3
0
 def __init__(self, filename, delimeter="=", lowerCaseKey=True):
     dict.__init__(self)
     self.fmt = DictFormat(delimeter)
     self.filename = filename
     keyParser = {None: QM(lowerCaseKey, lambda k: parseType(k.lower()), parseType)}
     try:
         self.update(self.fmt.parse(open(filename), keyParser=keyParser))
     except Exception:
         pass
     self.olddict = self.items()
Beispiel #4
0
 def __init__(self, filename, delimeter='=', lowerCaseKey=True):
     dict.__init__(self)
     self.fmt = DictFormat(delimeter)
     self.filename = filename
     keyParser = {
         None: QM(lowerCaseKey, lambda k: parseType(k.lower()), parseType)
     }
     try:
         self.update(self.fmt.parse(open(filename), keyParser=keyParser))
     except Exception:
         pass
     self.olddict = self.items()
Beispiel #5
0
 def parse(self, lines, keyParser=None, valueParser=None):
     keyParser = keyParser or {}
     valueParser = valueParser or {}
     defaultKeyParser = keyParser.get(None, lambda k: parseType(k.lower()))
     defaultValueParser = valueParser.get(None, parseType)
     data = {}
     doAdd = False
     currentline = ''
     try:
         lines = lines.splitlines()
     except Exception:
         clear_current_exception()
     for line in lines:
         try:
             if not isinstance(line, str):
                 line = line.decode('utf-8')
             if self.escapeString:
                 # Switch accumulate on/off when odd number of quotes found
                 if (line.count('"') - line.count('\\"')) % 2 == 1:
                     doAdd = not doAdd
                 currentline += line
                 if doAdd:
                     continue
             else:
                 currentline = line
             # split at first occurence of delimeter and strip spaces around
             key_value_list = lmap(str.strip,
                                   currentline.split(self.delimeter, 1))
             if len(key_value_list) == 2:
                 key, value = key_value_list
                 currentline = ''
             else:  # in case no delimeter was found
                 currentline = ''
                 continue
             if self.escapeString:
                 value = value.strip('"').replace('\\"',
                                                  '"').replace('\\$', '$')
             key = keyParser.get(key, defaultKeyParser)(key)
             data[key] = valueParser.get(key, defaultValueParser)(
                 value)  # do .encode('utf-8') ?
         except Exception:
             raise GCError('Invalid dict format in %s' % repr(line))
     if doAdd:
         raise GCError('Invalid dict format in %s' % repr(lines))
     return data
Beispiel #6
0
	def parse(self, lines, keyParser = None, valueParser = None):
		keyParser = keyParser or {}
		valueParser = valueParser or {}
		defaultKeyParser = keyParser.get(None, lambda k: parseType(k.lower()))
		defaultValueParser = valueParser.get(None, parseType)
		data = {}
		doAdd = False
		currentline = ''
		try:
			lines = lines.splitlines()
		except Exception:
			clear_current_exception()
		for line in lines:
			try:
				if not isinstance(line, str):
					line = line.decode('utf-8')
				if self.escapeString:
					# Switch accumulate on/off when odd number of quotes found
					if (line.count('"') - line.count('\\"')) % 2 == 1:
						doAdd = not doAdd
					currentline += line
					if doAdd:
						continue
				else:
					currentline = line
				# split at first occurence of delimeter and strip spaces around
				key_value_list = lmap(str.strip, currentline.split(self.delimeter, 1))
				if len(key_value_list) == 2:
					key, value = key_value_list
					currentline = ''
				else: # in case no delimeter was found
					currentline = ''
					continue
				if self.escapeString:
					value = value.strip('"').replace('\\"', '"').replace('\\$', '$')
				key = keyParser.get(key, defaultKeyParser)(key)
				data[key] = valueParser.get(key, defaultValueParser)(value) # do .encode('utf-8') ?
			except Exception:
				raise GCError('Invalid dict format in %s' % repr(line))
		if doAdd:
			raise GCError('Invalid dict format in %s' % repr(lines))
		return data
Beispiel #7
0
 def fillParameterInfo(self, pNum, result):
     src = parseType(str(result.get(self._source, self._default)))
     result[self._key] = self._fmt % src
	def fillParameterInfo(self, pNum, result):
		tmp = dict(imap(lambda k_v: (str(k_v[0]), parseType(str(k_v[1]))), result.items()))
		try:
			result[self._key] = eval(self._fmt, tmp) # pylint:disable=eval-used
		except Exception:
			result[self._key] = self._default
	def fillParameterInfo(self, pNum, result):
		src = parseType(str(result.get(self._source, self._default)))
		result[self._key] = self._fmt % src