Exemple #1
0
  def StringEscape(self, string, match, **_):
    """Escape backslashes found inside a string quote.

    Backslashes followed by anything other than ['"rnbt] will just be included
    in the string.

    Args:
       string: The string that matched.
       match: The match object (m.group(1) is the escaped code)
    """
    precondition.AssertType(string, Text)
    if match.group(1) in "'\"rnbt":
      self.string += compatibility.UnescapeString(string)
    else:
      self.string += string
Exemple #2
0
    def StringEscape(self, string, match, **_):
        """Escape backslashes found inside a string quote.

    Backslashes followed by anything other than [\'"rnbt] will raise an Error.

    Args:
      string: The string that matched.
      match: The match object (m.group(1) is the escaped code)

    Raises:
      ParseError: For strings other than those used to define a regexp, raise an
        error if the escaped string is not one of [\'"rnbt].
    """
        precondition.AssertType(string, Text)

        # Allow unfiltered strings for regexp operations so that escaped special
        # characters (e.g. \*) or special sequences (e.g. \w) can be used in
        # objectfilter.
        if self.current_expression.operator == "regexp":
            self.string += compatibility.UnescapeString(string)
        elif match.group(1) in "\\'\"rnbt":
            self.string += compatibility.UnescapeString(string)
        else:
            raise ParseError("Invalid escape character %s." % string)
Exemple #3
0
 def testMany(self):
     self.assertEqual(compatibility.UnescapeString("foo\\n\\'bar\\'\nbaz"),
                      "foo\n'bar'\nbaz")
Exemple #4
0
 def testQuotemark(self):
     self.assertEqual(compatibility.UnescapeString("\\'"), "'")
     self.assertEqual(compatibility.UnescapeString("\\\""), "\"")
Exemple #5
0
 def testWhitespace(self):
     self.assertEqual(compatibility.UnescapeString("\\n"), "\n")
     self.assertEqual(compatibility.UnescapeString("\\r"), "\r")