Blob Blame History Raw
From 2cbee8611dfeaa5a3d43f54fd5638961b8f4d047 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= <zbyszek@in.waw.pl>
Date: Fri, 19 Jul 2019 22:03:35 +0200
Subject: [PATCH] py3: fix invalid escapes

python3.8 warns about strings which try to escape characters which do
not need that. To avoid the warning, the backslash should be escaped.
(Behaviour is functionally the same, so e.g. '\$' is still the same as
r'\$', except for the warning.)
---
 css_parser_tests/test_csscharsetrule.py      | 2 +-
 css_parser_tests/test_cssstyledeclaration.py | 6 +++---
 css_parser_tests/test_cssutils.py            | 4 ++--
 css_parser_tests/test_serialize.py           | 6 +++---
 css_parser_tests/test_tokenize2.py           | 2 +-
 5 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/css_parser_tests/test_csscharsetrule.py b/css_parser_tests/test_csscharsetrule.py
index d967047..5a8a29e 100644
--- a/css_parser_tests/test_csscharsetrule.py
+++ b/css_parser_tests/test_csscharsetrule.py
@@ -49,7 +49,7 @@ def test_init_encoding(self):
         for enc in ('unknown', ):
             self.assertRaisesEx(xml.dom.SyntaxErr,
                                 css_parser.css.CSSCharsetRule, enc,
-                                exc_pattern=re.compile("Unknown \(Python\) encoding"))
+                                exc_pattern=re.compile(r"Unknown \(Python\) encoding"))
 
     def test_encoding(self):
         "CSSCharsetRule.encoding"
diff --git a/css_parser_tests/test_cssstyledeclaration.py b/css_parser_tests/test_cssstyledeclaration.py
index aee5ee8..0f16b11 100644
--- a/css_parser_tests/test_cssstyledeclaration.py
+++ b/css_parser_tests/test_cssstyledeclaration.py
@@ -534,18 +534,18 @@ def test_nameParameter(self):
 
         self.assertEqual('1px', s.getPropertyValue('top'))
         self.assertEqual('1px', s.getPropertyValue('TOP'))
-        self.assertEqual('1px', s.getPropertyValue('T\op'))
+        self.assertEqual('1px', s.getPropertyValue(r'T\op'))
 
         self.assertEqual('important', s.getPropertyPriority('top'))
         self.assertEqual('important', s.getPropertyPriority('TOP'))
-        self.assertEqual('important', s.getPropertyPriority('T\op'))
+        self.assertEqual('important', s.getPropertyPriority(r'T\op'))
 
         s.setProperty('top', '2px', '!important')
         self.assertEqual('2px', s.removeProperty('top'))
         s.setProperty('top', '2px', '!important')
         self.assertEqual('2px', s.removeProperty('TOP'))
         s.setProperty('top', '2px', '!important')
-        self.assertEqual('2px', s.removeProperty('T\op'))
+        self.assertEqual('2px', s.removeProperty(r'T\op'))
 
     def test_css2properties(self):
         "CSSStyleDeclaration.$css2property get set del"
diff --git a/css_parser_tests/test_cssutils.py b/css_parser_tests/test_cssutils.py
index 738f851..a2bed36 100644
--- a/css_parser_tests/test_cssutils.py
+++ b/css_parser_tests/test_cssutils.py
@@ -234,7 +234,7 @@ def test_getUrls(self):
         "css_parser.getUrls()"
         css_parser.ser.prefs.keepAllProperties = True
 
-        css = '''
+        css = r'''
         @import "im1";
         @import url(im2);
         @import url( im3 );
@@ -263,7 +263,7 @@ def test_replaceUrls(self):
         "css_parser.replaceUrls()"
         css_parser.ser.prefs.keepAllProperties = True
 
-        css = '''
+        css = r'''
         @import "im1";
         @import url(im2);
         a {
diff --git a/css_parser_tests/test_serialize.py b/css_parser_tests/test_serialize.py
index 08e7d43..f207aea 100644
--- a/css_parser_tests/test_serialize.py
+++ b/css_parser_tests/test_serialize.py
@@ -246,7 +246,7 @@ def test_defaultPropertyName(self):
         css_parser.ser.prefs.defaultPropertyName = False
         self.assertEqual('a {\n    c\\olor: green\n    }'.encode(), s.cssText)
 
-        s = css_parser.parseString('a { color: red; c\olor: green; }')
+        s = css_parser.parseString(r'a { color: red; c\olor: green; }')
         self.assertEqual('a {\n    c\\olor: green\n    }'.encode(), s.cssText)
         css_parser.ser.prefs.defaultPropertyName = False
         self.assertEqual('a {\n    c\\olor: green\n    }'.encode(), s.cssText)
@@ -359,7 +359,7 @@ def test_indentClosingBrace(self):
 
     def test_keepAllProperties(self):
         "Preferences.keepAllProperties"
-        css = '''a {
+        css = r'''a {
             color: pink;
             color: red;
             c\olor: blue;
@@ -372,7 +372,7 @@ def test_keepAllProperties(self):
         # keep all
         css_parser.ser.prefs.keepAllProperties = True
         self.assertEqual(
-            'a {\n    color: pink;\n    color: red;\n    c\olor: blue;\n    c\olor: green\n    }'.encode(), s.cssText)
+            'a {\n    color: pink;\n    color: red;\n    c\\olor: blue;\n    c\olor: green\n    }'.encode(), s.cssText)
 
     def test_keepComments(self):
         "Preferences.keepComments"
diff --git a/css_parser_tests/test_tokenize2.py b/css_parser_tests/test_tokenize2.py
index 91cb5f5..616f7ed 100644
--- a/css_parser_tests/test_tokenize2.py
+++ b/css_parser_tests/test_tokenize2.py
@@ -41,7 +41,7 @@ class TokenizerTestCase(basetest.BaseTestCase):
         # TODO:
         # Note that this means that a "real" space after the escape sequence
         # must itself either be escaped or doubled:
-        '\\44\ x': [('IDENT', 'D\\ x', 1, 1)],
+        '\\44\\ x': [('IDENT', 'D\\ x', 1, 1)],
         '\\44  ': [('IDENT', 'D', 1, 1),
                     ('S', ' ', 1, 5)],