@@ -63,7 +63,7 @@ def __call__(self, s):
6363 s = s .lower ()
6464 if s in self .valid :
6565 return self .valid [s ]
66- raise ValueError ('Unrecognized %s string "%s" : valid strings are %s'
66+ raise ValueError ('Unrecognized %s string %r : valid strings are %s'
6767 % (self .key , s , list (six .itervalues (self .valid ))))
6868
6969
@@ -935,25 +935,13 @@ def _validate_linestyle(ls):
935935 A validator for all possible line styles, the named ones *and*
936936 the on-off ink sequences.
937937 """
938- # Look first for a valid named line style, like '--' or 'solid'
939- if isinstance (ls , six .string_types ):
940- try :
941- return _validate_named_linestyle (ls )
942- except (UnicodeDecodeError , KeyError ):
943- # On Python 2, string-like *ls*, like for example
944- # 'solid'.encode('utf-16'), may raise a unicode error.
945- raise ValueError ("the linestyle string {!r} is not a valid "
946- "string." .format (ls ))
947-
948- if isinstance (ls , (bytes , bytearray )):
949- # On Python 2, a string-like *ls* should already have lead to a
950- # successful return or to raising an exception. On Python 3, we have
951- # to manually raise an exception in the case of a byte-like *ls*.
952- # Otherwise, if *ls* is of even-length, it will be passed to the
953- # instance of validate_nseq_float, which will return an absurd on-off
954- # ink sequence...
955- raise ValueError ("linestyle {!r} neither looks like an on-off ink "
956- "sequence nor a valid string." .format (ls ))
938+ # Look first for a valid named line style, like '--' or 'solid' Also
939+ # includes bytes(-arrays) here (they all fail _validate_named_linestyle);
940+ # otherwise, if *ls* is of even-length, it will be passed to the instance
941+ # of validate_nseq_float, which will return an absurd on-off ink
942+ # sequence...
943+ if isinstance (ls , (str , bytes , bytearray )):
944+ return _validate_named_linestyle (ls )
957945
958946 # Look for an on-off ink sequence (in points) *of even length*.
959947 # Offset is set to None.
0 commit comments