Skip to content

Commit

Permalink
Reformatted code per updates in black style.
Browse files Browse the repository at this point in the history
  • Loading branch information
akornatskyy committed Aug 29, 2020
1 parent 5a88f25 commit 017c158
Show file tree
Hide file tree
Showing 19 changed files with 181 additions and 232 deletions.
9 changes: 3 additions & 6 deletions demos/hello/test_helloworld.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@


class MainTestCase(unittest.TestCase):
""" Test the ``main`` funcation call.
"""
"""Test the ``main`` funcation call."""

def test_hello_match(self):
"""
"""
""""""
from helloworld import main

def start_response(status, response_headers):
Expand All @@ -24,8 +22,7 @@ def start_response(status, response_headers):
self.assertEquals(["Hello World!"], response)

def test_any_path_match(self):
"""
"""
""""""
from helloworld import main

def start_response(status, response_headers):
Expand Down
22 changes: 10 additions & 12 deletions demos/time/test_functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,13 @@


class FunctionalTestCase(unittest.TestCase):
""" Functional tests for ``time`` application.
"""
"""Functional tests for ``time`` application."""

def go(self, path, expected_status="200 OK"):
""" Make a call to ``main`` function setting
wsgi ``environ['PATH_INFO']`` to ``path``
and validating expected http response
status.
"""Make a call to ``main`` function setting
wsgi ``environ['PATH_INFO']`` to ``path``
and validating expected http response
status.
"""
from app import main

Expand All @@ -28,24 +27,23 @@ def start_response(status, response_headers):
)

def test_welcome(self):
""" Welcome page must have a valid path
to ``server_time`` view.
"""Welcome page must have a valid path
to ``server_time`` view.
"""
response = self.go("/")

assert "Welcome" in response
assert "href='server/time'" in response

def test_server_time(self):
""" Ensure it is a server time page.
"""
"""Ensure it is a server time page."""
response = self.go("/server/time")

assert "time is" in response

def test_not_found(self):
""" Ensure HTTP 404 for requests that has no
intended request processors (views).
"""Ensure HTTP 404 for requests that has no
intended request processors (views).
"""
for path in ("/server", "/server/", "/server/time/x", "/x", "/abc"):
response = self.go(path, "404 Not Found")
Expand Down
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
README = open(os.path.join(os.path.dirname(__file__), "README.md")).read()
VERSION = (
re.search(
r'__version__ = "(.+)"', open("src/wheezy/routing/__init__.py").read(),
r'__version__ = "(.+)"',
open("src/wheezy/routing/__init__.py").read(),
)
.group(1)
.strip()
Expand Down
4 changes: 2 additions & 2 deletions src/wheezy/routing/builders.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@


def build_route(pattern, finishing, kwargs, name, route_builders):
""" Try to find suitable route builder to create a route.
Raises ``LookupError`` if none found.
"""Try to find suitable route builder to create a route.
Raises ``LookupError`` if none found.
"""
if not finishing:
assert not name
Expand Down
16 changes: 7 additions & 9 deletions src/wheezy/routing/choice.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@


def try_build_choice_route(pattern, finishing=True, kwargs=None, name=None):
""" If the choince route regular expression match the pattern
than create a ChoiceRoute instance.
"""If the choince route regular expression match the pattern
than create a ChoiceRoute instance.
"""
if isinstance(pattern, ChoiceRoute):
return pattern
Expand All @@ -21,8 +21,7 @@ def try_build_choice_route(pattern, finishing=True, kwargs=None, name=None):


class ChoiceRoute(object):
""" Route based on choice match, e.g. {locale:(en|ru)}.
"""
"""Route based on choice match, e.g. {locale:(en|ru)}."""

__slots__ = ("kwargs", "name", "exact_matches", "patterns", "path_format")

Expand All @@ -42,18 +41,17 @@ def __init__(self, pattern, finishing=True, kwargs=None, name=None):
self.path_format = prefix + "%s" + suffix

def match(self, path):
""" If the ``path`` matches, return the end of
substring matched and kwargs. Otherwise
return ``(-1, None)``.
"""If the ``path`` matches, return the end of
substring matched and kwargs. Otherwise
return ``(-1, None)``.
"""
for pattern, result in self.patterns:
if path.startswith(pattern):
return result
return (-1, None)

