Exemple #1
0
 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""
Exemple #3
0
 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"")
Exemple #4
0
 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""
Exemple #5
0
 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"")
Exemple #6
0
 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"")
Exemple #7
0
 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
Exemple #8
0
 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
Exemple #9
0
 def test_javapropertiesencode():
     assert quote.javapropertiesencode("abc") == "abc"
     assert quote.javapropertiesencode("abcḓ") == r"abc\u1E13"
     assert quote.javapropertiesencode("abc\n") == "abc\\n"
Exemple #10
0
 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"
Exemple #11
0
 def test_javepropertiesencode(self):
     assert quote.javapropertiesencode("abc") == "abc"
     assert quote.javapropertiesencode("abcḓ") == "abc\u1E13"
     assert quote.javapropertiesencode("abc\n") == "abc\\n"
Exemple #12
0
 def encode(cls, string):
     """Encode the string"""
     return quote.javapropertiesencode(string or u"")
Exemple #13
0
 def encode(cls, string):
     """Encode the string"""
     return quote.javapropertiesencode(string or u"")
Exemple #14
0
 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"")
Exemple #15
0
 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"")