def encode(cls, string, encoding=None): """Encode the string""" # FIXME: dialects are a bad idea, not possible for subclasses # to override key methods if encoding not in ("utf-8", "utf-16"): return quote.javapropertiesencode(string or "") return quote.java_utf8_properties_encode(string or "")
def encode(cls, string, encoding=None): """Encode the string""" # FIXME: dialects are a bad idea, not possible for subclasses # to override key methods if encoding != "utf-8": return quote.javapropertiesencode(string or u"") return string or u""
def settarget(self, target): self._rich_target = None target = data.forceunicode(target) if self.personality == "mozilla" or self.personality == "skype": self.translation = quote.mozillapropertiesencode(target or u"") else: self.translation = quote.javapropertiesencode(target or u"")
def setsource(self, source): self._rich_source = None source = data.forceunicode(source) if self.personality == "mozilla" or self.personality == "skype": self.value = quote.mozillapropertiesencode(source or u"") else: self.value = quote.javapropertiesencode(source or u"")
def setsource(self, source): """Sets the source AND the target to be equal""" source = data.forceunicode(source) if self.personality == "mozilla": self.value = quote.mozillapropertiesencode(source or u"") else: self.value = quote.javapropertiesencode(source or u"")
def convertline(self, line): returnline = "" # handle multiline msgid if we're in one if self.inmultilinemsgid: msgid = quote.rstripeol(line).strip() # see if there's more self.inmultilinemsgid = (msgid[-1:] == '\\') # if we're echoing... if self.inecho: returnline = line # otherwise, this could be a comment elif line.strip()[:1] == '#': returnline = quote.rstripeol(line) + eol else: line = quote.rstripeol(line) equalspos = line.find('=') # if no equals, just repeat it if equalspos == -1: returnline = quote.rstripeol(line) + eol # otherwise, this is a definition else: # backslash at end means carry string on to next line if quote.rstripeol(line)[-1:] == '\\': self.inmultilinemsgid = True # now deal with the current string... key = line[:equalspos].strip() # Calculate space around the equal sign prespace = line.lstrip()[line.lstrip().find(' '):equalspos] postspacestart = len(line[equalspos + 1:]) postspaceend = len(line[equalspos + 1:].lstrip()) postspace = line[equalspos + 1:equalspos + (postspacestart - postspaceend) + 1] if self.inputdict.has_key(key): self.inecho = False value = self.inputdict[key] if isinstance(value, str): value = value.decode('utf8') if self.personality == "mozilla" or self.personality == "skype": returnline = key + prespace + "=" + postspace + quote.mozillapropertiesencode( value) + eol else: returnline = key + prespace + "=" + postspace + quote.javapropertiesencode( value) + eol else: self.inecho = True returnline = line + eol if isinstance(returnline, unicode): returnline = returnline.encode('utf-8') return returnline
def convertline(self, line): returnline = "" # handle multiline msgid if we're in one if self.inmultilinemsgid: msgid = quote.rstripeol(line).strip() # see if there's more self.inmultilinemsgid = msgid[-1:] == "\\" # if we're echoing... if self.inecho: returnline = line # otherwise, this could be a comment elif line.strip()[:1] == "#": returnline = quote.rstripeol(line) + eol else: line = quote.rstripeol(line) equalspos = line.find("=") # if no equals, just repeat it if equalspos == -1: returnline = quote.rstripeol(line) + eol # otherwise, this is a definition else: # backslash at end means carry string on to next line if quote.rstripeol(line)[-1:] == "\\": self.inmultilinemsgid = True # now deal with the current string... key = line[:equalspos].strip() # Calculate space around the equal sign prespace = line.lstrip()[line.lstrip().find(" ") : equalspos] postspacestart = len(line[equalspos + 1 :]) postspaceend = len(line[equalspos + 1 :].lstrip()) postspace = line[equalspos + 1 : equalspos + (postspacestart - postspaceend) + 1] if self.inputdict.has_key(key): self.inecho = False value = self.inputdict[key] if isinstance(value, str): value = value.decode("utf8") if self.personality == "mozilla" or self.personality == "skype": returnline = key + prespace + "=" + postspace + quote.mozillapropertiesencode(value) + eol else: returnline = key + prespace + "=" + postspace + quote.javapropertiesencode(value) + eol else: self.inecho = True returnline = line + eol if isinstance(returnline, unicode): returnline = returnline.encode("utf-8") return returnline
def test_javapropertiesencode(): assert quote.javapropertiesencode("abc") == "abc" assert quote.javapropertiesencode("abcḓ") == r"abc\u1E13" assert quote.javapropertiesencode("abc\n") == "abc\\n"
def test_javepropertiesencode(self): assert quote.javapropertiesencode(u"abc") == u"abc" assert quote.javapropertiesencode(u"abcḓ") == "abc\u1E13" assert quote.javapropertiesencode(u"abc\n") == u"abc\\n"
def test_javepropertiesencode(self): assert quote.javapropertiesencode("abc") == "abc" assert quote.javapropertiesencode("abcḓ") == "abc\u1E13" assert quote.javapropertiesencode("abc\n") == "abc\\n"
def encode(cls, string): """Encode the string""" return quote.javapropertiesencode(string or u"")
def settarget(self, target): target = data.forceunicode(target) if self.personality == "mozilla" or self.personality == "skype": self.translation = quote.mozillapropertiesencode(target or u"") else: self.translation = quote.javapropertiesencode(target or u"")
def setsource(self, source): source = data.forceunicode(source) if self.personality == "mozilla" or self.personality == "skype": self.value = quote.mozillapropertiesencode(source or u"") else: self.value = quote.javapropertiesencode(source or u"")