diff --git a/httpbin/helpers.py b/httpbin/helpers.py index 836c8026..ac74b100 100644 --- a/httpbin/helpers.py +++ b/httpbin/helpers.py @@ -29,7 +29,7 @@ from .structures import CaseInsensitiveDict -ASCII_ART = """ +ASCII_ART = r''' -=[ teapot ]=- _...._ @@ -38,8 +38,8 @@ \_;`"---"`|// | ;/ \_ _/ - `\"\"\"` -""" + `"""` +''' REDIRECT_LOCATION = '/redirect/1' @@ -74,10 +74,10 @@ 'image/*' ] -ANGRY_ASCII =""" +ANGRY_ASCII = r""" .-''''''-. .' _ _ '. - / O O \\ + / O O \ : : | | : __ : @@ -441,7 +441,7 @@ def parse_multi_value_header(header_str): if header_str: parts = header_str.split(',') for part in parts: - match = re.search('\s*(W/)?\"?([^"]*)\"?\s*', part) + match = re.search(r'\s*(W/)?\"?([^"]*)\"?\s*', part) if match is not None: parsed_parts.append(match.group(2)) return parsed_parts diff --git a/tests/test_httpbin.py b/tests/test_httpbin.py index eb1d315c..3c7c7663 100755 --- a/tests/test_httpbin.py +++ b/tests/test_httpbin.py @@ -823,6 +823,27 @@ def test_index_falls_back_to_static_page_without_flasgger(self): self.assertEqual(result.returncode, 0, result.stderr) self.assertIn("OK", result.stdout) + def test_sources_have_no_invalid_escape_sequences(self): + """Every module in the httpbin package compiles without escape-sequence + warnings. Invalid escapes are a SyntaxWarning on 3.12+ (DeprecationWarning + earlier) and will become a SyntaxError in a future Python.""" + import glob + import warnings + + pkg_dir = os.path.dirname(httpbin.__file__) + py_files = glob.glob(os.path.join(pkg_dir, "**", "*.py"), recursive=True) + self.assertTrue(py_files, "no source files found") + with warnings.catch_warnings(): + warnings.simplefilter("error", SyntaxWarning) + warnings.simplefilter("error", DeprecationWarning) + for path in py_files: + with open(path, encoding="utf-8") as f: + src = f.read() + try: + compile(src, path, "exec") + except (SyntaxWarning, DeprecationWarning) as exc: + self.fail("{}: {}".format(path, exc)) + def test_parse_multi_value_header(self): self.assertEqual(parse_multi_value_header('xyzzy'), [ "xyzzy" ]) self.assertEqual(parse_multi_value_header('"xyzzy"'), [ "xyzzy" ])