Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions httpbin/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
from .structures import CaseInsensitiveDict


ASCII_ART = """
ASCII_ART = r'''
-=[ teapot ]=-

_...._
Expand All @@ -38,8 +38,8 @@
\_;`"---"`|//
| ;/
\_ _/
`\"\"\"`
"""
`"""`
'''

REDIRECT_LOCATION = '/redirect/1'

Expand Down Expand Up @@ -74,10 +74,10 @@
'image/*'
]

ANGRY_ASCII ="""
ANGRY_ASCII = r"""
.-''''''-.
.' _ _ '.
/ O O \\
/ O O \
: :
| |
: __ :
Expand Down Expand Up @@ -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
Expand Down
21 changes: 21 additions & 0 deletions tests/test_httpbin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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" ])
Expand Down
Loading