@@ -286,7 +286,7 @@ def outline(value):
286286
287287
288288##############################################################################
289- # # Border shorthands
289+ # Border shorthands
290290##############################################################################
291291def _parse_border_property_part (value , border_dict , direction = None ):
292292 """Parse border shorthand property part for known properties."""
@@ -454,7 +454,14 @@ def position(value):
454454 """
455455 [[ <percentage> | <length> | left | center | right ][ <percentage> | <length> | top | center | bottom ]? ] |
456456 [[ left | center | right ] || [ top | center | bottom ]]
457+
458+ Reference:
459+ - https://www.w3.org/TR/2011/REC-CSS2-20110607/colors.html#background-properties
457460 """
461+ from .constants import ( # noqa
462+ BOTTOM , CENTER , LEFT , RIGHT , TOP ,
463+ )
464+
458465 if value :
459466 if isinstance (value , str ):
460467 values = [val .strip () for val in value .split ()]
@@ -472,11 +479,11 @@ def position(value):
472479 # <length> values are allowed.
473480 try :
474481 return Position (horizontal = units (values [0 ]))
475- except ValueError as error :
476- if values [0 ] in ['left' , 'right' , 'center' ]:
482+ except ValueError :
483+ if values [0 ] in [LEFT , RIGHT , CENTER ]:
477484 return Position (horizontal = values [0 ])
478485
479- if values [0 ] in ['top' , 'bottom' ]:
486+ if values [0 ] in [TOP , BOTTOM ]:
480487 return Position (vertical = values [0 ])
481488
482489 elif len (values ) == 2 :
@@ -485,21 +492,21 @@ def position(value):
485492 # Check first value
486493 try :
487494 horizontal = units (values [0 ])
488- except ValueError as error :
489- if values [0 ] in ['left' , 'center' , 'right' ]:
495+ except ValueError :
496+ if values [0 ] in [LEFT , CENTER , RIGHT ]:
490497 horizontal = values [0 ]
491498
492- if values [0 ] in ['top' , 'center' , 'bottom' ]:
499+ if values [0 ] in [TOP , CENTER , BOTTOM ]:
493500 vertical = values [0 ]
494501
495502 # Check second value
496503 try :
497504 vertical = units (values [1 ])
498- except ValueError as error :
499- if values [1 ] in ['left' , 'center' , 'right' ]:
505+ except ValueError :
506+ if values [1 ] in [LEFT , CENTER , RIGHT ]:
500507 horizontal = values [1 ]
501508
502- if values [1 ] in ['top' , 'center' , 'bottom' ]:
509+ if values [1 ] in [TOP , CENTER , BOTTOM ]:
503510 vertical = values [1 ]
504511
505512 return Position (horizontal = horizontal , vertical = vertical )
@@ -510,7 +517,7 @@ def position(value):
510517##############################################################################
511518# Background shorthand
512519##############################################################################
513- def _parse_background_property_part (value , outline_dict ):
520+ def _parse_background_property_part (value , background_dict ):
514521 """Parse background shorthand property part for known properties."""
515522 from .constants import ( # noqa
516523 BACKGROUND_ATTACHMENT_CHOICES , BACKGROUND_COLOR_CHOICES , BACKGROUND_IMAGE_CHOICES ,
@@ -527,11 +534,11 @@ def _parse_background_property_part(value, outline_dict):
527534 except (ValueError , ValidationError ):
528535 continue
529536
530- if property_name in border_dict :
537+ if property_name in background_dict :
531538 raise ValueError ('Invalid duplicated property!' )
532539
533- border_dict [property_name ] = value
534- return border_dict
540+ background_dict [property_name ] = value
541+ return background_dict
535542
536543 raise ValueError ('Background value "{value}" not valid!' .format (value = value ))
537544
0 commit comments