# HG changeset patch # User Paul Boddie # Date 1485606451 -3600 # Node ID 5fad8f7bcd90b4a68c46750cef0a59392c6b2a73 # Parent 8640a7748b1229e100d2057c263b8afd759d0dcd Fixed some testing of string literal prefixes, moving b-prefixed string interpretation into the get_string_details function. diff -r 8640a7748b12 -r 5fad8f7bcd90 common.py --- a/common.py Fri Jan 27 23:54:18 2017 +0100 +++ b/common.py Sat Jan 28 13:27:31 2017 +0100 @@ -246,11 +246,10 @@ # Attempt to convert plain strings to text. elif isinstance(value, str) and self.encoding: - if not literal.startswith("b"): - try: - return get_string_details(literal, self.encoding) - except UnicodeDecodeError: - pass + try: + return get_string_details(literal, self.encoding) + except UnicodeDecodeError: + pass return value, value.__class__.__name__, None @@ -989,7 +988,6 @@ """ l = [] - typename = "unicode" # Identify the quote character and use it to identify the prefix. @@ -1000,6 +998,11 @@ if prefix not in ("", "b", "br", "r", "u", "ur"): raise ValueError, "String literal does not have a supported prefix: %s" % s + if "b" in prefix: + typename = "str" + else: + typename = "unicode" + # Identify triple quotes or single quotes. if len(s) >= 6 and s[-2] == quote_type and s[-3] == quote_type: @@ -1049,8 +1052,9 @@ # Add Unicode values. Where a string is u-prefixed, even \o and \x # produce Unicode values. - if term in ("u", "U") or prefix == "u" and ( - term == "x" or term in octal_digits): + if typename == "unicode" and ( + term in ("u", "U") or + "u" in prefix and (term == "x" or term in octal_digits)): needed, base = searches.get(term, (4, 8)) value = convert_quoted_value(s, index, needed, end, base, unichr)