def _parseline(self, line): """ parse a line into a key, value and comment :param str line: Line to be parsed :returns: Tuple of key, value, comment :rtype: tuple Handle comments and optionally unquote quoted strings Returns (key, value, comment) or (None, None, comment) key is always UPPERCASE and comment may by "" if none was found. """ s = line.strip() # Look for a # outside any quotes comment = "" comment_index = find_comment(s) if comment_index is not None: comment = s[comment_index:] s = s[:comment_index] # remove from comment to EOL key, eq, val = s.partition('=') key = key.strip() val = val.strip() if self.read_unquote: val = unquote(val) if key != '' and eq == '=': return (upper_ascii(key), val, comment) else: return (None, None, comment)
def addMessage(self, name, argc): if name in self.__names: raise AttributeError("%s queue already has a message named %s" % (self.name, name)) # Add a constant. const_name = upper_ascii(self.name) + "_CODE_" + upper_ascii(name) setattr(self, const_name, self.__counter) self.__counter += 1 # Add a convenience method for putting things into the queue. method_name = "send_" + lower_ascii(name) method = self._makeMethod(getattr(self, const_name), method_name, argc) setattr(self, method_name, method) self.__names.append(name)
def test_upper_ascii(self): """Test upper_ascii.""" assert upper_ascii("") == "" assert upper_ascii("a") == "A" assert upper_ascii("A") == "A" assert upper_ascii("aBc") == "ABC" assert upper_ascii("_&*'@#$%^aBcžčŘ") == \ "_&*'@#$%^ABCZCR" _out = "HEIZOLRUCKSTOABDAMPFUNG" assert upper_ascii("Heizölrückstoßabdämpfung") == _out
def get(self, key): return self.info.get(upper_ascii(key), "")
def unset(self, *keys): for key in (upper_ascii(k) for k in keys): if key in self.info: del self.info[key]
def set(self, *args): for key, value in args: self.info[upper_ascii(key)] = value