# HG changeset patch # User laurent # Date 1323421604 -3600 # Node ID 41e62b3174dc928b1c89a308b523b4dbaf57e5db # Parent 34c3569042db8550fe7ed38671963ab1e592775c Fixing bug when updating name of project elements in utf-8 formatted text diff -r 34c3569042db -r 41e62b3174dc plcopen/plcopen.py --- a/plcopen/plcopen.py Thu Nov 24 16:30:06 2011 +0100 +++ b/plcopen/plcopen.py Fri Dec 09 10:06:44 2011 +0100 @@ -129,26 +129,30 @@ cls = PLCOpenClasses.get("formattedText", None) if cls: def updateElementName(self, old_name, new_name): - index = self.text.find(old_name) + text = self.text.decode("utf-8") + index = text.find(old_name) while index != -1: - if index > 0 and (self.text[index - 1].isalnum() or self.text[index - 1] == "_"): - index = self.text.find(old_name, index + len(old_name)) - elif index < len(self.text) - len(old_name) and (self.text[index + len(old_name)].isalnum() or self.text[index + len(old_name)] == "_"): - index = self.text.find(old_name, index + len(old_name)) + if index > 0 and (text[index - 1].isalnum() or text[index - 1] == "_"): + index = text.find(old_name, index + len(old_name)) + elif index < len(text) - len(old_name) and (text[index + len(old_name)].isalnum() or text[index + len(old_name)] == "_"): + index = text.find(old_name, index + len(old_name)) else: - self.text = self.text[:index] + new_name + self.text[index + len(old_name):] - index = self.text.find(old_name, index + len(new_name)) + text = text[:index] + new_name + text[index + len(old_name):] + index = text.find(old_name, index + len(new_name)) + self.text = text.encode("utf-8") setattr(cls, "updateElementName", updateElementName) def updateElementAddress(self, address_model, new_leading): + text = self.text.decode("utf-8") startpos = 0 - result = address_model.search(self.text, startpos) + result = address_model.search(text, startpos) while result is not None: groups = result.groups() new_address = groups[0] + new_leading + groups[2] - self.text = self.text[:result.start()] + new_address + self.text[result.end():] + text = text[:result.start()] + new_address + text[result.end():] startpos = result.start() + len(new_address) result = address_model.search(self.text, startpos) + self.text = text.encode("utf-8") setattr(cls, "updateElementAddress", updateElementAddress) def Search(self, criteria, parent_infos): diff -r 34c3569042db -r 41e62b3174dc xmlclass/xmlclass.py --- a/xmlclass/xmlclass.py Thu Nov 24 16:30:06 2011 +0100 +++ b/xmlclass/xmlclass.py Fri Dec 09 10:06:44 2011 +0100 @@ -1402,7 +1402,6 @@ structure_model = re.compile("(%s)$" % structure_pattern) result = structure_model.match(children_structure) if not result: - print structure_model.pattern, children_structure raise ValueError("Invalid structure for \"%s\" children!." % tree.nodeName) required_attributes = dict([(attr["name"], True) for attr in classinfos["attributes"] if attr["use"] == "required"]) if classinfos.has_key("base"):