Skip to content

Commit

Permalink
Fix code style
Browse files Browse the repository at this point in the history
  • Loading branch information
goanpeca committed Jan 2, 2020
1 parent 1d74746 commit 18436e9
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 13 deletions.
2 changes: 1 addition & 1 deletion colosseum/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ def __str__(self):
'font_weight': NORMAL,
'font_size': MEDIUM,
'line_height': NORMAL,
'font_family': '', # TODO: Depends on user agent. What to use?
'font_family': [INITIAL], # TODO: Depends on user agent. What to use?
}

######################################################################
Expand Down
18 changes: 9 additions & 9 deletions colosseum/declaration.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,27 +28,27 @@ def validated_font_property(name, initial):
def getter(self):
font = initial
for property_name, initial_value in font.items():
font[property_name] = getattr(self, property_name, initial_value)
return getattr(self, name, construct_font_property(font))
font[property_name] = getattr(self, '_%s' % property_name, initial_value)
return getattr(self, '_%s' % name, construct_font_property(font))

def setter(self, value):
font = parse_font_property(value)
for property_name, property_value in font.items():
setattr(self, property_name, property_value)
setattr(self, '_%s' % property_name, property_value)
self.dirty = True
setattr(self, name, value)

def deleter(self):
try:
delattr(self, name)
delattr(self, '_%s' % name)
self.dirty = True
except AttributeError:
# Attribute doesn't exist
pass

for property_name in INITIAL_FONT_VALUES:
try:
delattr(self, property_name)
delattr(self, '_%s' % property_name)
self.dirty = True
except AttributeError:
# Attribute doesn't exist
Expand All @@ -64,7 +64,7 @@ def validated_list_property(name, choices, initial):
raise ValueError('Initial value must be a list!')

def getter(self):
return getattr(self, name, initial)
return getattr(self, '_%s' % name, initial)

def setter(self, value):
try:
Expand All @@ -79,13 +79,13 @@ def setter(self, value):
value, name, choices
))

if values != getattr(self, name, initial):
setattr(self, name, values)
if values != getattr(self, '_%s' % name, initial):
setattr(self, '_%s' % name, values)
self.dirty = True

def deleter(self):
try:
delattr(self, name)
delattr(self, '_%s' % name)
self.dirty = True
except AttributeError:
# Attribute doesn't exist
Expand Down
1 change: 1 addition & 0 deletions colosseum/fonts.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ def get_system_font(keyword):

def construct_font_property(font):
"""Construct font property string from a dictionary of font properties."""
font['font_family'] = ', '.join(font['font_family'])
return ('{font_style} {font_variant} {font_weight} '
'{font_size}/{line_height} {font_family}').format(**font)

Expand Down
6 changes: 3 additions & 3 deletions colosseum/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,12 @@ def is_color(value):

def is_font_family(value=None, generic_family=None):
"""Validate that value is a valid font family."""
generic_family = generic_family or []

def validator(font_value):
font_value = ' '.join(font_value.strip().split())
values = [v.strip() for v in font_value.split(',')]
checked_values = []
generic_family = generic_family or []
checked_values = []
for val in values:
if (val.startswith('"') and val.endswith('"')
or val.startswith("'") and val.endswith("'")):
Expand All @@ -144,7 +144,7 @@ def validator(font_value):

return ', '.join(checked_values)

if generic_family is None:
if generic_family is []:
return validator(value)
else:
return validator
Expand Down

0 comments on commit 18436e9

Please sign in to comment.