Skip to content

Commit

Permalink
Fix order of parameters for expanders
Browse files Browse the repository at this point in the history
  • Loading branch information
liZe committed Dec 27, 2023
1 parent c641f59 commit 1328c26
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion weasyprint/css/validation/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ def validation_error(level, reason):
if not tokens:
raise InvalidValues('no value')
# Use list() to consume generators now and catch any error.
result = list(expander(name, tokens, base_url))
result = list(expander(tokens, name, base_url))
except InvalidValues as exc:
validation_error(
'warning',
Expand Down
2 changes: 1 addition & 1 deletion weasyprint/css/validation/descriptors.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ def font_variant(tokens):
for name, sub_tokens in expand_font_variant(tokens):
try:
values.append(properties.validate_non_shorthand(
f'font-variant{name}', sub_tokens, required=True))
sub_tokens, f'font-variant{name}', required=True))
except InvalidValues:
return None
return values
Expand Down
20 changes: 10 additions & 10 deletions weasyprint/css/validation/expanders.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def generic_expander(*expanded_names, **kwargs):
def generic_expander_decorator(wrapped):
"""Decorate the ``wrapped`` expander."""
@functools.wraps(wrapped)
def generic_expander_wrapper(name, tokens, base_url):
def generic_expander_wrapper(tokens, name, base_url):
"""Wrap the expander."""
expander = functools.partial(
generic_expander_wrapper, name=name, base_url=base_url)
Expand Down Expand Up @@ -132,7 +132,7 @@ def generic_expander_wrapper(name, tokens, base_url):
if not skip_validation:
# validate_non_shorthand returns ((name, value),)
(actual_new_name, value), = validate_non_shorthand(
actual_new_name, value, base_url, required=True)
value, actual_new_name, base_url, required=True)
else:
value = 'initial'

Expand All @@ -147,7 +147,7 @@ def generic_expander_wrapper(name, tokens, base_url):
@expander('margin')
@expander('padding')
@expander('bleed')
def expand_four_sides(name, tokens, base_url):
def expand_four_sides(tokens, name, base_url):
"""Expand properties setting a token for the four sides of a box."""
# Define expanded names.
expanded_names = []
Expand Down Expand Up @@ -179,7 +179,7 @@ def expand_four_sides(name, tokens, base_url):
# validate_non_shorthand returns ((name, value),), we want
# to yield (name, value).
result, = validate_non_shorthand(
new_name, [token], base_url, required=True)
[token], expanded_name, base_url, required=True)
yield result


Expand Down Expand Up @@ -220,9 +220,9 @@ def border_radius(tokens, name, base_url):
f'Expected 1 to 4 token components got {len(values)}')
corners = ('top-left', 'top-right', 'bottom-right', 'bottom-left')
for corner, tokens in zip(corners, zip(horizontal, vertical)):
new_name = f'border-{corner}-radius'
validate_non_shorthand(new_name, tokens, base_url, required=True)
yield new_name, tokens
name = f'border-{corner}-radius'
validate_non_shorthand(tokens, name, base_url, required=True)
yield name, tokens


@expander('list-style')
Expand Down Expand Up @@ -269,14 +269,14 @@ def expand_list_style(tokens, name, base_url):


@expander('border')
def expand_border(name, tokens, base_url):
def expand_border(tokens, name, base_url):
"""Expand the ``border`` shorthand property.
See https://www.w3.org/TR/CSS21/box.html#propdef-border
"""
for suffix in ('-top', '-right', '-bottom', '-left'):
for new_prop in expand_border_side(name + suffix, tokens, base_url):
for new_prop in expand_border_side(tokens, name + suffix, base_url):
yield new_prop


Expand Down Expand Up @@ -306,7 +306,7 @@ def expand_border_side(tokens, name):


@expander('background')
def expand_background(name, tokens, base_url):
def expand_background(tokens, name, base_url):
"""Expand the ``background`` shorthand property.
See https://drafts.csswg.org/css-backgrounds-3/#the-background
Expand Down
2 changes: 1 addition & 1 deletion weasyprint/css/validation/properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def decorator(function):
return decorator


def validate_non_shorthand(name, tokens, base_url=None, required=False):
def validate_non_shorthand(tokens, name, base_url=None, required=False):
"""Validator for non-shorthand properties."""
if name.startswith('--'):
# TODO: validate content
Expand Down

0 comments on commit 1328c26

Please sign in to comment.