def path(self, values=None):
""" Build the path for given route.
"""
"""Build the path for given route."""
if not values or self.name not in values:
values = self.kwargs
return self.path_format % values[self.name]
22 changes: 11 additions & 11 deletions src/wheezy/routing/curly.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@


def try_build_curly_route(pattern, finishing=True, kwargs=None, name=None):
""" Convert pattern expression into regex with
named groups and create regex route.
"""Convert pattern expression into regex with
named groups and create regex route.
"""
if isinstance(pattern, RegexRoute):
return pattern
Expand Down Expand Up @@ -44,8 +44,8 @@ def try_build_curly_route(pattern, finishing=True, kwargs=None, name=None):


def convert(s):
""" Convert curly expression into regex with
named groups.
"""Convert curly expression into regex with
named groups.
"""
parts = outer_split(s, sep="[]")
parts[1::2] = ["(%s)?" % p for p in map(convert, parts[1::2])]
Expand All @@ -54,16 +54,16 @@ def convert(s):


def convert_single(s):
""" Convert curly expression into regex with
named groups.
"""Convert curly expression into regex with
named groups.
"""
parts = RE_SPLIT.split(s)
return "".join(map(replace, parts))


def replace(val):
""" Replace ``{group_name:pattern_name}`` by regex with
named groups.
"""Replace ``{group_name:pattern_name}`` by regex with
named groups.
"""
if val.startswith("{") and val.endswith("}"):
group_name, pattern_name = parse(val[1:-1])
Expand All @@ -73,10 +73,10 @@ def replace(val):


def parse(s):
""" Parse ``s`` according to ``group_name:pattern_name``.
"""Parse ``s`` according to ``group_name:pattern_name``.
There is just ``group_name``, return default
``pattern_name``.
There is just ``group_name``, return default
``pattern_name``.
"""
if ":" in s:
return tuple(s.split(":", 1))
Expand Down
27 changes: 13 additions & 14 deletions src/wheezy/routing/plain.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@


def try_build_plain_route(pattern, finishing=True, kwargs=None, name=None):
""" If the plain route regular expression match the pattern
than create a PlainRoute instance.
"""If the plain route regular expression match the pattern
than create a PlainRoute instance.
"""
if isinstance(pattern, PlainRoute):
return pattern
Expand All @@ -18,15 +18,14 @@ def try_build_plain_route(pattern, finishing=True, kwargs=None, name=None):


class PlainRoute(object):
""" Route based on string equalty operation.
"""
"""Route based on string equalty operation."""

__slots__ = ("pattern", "kwargs", "matched", "match", "exact_matches")

def __init__(self, pattern, finishing, kwargs=None, name=None):
""" Initializes the route by given ``pattern``. If
``finishing`` is True than choose ``equals_math``
strategy
"""Initializes the route by given ``pattern``. If
``finishing`` is True than choose ``equals_math``
strategy
"""
kwargs = kwargs and kwargs.copy() or {}
self.pattern = pattern
Expand All @@ -42,17 +41,17 @@ def __init__(self, pattern, finishing, kwargs=None, name=None):
self.kwargs = kwargs

def equals_match(self, path):
""" If the ``path`` exactly equals pattern string,
return end index of substring matched and a copy
of ``self.kwargs``.
"""If the ``path`` exactly equals pattern string,
return end index of substring matched and a copy
of ``self.kwargs``.
"""
return (
path == self.pattern and (self.matched, self.kwargs) or (-1, None)
)

def startswith_match(self, path):
""" If the ``path`` starts with pattern string, return
the end of substring matched and ``self.kwargs``.
"""If the ``path`` starts with pattern string, return
the end of substring matched and ``self.kwargs``.
"""
return (
path.startswith(self.pattern)
Expand All @@ -61,7 +60,7 @@ def startswith_match(self, path):
)

def path(self, values=None):
""" Build the path for given route by simply returning
the pattern used during initialization.
"""Build the path for given route by simply returning
the pattern used during initialization.
"""
return self.pattern
Loading

0 comments on commit 017c158

Please sign in to comment.